-
Notifications
You must be signed in to change notification settings - Fork 45.4k
Description
inception model this issue is about
According to the tutorial, I build vgg_16 model follow the inception v3 model with flowers_data.
Here is my part of the code:
vgg_16 model:
def vgg_16_(inputs, dropout_keep_prob=0.5, num_classes=1000, is_training=True,
restore_logits=True, scope=''):
with tf.op_scope([inputs], scope, 'vgg_16'):
with scopes.arg_scope([ops.conv2d, ops.fc], stddev=0.01, weight_decay=0.0005):
net = ops.repeat_op(2, inputs, ops.conv2d, 64, [3, 3], scope='conv1')
net = ops.max_pool(net, [2, 2], scope='pool1')
net = ops.repeat_op(2, net, ops.conv2d, 128, [3, 3], scope='conv2')
net = ops.max_pool(net, [2, 2], scope='pool2')
net = ops.repeat_op(3, net, ops.conv2d, 256, [3, 3], scope='conv3')
net = ops.max_pool(net, [2, 2], scope='pool3')
net = ops.repeat_op(3, net, ops.conv2d, 512, [3, 3], scope='conv4')
net = ops.max_pool(net, [2, 2], scope='pool4')
net = ops.repeat_op(3, net, ops.conv2d, 512, [3, 3], scope='conv5')
net = ops.max_pool(net, [2, 2], scope='pool5')
net = ops.flatten(net, scope='flatten5')
net = ops.fc(net, 4096, scope='fc6')
net = ops.dropout(net, dropout_keep_prob, scope='dropout6')
net = ops.fc(net, 4096, scope='fc7')
net = ops.dropout(net, dropout_keep_prob, scope='dropout7')
net = ops.fc(net, num_classes, activation=None, scope='fc8')
return net
inference and loss
def inference(images, num_classes, for_training=False, restore_logits=False,
scope=None):
# Parameters for BatchNorm.
batch_norm_params = {
# Decay for the moving averages.
'decay': BATCHNORM_MOVING_AVERAGE_DECAY,
# epsilon to prevent 0s in variance.
'epsilon': 0.001,
}
# Set weight_decay for weights in Conv and FC layers.
with slim.arg_scope([slim.ops.conv2d, slim.ops.fc], weight_decay=0.00004):
with slim.arg_scope([slim.ops.conv2d],
stddev=0.1,
activation=tf.nn.relu,
batch_norm_params=batch_norm_params):
logits = slim.vgg_16.vgg_16_diy(
images,
dropout_keep_prob=0.5,
num_classes=num_classes,
is_training=for_training,
restore_logits=restore_logits,
scope=scope)
return logits
def loss(logits, labels, batch_size=None):
if not batch_size:
batch_size = FLAGS.batch_size
# Reshape the labels into a dense Tensor of
# shape [FLAGS.batch_size, num_classes].
sparse_labels = tf.reshape(labels, [batch_size, 1])
indices = tf.reshape(tf.range(batch_size), [batch_size, 1])
concated = tf.concat(1, [indices, sparse_labels])
num_classes = logits[0].get_shape()[-1].value
dense_labels = tf.sparse_to_dense(concated,
[batch_size, num_classes],
1.0, 0.0)
# Cross entropy loss for the main softmax prediction.
slim.losses.cross_entropy_loss(logits[0],
dense_labels,
label_smoothing=0.1,
weight=1.0)
The following error occurred when I run it:
Traceback (most recent call last):
File "/home/zzq/vgg/model/inception/bazel-bin/inception/flowers_vgg16_train.runfiles/inception/flowers_vgg16_train.py", line 41, in
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 30, in run
sys.exit(main(sys.argv))
File "/home/zzq/vgg/model/inception/bazel-bin/inception/flowers_vgg16_train.runfiles/inception/flowers_vgg16_train.py", line 37, in main
vgg_16_train.train(dataset)
File "/home/zzq/vgg/model/inception/bazel-bin/inception/flowers_vgg16_train.runfiles/inception/vgg_16_train.py", line 239, in train
scope)
File "/home/zzq/vgg/model/inception/bazel-bin/inception/flowers_vgg16_train.runfiles/inception/vgg_16_train.py", line 113, in _tower_loss
vgg_16.loss(logits, labels, batch_size=split_batch_size)
File "/home/zhouzhiqiang/vgg/model/inception/bazel-bin/inception/flowers_vgg16_train.runfiles/inception/vgg_16_model.py", line 116, in loss
num_classes = logits[0].get_shape()[-1].value
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 169, in _SliceHelper
sliced = slice(tensor, indices, sizes)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 219, in slice
return gen_array_ops.slice(input, begin, size, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 1428, in _slice
name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 693, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2179, in create_op
set_shapes_for_outputs(ret)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1633, in set_shapes_for_outputs
shapes = shape_func(op)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 928, in _SliceShape
input_shape.assert_has_rank(ndims)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_shape.py", line 605, in assert_has_rank
raise ValueError("Shape %s must have rank %d" % (self, rank))
ValueError: Shape (32, 6) must have rank 1