在Google Colab上按照这个教程训练我的模型后,当我尝试运行model.export('image_classifier.tflite', 'image_labels.txt')
时,显示如下错误:
---------------------------------------------------------------------------AttributeError Traceback (most recent call last)<ipython-input-37-4d5419f8b12d> in <module>()----> 1 model.export('image_classifier.tflite', 'image_labels.txt')1 frames/usr/local/lib/python3.6/dist-packages/tensorflow_examples/lite/model_customization/core/task/image_classifier.py in export(self, tflite_filename, label_filename, **kwargs) 185 else: 186 quantized = False--> 187 self._export_tflite(tflite_filename, label_filename, quantized) 188 else: 189 raise ValueError('Model Export Format %s is not supported currently.' %/usr/local/lib/python3.6/dist-packages/tensorflow_examples/lite/model_customization/core/task/classification_model.py in _export_tflite(self, tflite_filename, label_filename, quantized) 130 quantized: boolean, if True, save quantized model. 131 """--> 132 converter = tf.lite.TFLiteConverter.from_keras_model(self.model) 133 if quantized: 134 converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]AttributeError: type object 'TFLiteConverter' has no attribute 'from_keras_model
回答:
这个问题通过更新TensorFlow版本得以解决,我之前使用的是1.X版本,而TensorFlow在新版本中有了很大的变化。如果你在使用Google的Colab,版本仍然是1.X,很快将升级到2.0,所以建议你尝试以其他方式构建你的模型。