해당 cpp 예제는 label_image를 수정한 것 같고, 이미지는 bmp 24bit만 받아들일 수 있을 것으로 생각된다.

그리고 이미지는 알아서 resize 해주지 않아 244*244로 리사이즈 한 이미지를 넣어주어야 한다.

 

netron 웹 사이트에서  모델을 불러들여서 확인해보니 input tensor 사이즈가 [1,244,244,3] 이다.

 

아.. 놔.. threshold는 0~1 사이 실수로 입력해야 한다. (도움말 좀만 더 친절히 해줘 ㅠㅠ)

(대충 봐서 thread로 보고 4를 넣었으니 결과가 나올리가..)

./classify <model_file> <label_file> <image_file> <threshold>

 

그리고 edgetpu용으로 돌리나 일반용으로 돌리나 시간 차이가 좀 나긴 한데 무슨 차이인진 모르겠다.

$ time ./classify models/mobilenet_v2_1.0_224_inat_bird_quant.tflite models/inat_bird_labels.txt images/parrot_re.bmp 0.2
0.79297923 Ara macao (Scarlet Macaw)

real    0m3.914s
user    0m0.612s
sys     0m0.132s

 

쥐꼬리 만큼 줄긴했는데... user쪽이 많이 줄어들긴 했다.

$ time ./classify models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite models/inat_bird_labels.txt images/parrot_re.bmp 0.1
0.79297923 Ara macao (Scarlet Macaw)

real    0m3.542s
user    0m0.108s
sys     0m0.171s

 

 

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

google coral with tpu, python  (0) 2022.02.07
edgetpu_c.h 파일 내용 분석  (0) 2022.02.07
tensorflow brace-enclosed initializer list  (4) 2022.02.07
google coral, tpu yolo  (0) 2022.01.27
coral tpu delegate example  (0) 2022.01.25
Posted by 구차니

이전에 했었는데 먼가 내용을 다시보니 부족해서 추가

 

edgetpu 용으로 변환된 모델

$ python3 classify_image.py   --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite   --labels models/inat_bird_labels.txt   --input images/parrot.jpg
----INFERENCE TIME----
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
137.5ms
13.0ms
13.1ms
13.1ms
13.1ms
-------RESULTS--------
Ara macao (Scarlet Macaw): 0.77734

 

변환되지 않은 모델. 속도 차이가 상당히 나는데 반복 실행시 속도가 줄어들지 않는걸 보면..

tpu 가속을 받지 못하고 cpu로 돌리기 때문이려나?

그리고 정확도는 소수점 5자리 까지 동일하게 나온다.

quantization 으로 인한 정확도 차이는 잘만들면 무시할 만한 수준 이라고 보면 될 듯.

$ python3 classify_image.py \
>   --model models/mobilenet_v2_1.0_224_inat_bird_quant.tflite \
>   --labels models/inat_bird_labels.txt \
>   --input images/parrot.jpg


----INFERENCE TIME----
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU m                                                                                                           emory.
552.0ms
542.7ms
541.3ms
549.1ms
541.4ms
-------RESULTS--------
Ara macao (Scarlet Macaw): 0.77734

 

2020.10.20 - [프로그램 사용/google coral] - google coral, ubuntu 18.04

 

 

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

google coral with tpu, cpp  (4) 2022.02.07
edgetpu_c.h 파일 내용 분석  (0) 2022.02.07
tensorflow brace-enclosed initializer list  (4) 2022.02.07
google coral, tpu yolo  (0) 2022.01.27
coral tpu delegate example  (0) 2022.01.25
Posted by 구차니

 

2020년 1월 30일 커밋 되었는데

헤더에 사용법을 넣어두었고 그게 바로.. 문제의 그 내용 -_-

// 4. Modify interpreter with the delegate.
//
// auto* delegate =
//     edgetpu_create_delegate(device.type, device.path, nullptr, 0);
// interpreter->ModifyGraphWithDelegate({delegate, edgetpu_free_delegate});


// Frees delegate returned by `edgetpu_create_delegate`.
EDGETPU_EXPORT void edgetpu_free_delegate(TfLiteDelegate* delegate);

[링크 : https://github.com/google-coral/edgetpu/blob/master/libedgetpu/edgetpu_c.h]

 

delegate를 free 하지 않고(메모리 누수를 감수하면..)

위의 함수 원형으로 delegate만 던져주거나

unique_ptr <Delegate, Deleter > 로 랩핑하면 가능을 할 것 같은데

그게 아니라면..  { } 로 감싼 부분이 자동으로 변형되는건 아니겠지? (컴파일러 옵션에 의해)

TfLiteStatus ModifyGraphWithDelegate(
  TfLiteDelegate *delegate
)

TfLiteStatus ModifyGraphWithDelegate(
  std::unique_ptr< Delegate, Deleter > delegate
)

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

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

google coral with tpu, cpp  (4) 2022.02.07
google coral with tpu, python  (0) 2022.02.07
tensorflow brace-enclosed initializer list  (4) 2022.02.07
google coral, tpu yolo  (0) 2022.01.27
coral tpu delegate example  (0) 2022.01.25
Posted by 구차니

그냥 손에 익숙한(!) v2.4.1을 써서 그런가(구버전 api라서?)

해당 함수가 존재하지 않는다고 에러가 발생하고 빌드에 실패한다.

classify.cc:177:73: error: no matching function for call to ‘tflite::Interpreter::ModifyGraphWithDelegate(<brace-enclosed initializer list>)’
   interpreter->ModifyGraphWithDelegate({delegate, edgetpu_free_delegate});
                                                                         ^
In file included from classify.cc:12:
/home/pi/work/coral/tensorflow/tensorflow/lite/interpreter.h:421:16: note: candidate: ‘TfLiteStatus tflite::Interpreter::ModifyGraphWithDelegate(TfLiteDelegate*)’
   TfLiteStatus ModifyGraphWithDelegate(TfLiteDelegate* delegate);
                ^~~~~~~~~~~~~~~~~~~~~~~
/home/pi/work/coral/tensorflow/tensorflow/lite/interpreter.h:421:16: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘TfLiteDelegate*’
/home/pi/work/coral/tensorflow/tensorflow/lite/interpreter.h:431:23: note: candidate: ‘template<class Delegate, class Deleter> TfLiteStatus tflite::Interpreter::ModifyGraphWithDelegate(std::unique_ptr<_Tp, _Dp>)’
   inline TfLiteStatus ModifyGraphWithDelegate(
                       ^~~~~~~~~~~~~~~~~~~~~~~
/home/pi/work/coral/tensorflow/tensorflow/lite/interpreter.h:431:23: note:   template argument deduction/substitution failed:
classify.cc:177:73: note:   couldn't deduce template parameter ‘Delegate’
   interpreter->ModifyGraphWithDelegate({delegate, edgetpu_free_delegate});

 

검색해보니 c++x00

 

class Example {
  private:
  public:
    Example(std::initializer_list<int> list) {
    }
};

Example exam = {10,10,10,10,10};

[링크 : https://forum.arduino.cc/t/how-to-make-brace-enclosed-initializer-list-constructor/628295]

 

Phenotype(std::initializer_list<uint8> c) {
  assert(c.size() <= std::size(m_array));
  std::copy(c.begin(), c.end(), m_array);
}

// used like
Phenotype p1{1, 2, 3};
Phenotype p2({1, 3, 2}); // works too
Phenotype p3(1, 2, 3); // doesn't work

[링크 : https://stackoverflow.com/questions/4118025/brace-enclosed-initializer-list-constructor]

 

그나저나 api 문서가 업데이트 늦을수도 있지만

아래의 원형밖에 없는데 std::unique_ptr이 std::initializer_list일 리는 없을테고. 도대체 어떤 함수를 써야 하는걸까?

TfLiteStatus ModifyGraphWithDelegate(
  TfLiteDelegate *delegate
)

TfLiteStatus ModifyGraphWithDelegate(
  std::unique_ptr< Delegate, Deleter > delegate
)

TfLiteStatus ModifyGraphWithDelegate(
  std::unique_ptr< TfLiteDelegate > delegate
)=delete

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

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

google coral with tpu, python  (0) 2022.02.07
edgetpu_c.h 파일 내용 분석  (0) 2022.02.07
google coral, tpu yolo  (0) 2022.01.27
coral tpu delegate example  (0) 2022.01.25
google coral, ubuntu 18.04  (0) 2020.10.20
Posted by 구차니

요약하면.. 메모리 부족하니 빌드 속도를 포기하고 swap을 이용해서 커버치기!

[링크 : https://gist.github.com/EKami/9869ae6347f68c592c5b5cd181a3b205]

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

tensorflow lite / mnist 학습  (0) 2024.01.02
yolo-label  (0) 2022.03.22
bazel cross compile  (0) 2022.01.27
bazel clean  (0) 2021.10.19
2.7.0-rc with opencl  (0) 2021.10.13
Posted by 구차니

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

yolo-label  (0) 2022.03.22
tflite bazel rpi3b+  (0) 2022.01.27
bazel clean  (0) 2021.10.19
2.7.0-rc with opencl  (0) 2021.10.13
tf release 2.7.0-rc  (0) 2021.10.12
Posted by 구차니

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

edgetpu_c.h 파일 내용 분석  (0) 2022.02.07
tensorflow brace-enclosed initializer list  (4) 2022.02.07
coral tpu delegate example  (0) 2022.01.25
google coral, ubuntu 18.04  (0) 2020.10.20
google coral  (0) 2020.10.06
Posted by 구차니
프로그램 사용/VNC2022. 1. 26. 17:07

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

libvncserver 마우스 이벤트  (0) 2022.02.25
libvncserver 사용예  (0) 2022.02.15
gconf-editor / ubuntu 14.04 LTS vino + VNC 접속불가  (0) 2015.03.22
VNC web 버전?  (0) 2014.12.11
VNC 5.0.5  (0) 2013.09.04
Posted by 구차니
프로그램 사용/meson2022. 1. 25. 15:04

 

 

[binaries]
c = '/usr/lib/ccache/arm-linux-gnueabihf-gcc'
cpp = '/usr/lib/ccache/arm-linux-gnueabihf-g++'
ar = '/usr/bin/arm-linux-gnueabihf-ar'
strip = '/usr/bin/arm-linux-gnueabihf-strip'
pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config'
 
[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'armv8hl'
endian = 'little'
meson build/ \
    --cross-file=$HOME/pi/mesa/cross_file

[링크 : https://makersweb.net/qt/17557]

 

ubuntu 에서 apt install meson 으로 설치시 구버전이라 발생하는 에러

meson_options.txt:1:0: ERROR:  Unknown type feature.

[링크 : https://github.com/swaywm/wlroots/issues/1258]

 

Ninja는 속도에 중점을 둔 소형 빌드 시스템으로, Make의 느린 증분 빌드의 대안으로 만들어졌습니다.

[링크 : https://int-i.github.io/cpp/2021-06-26/cpp-meson/]

Posted by 구차니

cpp

[링크 : https://github.com/google-coral/tflite]

[링크 : https://coral.ai/docs/edgetpu/tflite-cpp/]

 

 

python

[링크 : https://coding-yoon.tistory.com/91]

 

+

auto* delegate = edgetpu_create_delegate(device.type, device.path, nullptr, 0);
  interpreter->ModifyGraphWithDelegate({delegate, edgetpu_free_delegate});

[링크 : https://github.com/google-coral/tflite/blob/master/cpp/examples/classification/classify.cc]

 

auto delegates = delegate_providers.CreateAllDelegates();
  for (auto& delegate : delegates) {
    const auto delegate_name = delegate.provider->GetName();
    if (interpreter->ModifyGraphWithDelegate(std::move(delegate.delegate)) !=
        kTfLiteOk) {
      LOG(ERROR) << "Failed to apply " << delegate_name << " delegate.";
      exit(-1);
    } else {
      LOG(INFO) << "Applied " << delegate_name << " delegate.";
    }
  }

[링크 : https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/examples/label_image/label_image.cc]

 

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

edgetpu_c.h 파일 내용 분석  (0) 2022.02.07
tensorflow brace-enclosed initializer list  (4) 2022.02.07
google coral, tpu yolo  (0) 2022.01.27
google coral, ubuntu 18.04  (0) 2020.10.20
google coral  (0) 2020.10.06
Posted by 구차니