Ich habe versucht, einen Wrapper zu entwerfen, der die vorgefertigten Tensorflow Slim-Modelle für einen benutzerdefinierten Datensatz verwendet. Der Datensatz enthält 1000 Bilder von Quadraten und Dreiecken, 32x32 Graustufen. Sie sind als Datensatz/Formen/Dreiecke/und Datensatz/Formen/Quadrate/organisiert.TensorFlow Slim Vortrainierte Modelle Negative Abmessungen
Mit dem folgenden Code kann ich das Modell inception_v2 ohne Fehler trainieren. Die tf.reshape wird später durch die korrekten variablen Parameter ersetzt. Die .tfrecords-Dateien werden mit dem Skript this von Google erstellt, das die Datensätze aus der oben erwähnten Datensatzstruktur erstellt.
graph = tf.Graph()
sess = tf.InteractiveSession(graph=graph)
with graph.as_default():
name_dict, nClass = gen_dict(data_directory, path_to_labels_file)
# associate the "label" and "image" objects with the corresponding features read from
# a single example in the training data file
label, image = getImage("datasets/shapes/train-00000-of-00001", height, width, nClass)
# associate the "label_batch" and "image_batch" objects with a randomly selected batch---
# of labels and images respectively
imageBatch, labelBatch = tf.train.shuffle_batch(
[image, label], batch_size=bsize,
capacity=2000,
min_after_dequeue=1000)
with sess.as_default():
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
sess.run(tf.global_variables_initializer())
batch_xs, batch_ys = sess.run([imageBatch, labelBatch])
print('ran shuffle batch')
print(tf.shape(batch_xs))
print(tf.shape(batch_ys))
# batch_xs = tf.expand_dims(batch_xs, 2)
batch_xs = tf.reshape(batch_xs, [100, 32, 32, 1])
print(tf.shape(batch_xs))
logits, end_points = inception.inception_v2(batch_xs,
num_classes=2,
is_training=True)
predictions = end_points['Predictions']
logits = end_points['Logits']
tf.losses.softmax_cross_entropy(batch_ys, logits)
total_loss = slim.losses.get_total_loss()
optimizer = tf.train.GradientDescentOptimizer(learning_rate=.001)
train_tensor = slim.learning.create_train_op(total_loss, optimizer)
slim.learning.train(train_tensor,
train_log_dir,
number_of_steps=1000)
Das Problem, das ich habe, ist mit anderen Modellen. Mit inception_v1, mit den gleichen Argumenten, bekomme ich folgende Fehlermeldung:
File "model_test.py", line 62, in <module>
is_training=True)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/contrib/slim/python/slim/nets/inception_v1.py", line 349, in inception_v1
net, [7, 7], stride=1, scope='MaxPool_0a_7x7')
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args
return func(*args, **current_args)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 131, in avg_pool2d
outputs = layer.apply(inputs)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 492, in apply
return self.__call__(inputs, *args, **kwargs)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 441, in __call__
outputs = self.call(inputs, *args, **kwargs)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/layers/pooling.py", line 276, in call
data_format=utils.convert_data_format(self.data_format, 4))
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 1741, in avg_pool
name=name)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 48, in _avg_pool
data_format=data_format, name=name)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2508, in create_op
set_shapes_for_outputs(ret)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1873, in set_shapes_for_outputs
shapes = shape_func(op)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1823, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn
debug_python_shape_fn, require_shape_fn)
File "/home/chakicherla3/tf_slim_image_classification/models/slim/python/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 676, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Negative dimension size caused by subtracting 7 from 1 for 'InceptionV1/Logits/MaxPool_0a_7x7/AvgPool' (op: 'AvgPool') with input shapes: [100,1,1,1024].
ich einen ähnlichen Fehler erhalten mit inception_v3. Mit vgg_16 und vgg_19 erhalte ich:
ValueError: Negative dimension size caused by subtracting 7 from 1 for 'vgg_16/fc6/convolution' (op: 'Conv2D') with input shapes: [100,1,1,512], [7,7,512,4096].
Kann jemand Einblick in diese Fehler geben? Was könnte der Unterschied zwischen inception_v1 und inception_v2 sein, der zum Absturz führen würde, und wie unterscheiden sich die Startmodelle davon? Ich habe diesen Datensatz noch nicht mit ResNet ausprobiert, aber ich vermute, dass damit ein ähnlicher Fehler auftreten wird.
Als Referenz wird dieser Beispielcode basiert auf dem ‚Arbeitsbeispiel‘ mit dem tf schlanke Dokumentation, befindet here
Das System es ausgeführt wird, ist mit Python 2.7.10 mit Tensorflow-GPU 1.2.0 . Es ist ein Xeon System mit 4 Nvidia Titan X GPUs, auf Ubuntu 14.10.
Danke! Wenn Sie zusätzliche Systemkonfigurationen oder die getImage-Funktion benötigen, kann ich diese auch bereitstellen!
Das Problem ist die Eingabegröße. Zum Beispiel funktioniert das VGG-Netzwerk nur für 224x224. –
Danke @vijaym. Weißt du, warum inception v2 mit diesen Daten arbeitet, aber nicht mit den anderen? Wenn die Größe die Voraussetzung ist, sollte nicht auch v2 einen Fehler werfen? –