Reputation: 5803
I created a custom input_func
and converted a keras model into tf.Estimator
for training. However, it keeps throwing me error.
Here is my model summary. I have attempted to set the Input
layer with batch_shape=(16, 320, 320, 3)
for testing but the problem still persits
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
for conversion. I also create a input_fn
for training:
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)
And it throws me this error
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.
Upvotes: 2
Views: 5243
Reputation: 105
I had the same problem. In input_fun, if you look at images in line "return {'input_images': images}, labels", you'll see that your tensor has no shape. You have to call set_shape for each image. Look at https://github.com/tensorflow/models/blob/master/official/resnet/imagenet_main.py, they call vgg_preprocessing.preprocess_image to set the shape
Upvotes: 1