IT Convergence Engineering/AI 버섯 어플

[Tensorflow & keras] .h5 -> .pb -> .tflite 변환 오류(python)

Soo_buglosschestnut 2020. 8. 28. 23:05

 .h5 -> .pb -> .tflite 변환 오류(python)


  • .h5-> .pb 오류

colab으로 movilenetv2 모델로 돌려서 h5모델을 얻어냈다!!

 

but..!

bugloss-chestnut.tistory.com/entry/Android-h5-pb-tflite%EB%A1%9C-%EB%B3%80%ED%99%98-%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C%EC%97%90-%EC%A0%81%EC%9A%A9

 

[Tensorflow & Android] .h5 -> .pb -> .tflite로 변환 & 안드로이드에 적용(python & java)

.h5 -> .pb -> .tflite로 변환 & 안드로이드에 적용(python & java) 1. .h5 -> .pb -> .tflite로 변환 .h5 파일 -> .pb 파일로 변환하기 (코드) from tensorflow import keras model = keras.models.load_model(..

bugloss-chestnut.tistory.com

이 방법대로 했더니... 갑자기 오류가...

맨 마지막에 ValueError: Unknown layer: Functional 이라는 오류가 생겨서 먹통이 되었다.

 

그래서 폭풍 검색중에 발견한 블로그..!

kaen2891.tistory.com/tag/Keras%20Unknown%20layer%20%ED%95%B4%EA%B2%B0

 

Kaen의 일상생활

Only in the agony of parting do we look into the depths of love -- 낭만은 짧고 지저분한 질척거림만 남은 첫눈처럼 유독 추운 겨울이었고 누군가 떠날 것 같았다.

kaen2891.tistory.com

custom_object를 선언해서 해줬음에도 불구하고 똑같은 오류가 발생...

 

또 열심히 구글링 중에 발견한것..

 

stackoverflow.com/questions/63068639/valueerror-unknown-layer-functional

 

ValueError: Unknown layer: Functional

I made a CNN in colab and saved the models at every epoch. I exported the h5 file and now am trying to run the model on some test images. Here's the main error: ValueError: Unknown layer: Functional

stackoverflow.com

tensorflow 2.3.0 version이면 2.2.0 version으로 downgrade 해주란다~

 

근데 tensroflow downgrade하니 또 안될때가 있다...(밑에거랑 오류가 같이 떠서 해결방법이 같음.)

 

또 열심히 구글링

 

stackoverflow.com/questions/61200676/tensorflow2-1-invalidargumenterror-assertion-failed-0-opassert-name-eage

 

tensorflow2.1 InvalidArgumentError: assertion failed: [0] [Op:Assert] name: EagerVariableNameReuse

I trained my custom model and used tensorflow 2.1. When I run the code I'm getting the following error: InvalidArgumentError: assertion failed: [0] [Op:Assert] name: EagerVariableNameReuse He...

stackoverflow.com

밑에 보면 tensroflow-gpu를 downgrade!! 얼른 시도 해봣다

 

downgrade하고 했더니 성공 !! 이게 뭔 오류인가 도대체... ㅠㅠ

 

ps. downgrade하고도 안될시에 다시 2.3.0으로 upgrade 해주면 작동 잘 될듯(tensorflow 2.3.0 -> 2.2.0 -> 2.3.0 이렇게)

 

- pip install tensorflow==2.2.0

- pip install tensorflow-gpu==2.2.0


  • .pb -> .tflite 오류

이번엔 .pb -> .tflite 변환할때 오류가 난다~..

bugloss-chestnut.tistory.com/entry/Android-h5-pb-tflite%EB%A1%9C-%EB%B3%80%ED%99%98-%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C%EC%97%90-%EC%A0%81%EC%9A%A9

 

[Tensorflow & Android] .h5 -> .pb -> .tflite로 변환 & 안드로이드에 적용(python & java)

.h5 -> .pb -> .tflite로 변환 & 안드로이드에 적용(python & java) 1. .h5 -> .pb -> .tflite로 변환 .h5 파일 -> .pb 파일로 변환하기 (코드) from tensorflow import keras model = keras.models.load_model(..

bugloss-chestnut.tistory.com

코드에 문제가 없는거 같은데 왜이런지 ~...

 

이번엔 InvalidArgumentError: assertion failed: [0] [Op:Assert] name: EagerVariableNameReuse 오류

 

이것도 폭풍 검색중~~ 발견

github.com/tensorflow/tensorflow/issues/38518#issuecomment-669878400

 

InvalidArgumentError: assertion failed: [0] [Op:Assert] name: EagerVariableNameReuse · Issue #38518 · tensorflow/tensorflow

when i use tensorflow2.1 .I trained my model custom,yesterday,the code can run correctly. But torday is error, I debug my code , I found this code is error , self.train_accuracy = tf.keras.metrics....

github.com

 

이것도 아까와 같이 downgrade해보란다ㅋㅋㅋ 

 

역시 오류가 날때가 있다~

 

또 열심히 구글링

 

stackoverflow.com/questions/61200676/tensorflow2-1-invalidargumenterror-assertion-failed-0-opassert-name-eage

 

tensorflow2.1 InvalidArgumentError: assertion failed: [0] [Op:Assert] name: EagerVariableNameReuse

I trained my custom model and used tensorflow 2.1. When I run the code I'm getting the following error: InvalidArgumentError: assertion failed: [0] [Op:Assert] name: EagerVariableNameReuse He...

stackoverflow.com

 

tensorflow-gpu좀 손보란다~

 

나는 tensorflow-gpu 2.3이여서 2.2로 downgrade하고 다시 2.3으로 upgrade했더니 오류 안생기고 잘 돌아간다.

 

- pip install tensroflow==2.2.0

- pip install tensorflow-gpu==2.2.0

 


ⓐ db파일 안드로이드앱에 넣는거 올리기

bugloss-chestnut.tistory.com/entry/Android-db%ED%8C%8C%EC%9D%BC-Android-App%EC%97%90-%EB%84%A3%EA%B8%B0JAVA

 

[Android] .db파일 Android App에 넣기(JAVA)

.db파일 Android App에 넣기(JAVA) .db파일 Android App에 넣기 1. 먼저 assets 폴더를 만들어 줘야한다!! (assets 폴더 없으면 다음 링크를통행 assets 폴더 만들기!) bugloss-chestnut.tistory.com/entry/And..

bugloss-chestnut.tistory.com

ⓑ tflite quant 양자화 하는방법 올리기

bugloss-chestnut.tistory.com/entry/Tensorflow-tflite%EB%A5%BC-Quantization%EC%96%91%EC%9E%90%ED%99%94%ED%95%98%EA%B8%B0python

 

[Tensorflow] .tflite를 Quantization(양자화)하기(python)

.tflite를 Quantization(양자화)하기(python) Python API는 quantization 옵션을 제공한다. 양자화는 float32로 학습된 weight값들을 단순화 시키는 작업을 말한다. 이 작업을 하게되면 .tflite이 파일크기가 대략..

bugloss-chestnut.tistory.com