简体   繁体   中英

Tensorflow converting keras model for tensorflowjs

Using standard code import tensorflow as tf import tensorflowjs as 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)

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)

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"]]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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