'프로그램 사용'에 해당되는 글 2258건

  1. 2021.06.02 git pull rebase 설정
  2. 2021.05.26 tensorflow lite interpreter->AllocateTensors()
  3. 2021.05.21 tflite common.h
  4. 2021.05.12 distcc 만세!
  5. 2021.05.10 imx6q neon tensorlow lite
  6. 2021.05.10 git log --stat
  7. 2021.05.09 git stash
  8. 2021.05.07 gcc %p (nil)
  9. 2021.05.01 tflite type
  10. 2021.04.30 rpi distcc with ccache 실패 ㅠㅠ

 

 

$ git config --global branch.autosetuprebase always
$ git config branch.{BRANCH-NAME}.rebase true

[링크 : http://theeye.pe.kr/archives/1980]

 

비슷한 결과를 만드는 다른 방식으로, C3 에서 변경된 사항을 Patch로 만들고 이를 다시 C4 에 적용시키는 방법이 있다. Git에서는 이런 방식을 Rebase 라고 한다. rebase 명령으로 한 브랜치에서 변경된 사항을 다른 브랜치에 적용할 수 있다.

[링크 : https://git-scm.com/book/ko/v2/Git-브랜치-Rebase-하기]

[링크 : https://jusths.tistory.com/60]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git reset 서버 commit  (0) 2021.09.14
git blame  (0) 2021.06.21
git log --stat  (0) 2021.05.10
git stash  (0) 2021.05.09
git 저장소 합치기 해보았으나..  (0) 2021.04.07
Posted by 구차니

segmentation fault가 떠서 어디서 죽나 찾는데 꽤나 고생했네 -_-

(빌드가 느리면 역시 스트레스..)

 

그런데 도무지 allocateTensors() 라는 함수가 어떤 역활을 하는지 모르겠네..

한번 할당하고 또 할당하면 오류나는 느낌..

 

  // Allocate memory for the model's input `Tensor`s.
  try interpreter.allocateTensors()

[링크 : https://www.tensorflow.org/lite/guide/inference]

[링크 : https://www.tensorflow.org/lite/api_docs/cc/class/tflite/interpreter#allocatetensors]

 

여기 소스를 많이 참고했는데.. tensorflow의 label_image쪽이랑은 또 많이 달라서

어느 가이드를 따라가야 하나 고민..

[링크 : https://github.com/Qengineering/TensorFlow_Lite_SSD_RPi_64-bits/blob/master/MobileNetV1.cpp]

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tflite yolov4  (0) 2021.06.14
tensorflow lite yolov4  (0) 2021.06.10
tflite common.h  (0) 2021.05.21
imx6q neon tensorlow lite  (0) 2021.05.10
tflite type  (0) 2021.05.01
Posted by 구차니

label_image 예제를 보면 get_top_n 에서

(prediction[i] + 128) / 256.0 나 prediction[i] / 255.0 

같은 quantization 범위에 맞춘 무언가가 보이는데 

TfLiteQuantizationParams.scale 와 TfLiteQuantizationParams.zero_point을 이용하면 자동화 가능할 느낌.

template <class T>
void get_top_n(T* prediction, int prediction_size, size_t num_results,
               float threshold, std::vector<std::pair<float, int>>* top_results,
               TfLiteType input_type) {
  // Will contain top N results in ascending order.
  std::priority_queue<std::pair<float, int>, std::vector<std::pair<float, int>>,
                      std::greater<std::pair<float, int>>>
      top_result_pq;

  const long count = prediction_size;  // NOLINT(runtime/int)
  float value = 0.0;

  for (int i = 0; i < count; ++i) {
    switch (input_type) {
      case kTfLiteFloat32:
        value = prediction[i];
        break;
      case kTfLiteInt8:
        value = (prediction[i] + 128) / 256.0;
        break;
      case kTfLiteUInt8:
        value = prediction[i] / 255.0;
        break;
      default:
        break;
    }
    // Only add it if it beats the threshold and has a chance at being in
    // the top N.
    if (value < threshold) {
      continue;
    }

    top_result_pq.push(std::pair<float, int>(value, i));

    // If at capacity, kick the smallest value out.
    if (top_result_pq.size() > num_results) {
      top_result_pq.pop();
    }
  }

  // Copy to output vector and reverse into descending order.
  while (!top_result_pq.empty()) {
    top_results->push_back(top_result_pq.top());
    top_result_pq.pop();
  }
  std::reverse(top_results->begin(), top_results->end());
}

 

netron 에서 보면 quantization 범위가 나오는데, 어딘가 저장하고는 있는 듯 해서 검색 중

// SupportedQuantizationTypes.
typedef enum TfLiteQuantizationType {
  // No quantization.
  kTfLiteNoQuantization = 0,
  // Affine quantization (with support for per-channel quantization).
  // Corresponds to TfLiteAffineQuantization.
  kTfLiteAffineQuantization = 1,
} TfLiteQuantizationType;

// Structure specifying the quantization used by the tensor, if-any.
typedef struct TfLiteQuantization {
  // The type of quantization held by params.
  TfLiteQuantizationType type;
  // Holds a reference to one of the quantization param structures specified
  // below.
  void* params;
} TfLiteQuantization;

// Legacy. Will be deprecated in favor of TfLiteAffineQuantization.
// If per-layer quantization is specified this field will still be populated in
// addition to TfLiteAffineQuantization.
// Parameters for asymmetric quantization. Quantized values can be converted
// back to float using:
//     real_value = scale * (quantized_value - zero_point)
typedef struct TfLiteQuantizationParams {
  float scale;
  int32_t zero_point;
} TfLiteQuantizationParams;

// Parameters for asymmetric quantization across a dimension (i.e per output
// channel quantization).
// quantized_dimension specifies which dimension the scales and zero_points
// correspond to.
// For a particular value in quantized_dimension, quantized values can be
// converted back to float using:
//     real_value = scale * (quantized_value - zero_point)
typedef struct TfLiteAffineQuantization {
  TfLiteFloatArray* scale;
  TfLiteIntArray* zero_point;
  int32_t quantized_dimension;
} TfLiteAffineQuantization;

typedef struct TfLiteTensor {
  TfLiteType type;
  TfLitePtrUnion data;
  TfLiteIntArray* dims;
  TfLiteQuantizationParams params;
  TfLiteAllocationType allocation_type;
  size_t bytes;
  const void* allocation;
  const char* name;
  struct TfLiteDelegate* delegate;
  TfLiteBufferHandle buffer_handle;
  bool data_is_stale;
  bool is_variable;
  TfLiteQuantization quantization;
  TfLiteSparsity* sparsity;
  const TfLiteIntArray* dims_signature;
} TfLiteTensor;

 

+

2021.05.26

typedef struct TfLiteIntArray {
  int size;
// gcc 6.1+ have a bug where flexible members aren't properly handled
// https://github.com/google/re2/commit/b94b7cd42e9f02673cd748c1ac1d16db4052514c
#if (!defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \
     __GNUC_MINOR__ >= 1) ||                                      \
    defined(HEXAGON) || (__clang_major__ == 7 && __clang_minor__ == 1)
  int data[0];
#else
  int data[];
#endif
} TfLiteIntArray;

// Fixed size list of floats. Used for per-channel quantization.
typedef struct TfLiteFloatArray {
  int size;
// gcc 6.1+ have a bug where flexible members aren't properly handled
// https://github.com/google/re2/commit/b94b7cd42e9f02673cd748c1ac1d16db4052514c
// This also applies to the toolchain used for Qualcomm Hexagon DSPs.
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \
    __GNUC_MINOR__ >= 1
  float data[0];
#else
  float data[];
#endif
} TfLiteFloatArray;

 

class Interpreter {
  /// Invoke the interpreter (run the whole graph in dependency order).
  ///
  /// NOTE: It is possible that the interpreter is not in a ready state
  /// to evaluate (i.e. if a ResizeTensor() has been performed without an
  /// AllocateTensors().
  /// Returns status of success or failure.
  TfLiteStatus Invoke();

  /// WARNING: Experimental interface, subject to change
  Subgraph& primary_subgraph() {
    return *subgraphs_.front();  /// Safe as subgraphs_ always has 1 entry.
  }
  
  /// Read only access to list of inputs.
  const std::vector<int>& inputs() const { return primary_subgraph().inputs(); }
  
  /// Read only access to list of outputs.
  const std::vector<int>& outputs() const {
    return primary_subgraph().outputs();
  }
  
  // Subgraphs
  std::vector<std::unique_ptr<Subgraph>> subgraphs_;
};

[링크 : https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/interpreter.h]

 

class Subgraph {
  // Array of indices representing the tensors that are inputs to the
  // interpreter.
  std::vector<int> inputs_;

  // Array of indices representing the tensors that are outputs to the
  // interpreter.
  std::vector<int> outputs_;
  
  // Read only access to list of inputs.
  std::vector<int>& inputs() { return inputs_; }

  // Read only access to list of inputs.
  const std::vector<int>& inputs() const { return inputs_; }

  // Read only access to list of outputs.
  std::vector<int>& outputs() { return outputs_; }

  // Read only access to list of outputs.
  const std::vector<int>& outputs() const { return outputs_; }
};

[링크 : https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/core/subgraph.h]

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tensorflow lite yolov4  (0) 2021.06.10
tensorflow lite interpreter->AllocateTensors()  (0) 2021.05.26
imx6q neon tensorlow lite  (0) 2021.05.10
tflite type  (0) 2021.05.01
tflite example  (0) 2021.04.19
Posted by 구차니

라즈베리 파이 3b+ 에 lxde 올리지 않고 콘솔로만 해서 메모리 최대한 확보하고 쓰는 중인데

비디오 메모리 64MB 정도 먹혔는지 가용 메모리가 706MiB 정도.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          924Mi        50Mi       706Mi       4.0Mi       166Mi       817Mi
Swap:          99Mi       9.0Mi        90Mi

 

그런 이유로 텐서플로우 빌드시 rpi 메모리가 2G 넘지 않으면 코어 하나만 쓰게 되어있다.

FREE_MEM="$(free -m | awk '/^Mem/ {print $2}')"
# Use "-j 4" only memory is larger than 2GB
if [[ "FREE_MEM" -gt "2000" ]]; then
  NO_JOB=4
else
  NO_JOB=1
fi

 

그래서 distcc 통해 개별 노드에서 2개씩, 총 3개 노드/ 6 core 쓰도록 하니

35~40분 정도 걸리던 빌드가 8분 40초 만에 끝내준다.

real    8m39.261s
user    2m47.210s
sys     0m51.071s

 

개별 노드에서 병렬시 2개 까지만 허락하도록 해놔야지 안그러면

메모리 부족으로 스왑한다고 io 폭주해서 라즈베리가 먹통이 된다.

/etc/default/distcc

#
# You can specify a maximum number of jobs, the server will accept concurrently
#
# JOBS=""

JOBS="2"

'프로그램 사용 > distcc & ccache' 카테고리의 다른 글

rpi distcc with ccache 실패 ㅠㅠ  (0) 2021.04.30
rpi distcc 성공인데 실패  (0) 2021.04.28
distcc hosts 파일과 순서  (0) 2016.10.19
distcc-pump 시도..  (0) 2016.10.18
distcc 를 DHCP 에서.. 2?  (0) 2016.10.18
Posted by 구차니

이번 빌드 옵션들을 뒤져보다 보니 빼먹고 안 넣은게 있었네

(라고 쓰고 실은 귀찮았던...)

 

-mvectorize-with-neon-quad -ffast-math

[링크 : http://stackoverflow.com/questions/14962447/gcc-options-for-a-freescale-imx6q-arm-processor]

 

 

In addition GCC offers the -ffast-math flag which is a shortcut for several options, presenting the least conforming but fastest math mode. It enables -fno-trapping-math, -funsafe-math-optimizations, -ffinite-math-only, -fno-errno-math, -fno-signaling-nans, -fno-rounding-math, -fcx-limited-range and -fno-signed-zeros. Each of these flags violates IEEE in a different way. 

[링크 : http://gcc.gnu.org/wiki/FloatingPointMath]

 

 

Cortex-A9 -mcpu=cortex-a9 -mfpu=vfpv3-fp16 -mfpu=vfpv3-d16-fp16 -mfpu=neon-fp16

[링크 : http://www.programmersought.com/article/5320739655/]

 

-DENABLE_VFPV3=ON ARM VFPv3 floating 

[링크 : http://www.google.com/amp/s/learnopencv.com/build-and-install-opencv-4-for-raspberry-pi/amp/]

 

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tensorflow lite interpreter->AllocateTensors()  (0) 2021.05.26
tflite common.h  (0) 2021.05.21
tflite type  (0) 2021.05.01
tflite example  (0) 2021.04.19
tflite convert  (0) 2021.04.16
Posted by 구차니

'프로그램 사용 > Version Control' 카테고리의 다른 글

git blame  (0) 2021.06.21
git pull rebase 설정  (0) 2021.06.02
git stash  (0) 2021.05.09
git 저장소 합치기 해보았으나..  (0) 2021.04.07
git 특정 디렉토리만 clone 하기  (0) 2021.04.07
Posted by 구차니

이번에 한번 날릴 각오로(!) 써봐야지 -_ㅠ

git stash [push]

git stash list

git stash apply | pop

SYNOPSIS
       git stash list [<options>]
       git stash show [<stash>]
       git stash drop [-q|--quiet] [<stash>]
       git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
       git stash branch <branchname> [<stash>]
       git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
                    [-u|--include-untracked] [-a|--all] [-m|--message <message>]
                    [--] [<pathspec>...]]
       git stash clear
       git stash create [<message>]
       git stash store [-m|--message <message>] [-q|--quiet] <commit>

[링크 : https://gmlwjd9405.github.io/2018/05/18/git-stash.html]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git pull rebase 설정  (0) 2021.06.02
git log --stat  (0) 2021.05.10
git 저장소 합치기 해보았으나..  (0) 2021.04.07
git 특정 디렉토리만 clone 하기  (0) 2021.04.07
git lfs  (0) 2021.04.06
Posted by 구차니
프로그램 사용/gcc2021. 5. 7. 17:30

%p로 출력하니 0일 경우 (nil)로 출력되네?

 

[링크 : https://stackoverflow.com/questions/4744650/nil-pointer-in-c-c]

'프로그램 사용 > gcc' 카테고리의 다른 글

gcc vectorized loop  (0) 2021.06.30
gcc unsigned to signed cast  (0) 2021.06.22
gcc -D 옵션 인자를 printf로 출력하기  (0) 2021.04.08
Auto-vectorization in GCC  (0) 2021.03.25
gcc -march 옵션  (0) 2021.01.24
Posted by 구차니

 

변수 추적해보니 그게 그거인가?

  int output = interpreter->outputs()[0];
  TfLiteIntArray* output_dims = interpreter->tensor(output)->dims;
  // assume output dims to be something like (1, 1, ... ,size)
  auto output_size = output_dims->data[output_dims->size - 1];

 

    const float* detection_locations = interpreter->tensor(interpreter->outputs()[0])->data.f;
    const float* detection_classes=interpreter->tensor(interpreter->outputs()[1])->data.f;
    const float* detection_scores = interpreter->tensor(interpreter->outputs()[2])->data.f;
    const int    num_detections = *interpreter->tensor(interpreter->outputs()[3])->data.f;

    //there are ALWAYS 10 detections no matter how many objects are detectable
    //cout << "number of detections: " << num_detections << "\n";

    const float confidence_threshold = 0.5;
    for(int i = 0; i < num_detections; i++){
        if(detection_scores[i] > confidence_threshold){
            int  det_index = (int)detection_classes[i]+1;
            float y1=detection_locations[4*i  ]*cam_height;
            float x1=detection_locations[4*i+1]*cam_width;
            float y2=detection_locations[4*i+2]*cam_height;
            float x2=detection_locations[4*i+3]*cam_width;

            Rect rec((int)x1, (int)y1, (int)(x2 - x1), (int)(y2 - y1));
            rectangle(src,rec, Scalar(0, 0, 255), 1, 8, 0);
            putText(src, format("%s", Labels[det_index].c_str()), Point(x1, y1-5) ,FONT_HERSHEY_SIMPLEX,0.5, Scalar(0, 0, 255), 1, 8, 0);
        }
    }

 

 

typedef struct {
  int size;
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \
    __GNUC_MINOR__ >= 1
  int data[0];
#else
  int data[];
#endif
} TfLiteIntArray;

typedef union {
  int* i32;
  int64_t* i64;
  float* f;
  char* raw;
  const char* raw_const;
  uint8_t* uint8;
  bool* b;
  int16_t* i16;
  TfLiteComplex64* c64;
  int8_t* int8;
} TfLitePtrUnion;

typedef struct {
  TfLiteType type;
  TfLitePtrUnion data;
  TfLiteIntArray* dims;
  TfLiteQuantizationParams params;
  TfLiteAllocationType allocation_type;
  size_t bytes;
  const void* allocation;
  const char* name;
  TfLiteDelegate* delegate;
  TfLiteBufferHandle buffer_handle;
  bool data_is_stale;
  bool is_variable;
  TfLiteQuantization quantization;
} TfLiteTensor;

[링크 : https://android.googlesource.com/platform/external/tensorflow/.../tensorflow/lite/c/c_api_internal.h]

 

현재 소스에서는 common.h 로 옮겨진듯

[링크 : https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/common.h]

'프로그램 사용 > yolo_tensorflow' 카테고리의 다른 글

tflite common.h  (0) 2021.05.21
imx6q neon tensorlow lite  (0) 2021.05.10
tflite example  (0) 2021.04.19
tflite convert  (0) 2021.04.16
LSTM - Long short-term memory  (0) 2021.04.16
Posted by 구차니

그런 이유로 distcc-pump 모드 시도 ㅠㅠ

 

[링크 : https://itmir.tistory.com/454]

[링크 : https://www.whatwant.com/entry/Ubuntu에서-ccache-사용하기]

'프로그램 사용 > distcc & ccache' 카테고리의 다른 글

distcc 만세!  (0) 2021.05.12
rpi distcc 성공인데 실패  (0) 2021.04.28
distcc hosts 파일과 순서  (0) 2016.10.19
distcc-pump 시도..  (0) 2016.10.18
distcc 를 DHCP 에서.. 2?  (0) 2016.10.18
Posted by 구차니