Posted by 구차니

23bit 비트의 정수고 8bit의 십진수 정확도 라고 하니 먼가 감이 안오는데

 

0 ~ 8388608(2^23) 범위를

0  ~ 32768 로 사용한다는 것. (그럼 이론상 FHD 17*17개 UHD 8*8 까지 가능하려나)

 

정확도는 어떤 의미로 쓰려나.. 나중에 확대했을때를 대비해서 소수점 포인트를 주는건가?

 

/**
 * Fixed-point number
 *
 * A `wl_fixed_t` is a 24.8 signed fixed-point number with a sign bit, 23 bits
 * of integer precision and 8 bits of decimal precision. Consider `wl_fixed_t`
 * as an opaque struct with methods that facilitate conversion to and from
 * `double` and `int` types.
 */
typedef int32_t wl_fixed_t;

[링크 : https://code.woboq.org/qt5/include/wayland-util.h.html]

 

typedef int32_t wl_fixed_t;

static inline int wl_fixed_to_int(wl_fixed_t f)
{
    return f / 256;
}

static inline wl_fixed_t wl_fixed_from_int(int i)
{
    return i * 256;
}

[링크 : https://github.com/nobled/wayland/blob/master/src/wayland-util.h]

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

wayvnc 실행 실패  (0) 2022.02.17
wayland-scanner  (0) 2022.02.16
wayvnc  (0) 2022.01.24
weston client 메모리 누수  (0) 2022.01.17
wayland buffer  (0) 2022.01.13
Posted by 구차니
프로그램 사용/gcc2022. 2. 7. 16:07

전부 정적으로 묶고 일부만 동적으로 묶는거나

동적으로 묶을건 냅두고 필요한(나머지) 것을 정적으로 묶는거나 그게 그건가?

 

-static-libgcc 한다고 해서 glibc 버전 안 맞다고 발생하는 에러를 해결할 순 없다

[링크 : https://stackoverflow.com/questions/26304531]

 

[링크 : https://kldp.org/node/136157]

  [링크 : https://enst.tistory.com/entry/liblibcso6-version-GLIBC27-not-found]

 

 

[링크 : https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html]

  [링크 : https://www.codeproject.com/Questions/1241890/How-to-link-to-libc-statically]

 

-lm 버전 문제 있으면 걍 해당 라이브러리를 static link 해버리면 되니까!

$ g++ -std=c++11 -o classify classify.cc -I/home/pi/work/coral/libedgetpu/tflite/public -I/home/pi/work/coral/tensorflow -I/home/pi/work/coral/tensorflow/tensorflow/lite/tools/make/downloads/flatbuffers/include -L/home/pi/work/coral/tensorflow/tensorflow/lite/tools/make/gen/rpi_armv7l/lib -L/home/pi/work/coral/pycoral/libedgetpu_bin/throttled/armv7a -ltensorflow-lite -static-libgcc -l:libedgetpu.so.1.0 -lpthread -ldl /usr/lib/arm-linux-gnueabihf/libm.a

[링크 : http://www.iamroot.org/xe/index.php?mid=Programming&document_srl=13406]

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

gcc vectorization 실패  (0) 2022.06.02
gcc / 문자열 선언  (0) 2022.03.17
구조체 타입과 변수명은 구분된다?  (0) 2021.11.18
gcc unsigned to signed upcast 테스트  (0) 2021.07.08
gcc vectorized loop  (0) 2021.06.30
Posted by 구차니

해당 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 구차니