python - TFSlim ValueError Can not squeeze dim[1], expected a dimension of 1, got 3 for 'vgg_16/fc8/squeezed' (op: 'Squeeze') with input shapes: [3,3,3,2] -
trying fine-tune tensorflow slim vgg16 net on different set of class labels ( 2 ) excluding fc8. on execution getting error.
error
logits, _ = vgg.vgg_16(images, num_classes=num_classes, is_training=true) /models/slim/nets/vgg.py", line 178, in vgg_16 net = tf.squeeze(net, [1, 2], name='fc8/squeezed') /anaconda/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 2273, in squeeze --- stack trace omitted ----- /anaconda/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 675, in _call_cpp_shape_fn_impl raise valueerror(err.message) valueerror: can not squeeze dim[1], expected dimension of 1, got 3 'vgg_16/fc8/squeezed' (op: 'squeeze') input shapes: [3,3,3,2].
code
batch_size = 3 num_classes = 2 def load_batch(): filepaths, labels = read_label_file(train_labels_file) images = ops.convert_to_tensor(filepaths, dtype=dtypes.string) labels = ops.convert_to_tensor(labels, dtype=dtypes.int32) input_queue = tf.train.slice_input_producer([images, labels],shuffle=false) file_content = tf.read_file(input_queue[0]) image = tf.image.decode_jpeg(file_content, channels=num_channels) label = input_queue[1] image.set_shape([387,408,3]) size = tf.constant([224,224],dtype=tf.int32) image = tf.image.resize_images(image,size) image_batch, label_batch = tf.train.batch([image, label],batch_size=batch_size , num_threads=1) return image_batch , label_batch tf.graph().as_default(): tf.logging.set_verbosity(tf.logging.info) images,labels = load_batch() slim.arg_scope(vgg.vgg_arg_scope()): logits, _ = vgg.vgg_16(images, num_classes=num_classes, is_training=true) ....
can try defining batch directly:
with tf.graph().as_default(): tf.logging.set_verbosity(tf.logging.info) images = tf.randon_uniform([batch_size, 224, 224, 3]) labels = tf.randon_uniform([batch_size], max_value=num_clases) slim.arg_scope(vgg.vgg_arg_scope()): logits, _ = vgg.vgg_16(images, num_classes=num_classes, is_training=true)
also can debug shapes of tensors images , labels before passing them vgg.vgg_16
Comments
Post a Comment