Skip to content

tensorflow => tensorflow.js 변환에 대해 질문드립니다. #1140

Open

Description

@donhaklee

안녕하세요! 어제까지 야학 공부를 끝낸 학생입니다.
1주 전에 그림<=>사진 웹 프로그램을 만들기 위해 질문드렸고
도움이 되는 자료를 많이 주셨는데 활용을 못해서
1주간 열심히 시도해봤지만 실패하여 염치없이 다시 질문하게 되었습니다..ㅠ

# 해결하고자 하는 문제
https://www.tensorflow.org/tutorials/generative/style_transfer
해당 사이트의 파이썬 코드를
teachable machine에 tensorflow와 tensorflow.js가 있듯이
자바스크립트 코드로 변환해보려 시도를 했는데 잘 안되어 질문드립니다.

https://www.tensorflow.org/js/tutorials/conversion/import_keras?hl=ko
https://www.youtube.com/watch?v=yWBM2-Rx47M
우선 해당 사이트와 유튜브를 참고하며
파이썬을 자바스크립트로 바꾸는 작업을 1주일동안 찾아가며 해보는 중인데
정말 해결이 안돼서 어렵네요 ㅠ 답도 다 나와있는데 말이죠...

# 코드 혹은 오류

<해당 방법으로는 model.json 생성에 성공했지만 경로 입력시 오류가 발생했습니다.>
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(4, input_dim=2, activation='tanh'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['binary_accuracy'])
tfjs.converters.save_keras_model(model,'models')

tensorflowjs_converter --input_format keras \C:\Users\User\Desktop\picturetophoto\model.json \C:\Users\User\Desktop\picturetophoto

에러 : ValueError: Nonexistent path to HDF5 file: \C:\Users\User\Desktop\picturetophoto\models\model.json

<.h5를 생성하는 해당방법엔 해당오류가 있었습니다>
model = tf.keras.models.Sequential()
model.save('C:\Users\User\Desktop\picturetophoto')

에러 : File "c:\Users\User\Desktop\picturetophoto\model.py", line 74 -3: truncated \UXXXXXXXX escape
model.save('C:\Users\User\Desktop\picturetophoto') ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

이렇게 2가지 방향으로 변환을 시키려 시도했는데 둘 다 잘 안되어 질문드립니다.

되도록 json을 로드하는 방법이 아닌 자바스크립트 코드로 바꿔 수정이 가능하도록 하고 싶은데 혹시 방법이 있을까요??

Activity

  1. kheedogg commented on Jul 28, 2021

    @kheedogg
    Collaborator

    해당 코드를
    model.save('C:/Users/User/Desktop/picturetophoto')
    아래의 코드로 바꾸어 돌려보시고 안되시면 답글 달아주세요!
    model.save('C:/Users/User/Desktop/picturetophoto/model.h5')

  2. donhaklee commented on Jul 29, 2021

    @donhaklee
    Author

    File "c:\Users\User\Desktop\picturetophoto\model.py", line 74
    model.save('C:\Users\User\Desktop\picturetophoto\model.h5')
    ^
    SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

    말씀하신대로 해봤는데 해당 에러가 뜨네요

    디렉터리 현황은 이렇습니다!
    picturetophoto(폴더)
    -model.py
    -models(폴더)
    ---group1-shard1of1.bin
    ---model.json

  3. kheedogg commented on Jul 29, 2021

    @kheedogg
    Collaborator

    파일 경로 내의 \ 를 / 또는 \ \ 으로 변경하시면 말씀하신 오류는 해결되실것같습니다 :)

  4. donhaklee commented on Jul 29, 2021

    @donhaklee
    Author

    아하ㅠㅠㅠ 감사합니다.. 이런 어처구니 없는 실수를 1주일동안 붙잡고 있었네요.. 이후 계속 해보도록 하겠습니다!

  5. donhaklee commented on Jul 29, 2021

    @donhaklee
    Author

    앗.. 그런데 결국 이 방법이 json을 생성하는 방법인데 혹시 js코드로 변환가능한 방법이 있나요??
    혹시나 변환 불가능하면 html에 적용 수정이 어려울것같아서요..ㅠ

  6. blackdew commented on Jul 29, 2021

    @blackdew
    Collaborator

    js 변환 코드가 필요하면 직접 작성을 하셔야 할거에요.
    야학에 tensorflowjs 수업이 tensorflow python 코드와 동일한 내용으로 만들어져 있어서
    찹고하시면 변환하실 수 있을 겁니다.

    또한, 직접 경험은 없어서 경험을 나누어 드리기는 어렵지만,
    모델 코드가 다 작성이 안되어있어도 모델을 올려서 predict하는 건 가능할 거에요.

  7. donhaklee commented on Jul 29, 2021

    @donhaklee
    Author

    감사합니다! 덕분에 방향성을 잡을 수 있게 됐네요ㅠ

  8. added
    ML / DL
    on Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ML / DL

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions