简体   繁体   English

在使用 TFLiteConverter.from_keras_model(“model.h5”) 转动 Keras“model.h5”时,在 Google Colab python 中遇到问题

[英]Having trouble turning in Google Colab python in turning a Keras “model.h5” using TFLiteConverter.from_keras_model(“model.h5”)

Having trouble turning in Google Colab python in turning a Keras model.h5 using TFLiteConverter.from_keras_model("model.h5")在使用TFLiteConverter.from_keras_model("model.h5")转动 Keras model.h5时遇到问题在 Google Colab python

I am using TensorFlow 2.2.0我正在使用 TensorFlow 2.2.0

First attempt script第一次尝试脚本

import tensorflow as tf 

converter = tf.lite.TFLiteConverter.from_keras_model("model.h5")

tflite_model = converter.convert()

open("Robot_Eyes.tflite", "wb").write(tflite_model)

And Error gotten错误得到了

AttributeError                            Traceback (most recent call last)

<ipython-input-22-e8e8d3a7c79e> in <module>()

13 #new_model= tf.keras.models.load_model(filepath="model.h5")

14 

--->15 converter = tf.lite.TFLiteConverter.from_keras_model("model.h5")

16 

17 tflite_model = converter.convert()

/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py in from_keras_model(cls, model)

426     # to None.

427     # Once we have better support for dynamic shapes, we can remove this.

-->428     if not isinstance(model.call, _def_function.Function):

429       # Pass `keep_original_batch_size=True` will ensure that we get an input

430       # signature including the batch dimension specified by the user.

AttributeError: 'str' object has no attribute 'call'

Second attempt第二次尝试

import tensorflow as tf 

new_model= tf.keras.models.load_model(filepath="model.h5")

converter = tf.lite.TFLiteConverter.from_keras_model(new_model)

tflite_model = converter.convert()

open("model.tflite", "wb").write(tflite_model)

And 2nd Error gotten第二个错误得到了

OSError                                   Traceback (most recent call last)

<ipython-input-23-2344f7b515a1> in <module>()

11 import tensorflow as tf

12 

--->13 new_model= tf.keras.models.load_model(filepath="model.h5")

14 

15 converter = tf.lite.TFLiteConverter.from_keras_model(new_model)

3 frames

/usr/local/lib/python3.6/dist-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)

171         if swmr and swmr_support:

172             flags |= h5f.ACC_SWMR_READ

-->173         fid = h5f.open(name, flags, fapl=fapl)

174     elif mode == 'r+':

175         fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (truncated file: eof = 40894464, sblock->base_addr = 0, stored_eof = 159686248)

I don't know what is wrong and I've been trying to solve it.我不知道出了什么问题,我一直在努力解决它。 Thanks for the help.谢谢您的帮助。

Got it to work让它工作

!pip install tensorflow==1.15.0

import tensorflow as tf

print(tf.__version__)

converter = tf.lite.TFLiteConverter.from_keras_model_file("robot_eyes2.h5")

tflite_model = converter.convert()

open("Robot_Eyes.tflite", "wb").write(tflite_model)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM