我创建了一个自定义input_func
并将 keras 模型转换为tf.Estimator
为了训练。但是,它一直给我带来错误。
-
这是我的模型摘要。我试图设置Input
层与batch_shape=(16, 320, 320, 3)
进行测试,但问题仍然存在
inputs = Input(batch_shape=(16, 320, 320, 3), name='input_images')
outputs = yolov2.predict(intputs)
model = Model(inputs, outputs)
model.compile(optimizer= tf.keras.optimizers.Adam(lr=learning_rate),
loss = compute_loss)
-
I used tf.keras.estimator.model_to_estimator
用于转换。我还创建了一个input_fn
为了训练:
def input_fun(images, labels, batch_size, shuffle=True):
dataset = create_tfdataset(images, labels)
dataset = dataset.shuffle().batch(batch_size)
iterator = dataset.make_one_shot_iterator()
images, labels = iterator.next()
return {'input_images': images}, labels
estimator = tf.keras.estimator.model_to_estimator(keras_model=model)
estimator.train(input_fn = lambda: input_fn(images, labels, 32),
max_steps = 1000)
-
它引发了我这个错误
input_tensor = Input(tensor=x, name='input_wrapper_for_' + name)
...
File "/home/dat/anaconda3/envs/webapp/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 1309, in __init__
self._batch_input_shape = tuple(input_tensor.get_shape().as_list())
"as_list() is not defined on an unknown TensorShape.")
ValueError: as_list() is not defined on an unknown TensorShape.
我有同样的问题。
在 input_fun 中,如果您查看“return {'input_images': images}, labels”行中的图像,您会发现您的张量没有形状。您必须为每个图像调用 set_shape 。
看着https://github.com/tensorflow/models/blob/master/official/resnet/imagenet_main.py,他们调用 vgg_preprocessing.preprocess_image 来设置形状
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)