Skip to content

야학에서 배운 딥러닝을 안드로이드에서 쓰고 싶습니다 #1024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sungdoolim opened this issue Aug 25, 2020 · 1 comment
Labels
Android / iOS 안드로이드 / ios ML / DL machine learning, deep learning 질문의 보완을 부탁드립니다

Comments

@sungdoolim
Copy link

#154 해결하고자 하는 문제

야학에서 배운 첫번째 딥러닝 으로 y=2x를 추론? 하는 모델을 만들고(레모네이드 판매량 예측)
모델을 따로 저장했습니다.

model.save("first_model")
시험삼아 이를 가져와서 실행 해보니 잘 되는것을 확인했습니다 .
loaded = tf.keras.models.load_model("first_model")

혹시 안드로이드에 이를 적용해 보는 방법을 알고 계신분이 계실까요??

saved_model_dir='first_model'
converter=tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.target_spec.supported_ops=[tf.lite.OpsSet.TFLITE_BUILTINS,tf.lite.OpsSet.SELECT_TF_OPS]
tflite_model=converter.convert()
open('first_model.tflite','wb').write(tflite_model)

구글 검색을 통해 tflite를 만들어 내고,
10줄 내외의 코드를 작성했으며
결과적으로 안드로이드 내에서 이부분의 에러가 발생합니다.

    val input=1            
    val output=0
    tflite.run(input, output)

input 1을 넣으면 output에 1*2의 값이 2가 담겨 나오기를 기대했습니다.

여러 시도를 해보며 데이터 타입에 관한 오류메시지 / shape가 맞지 않다는 메시지를 마주했습니다.

환경

android-studio
kotlin 1.4

시도해본 방법

val input=intArrayOf(1)
val output=intArrayOf(0)
tflite.run(input, output)

@jiyongjung0
Copy link

코드를 공유해주셔서 감사합니다. 다만, 가장 중요한 오류메시지를 알려주지 않으셨습니다. ㅠㅠ
https://www.tensorflow.org/lite/guide/inference#inputs 가이드를 읽어보면 input, output이 적절한 버퍼여야할 것 같은데, 위에 보여주신 두 가지 모두 적절한 형태는 아닌 것 같습니다. 어떤 코드를 넣었을 때 어떤 오류 메시지가 나오는지 공유해주시면 좋을 것 같습니다.

일단 output이 나와야하니 intArrayOf(0)이 아니라 intArrayOf(1)은 되어야할 것 같네요. 물론 만드신 모델의 Input / output이 어떤 것인지 질문하신 내용만으로는 알 수 없습니다만...

@progh2 progh2 added 질문의 보완을 부탁드립니다 Android / iOS 안드로이드 / ios ML / DL machine learning, deep learning labels Aug 27, 2020
@progh2 progh2 added this to the 머신러닝 야학 milestone Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android / iOS 안드로이드 / ios ML / DL machine learning, deep learning 질문의 보완을 부탁드립니다
Projects
None yet
Development

No branches or pull requests

3 participants