简体   繁体   English

用于TensorFlow.js的Tensorflow转换Keras模型

[英]Tensorflow converting keras model for tensorflowjs

Using standard code import tensorflow as tf import tensorflowjs as tfjs 使用标准代码将tensorflow导入为tf将tensorflowjs导入为tfjs

 tfjs_target_dir = 'c:/files'
 model = tf.keras.applications.InceptionV3(
     include_top=True,
     weights='imagenet',
     input_tensor=None,
     input_shape=None,
     pooling=None,
     classes=1000
 )
 tfjs.converters.save_keras_model(model, tfjs_target_dir)

I get the following error 我收到以下错误

File "C:\\Program Files\\python36\\lib\\site-packages\\tensorflow\\python\\client\\session.py", line 1321, in _do_run run_metadata) 文件“ C:\\ Program Files \\ python36 \\ lib \\ site-packages \\ tensorflow \\ python \\ client \\ session.py”,行1321,在_do_run run_metadata中)

File "C:\\Program Files\\python36\\lib\\site-packages\\tensorflow\\python\\client\\session.py", line 1340, in _do_call raise type(e)(node_def, op, message) 文件“ C:\\ Program Files \\ python36 \\ lib \\ site-packages \\ tensorflow \\ python \\ client \\ session.py”,行1340,在_do_call中引发类型(e)(node_def,op,message)

FailedPreconditionError: Attempting to use uninitialized value conv2d_98/kernel [[Node: _retval_conv2d_98/kernel_0_0 = _RetvalT=DT_FLOAT, index=0, _device="/job:localhost/replica:0/task:0/device:CPU:0"]] FailedPreconditionError:尝试使用未初始化的值conv2d_98 / kernel [[节点:_retval_conv2d_98 / kernel_0_0 = _RetvalT = DT_FLOAT,索引= 0,_device =“ / job:localhost /副本0 /任务:0 /设备:CPU:0”]]

Have you tried to provide an input shape? 您是否尝试提供输入形状?

eg 例如

if K.image_data_format() == 'channels_first':
    input_shape = (3, img_height, img_width)
else:
    input_shape = (img_height, img_width, 3)

with img_height/width is the size of the pictures you want to predict img_height / width是您要预测的图片大小

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

相关问题 如何在将 keras 模型转换为 TensorflowJS 层模型的同时对其进行量化? - How can I quantize a keras model while converting it to a TensorflowJS Layers Model? 将 tensorflow/keras 模型转换为 tensorflow lite 模型时出现的问题 - Issues when converting tensorflow/keras model to tensorflow lite model tensorflowjs 和 keras 在相同模型和张量上的不同结果 - Different results for tensorflowjs and keras on same model and tensor 在 TF2 中将 Keras RNN 模型转换为 TensorFlow Lite 模型 - Converting Keras RNN model to TensorFlow Lite model in TF2 将 Keras 模型权重和架构转换为 TensorFlow Lite 模型 - Converting Keras Model Weights and Architecture to TensorFlow Lite Model 将 Keras 模型转换为 tensorflow 模型给了我错误 - Converting Keras model as tensorflow model gives me error 将 tfjs_layers_model 转换为 Keras 且 TensorFlow > 2.1 时出现 AttributeError - AttributeError when converting tfjs_layers_model to Keras with TensorFlow > 2.1 使用TocoConverter.from_keras_model_file将Keras模型转换为Tensorflow-Lite时出现问题 - Problem converting Keras model to Tensorflow-Lite using TocoConverter.from_keras_model_file 无法使用tensorflow.js_converter将keras模型转换为tfjs层 - Not able to convert keras model to tfjs layers using tensorflowjs_converter Keras模型到tensorflow.keras - Keras model to tensorflow.keras
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM