Ich bin neu bei Tensorflow und habe die build_image_data.py
Datei und Tutorial verwendet here gefunden.Datensätze nicht korrekt aus der TFRecord-Datei lesen?
Ich habe ein kleines konnektives neuronales Netzwerk gebaut, um meinen eigenen Datensatz mit 2 Klassen zu klassifizieren. Als ich meinen Code lief, bekam ich Fehler im Zusammenhang mit einer Umgestaltung, im Grunde sind meine Bilder 72x72 RGB
Pixel. Die von mir definierte Form war also [72, 72, 3]
. Ich bekam dann InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 14040 values, but the requested shape has 15552
. Jetzt sollte es 15552
Werte sein, die ich als 72*72*3 = 15552
dachte. Wenn es nur 14040
dann vielleicht etwas mit meinem Bild nicht stimmt?
Ich nahm die Bilder selbst oder habe sie von Google, und verwendet ein Java-Programm, um sie alle auf 72x72
Pixel Größe zu ändern.
Ich habe versucht, eval()
das Bild, wie sie in das Modell kommen, aber es gibt keine Ausgabe und das ganze Ding hängt nur für eine Minute, bis ich es abstellen.
sess = tf.InteractiveSession()
filename = "../../dataset/traffic_sign/train-00000-of-00001"
# convert filename to a queue for an input pipeline.
filenameQ = tf.train.string_input_producer([filename], num_epochs=None)
# OUTPUT = AttributeError: 'FIFOQueue' object has no attribute 'eval'
print(filenameQ.eval())
# object to read records
recordReader = tf.TFRecordReader()
# read the full set of features for a single example
key, fullExample = recordReader.read(filenameQ)
# NO OUTPUT: program hangs
print(fullExample.eval())
# parse the full example into its' component features.
features = tf.parse_single_example(
fullExample,
features={
'image/height': tf.FixedLenFeature([], tf.int64),
'image/width': tf.FixedLenFeature([], tf.int64),
'image/colorspace': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
'image/channels': tf.FixedLenFeature([], tf.int64),
'image/class/label': tf.FixedLenFeature([], tf.int64),
'image/class/text': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
'image/format': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
'image/filename': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
'image/encoded': tf.FixedLenFeature([], dtype=tf.string, default_value='')
})
# now we are going to manipulate the label and image features
label = features['image/class/label']
image_buffer = features['image/encoded']
# Decode the jpeg
with tf.name_scope('decode_jpeg', [image_buffer], None):
# decode turns tensor of type string. 0-D the JPEG encoded image
# to tensor of type uint8. 3-D with shape [height, width, channels]
image = tf.image.decode_jpeg(image_buffer, channels=3)
image = tf.reshape(image, [HEIGHT, WIDTH, NUM_CHANNELS])
image = tf.to_float(image, "ToFloat")
# re-define label as a "one-hot" vector
# it will be [0,1] or [1,0] here.
# This approach can easily be extended to more classes
label = tf.one_hot(label - 1, NUM_CLASSES, dtype=tf.int64)
init = tf.global_variables_initializer()
sess.run(init)
# NO OUTPUT: program hangs
print(label.eval())
Wenn ich geschaffen, um die TFRecord Datei ich das Beispiel gefolgt here mit einer Etikettendatei mylabels.txt
enthält go
und stop
und meine Verzeichnisstruktur ist wie folgt:
traffic_sign/train/go/go*.jpeg
traffic_sign/train/stop/stop*.jpeg
traffic_sign/validation/go/go*.jpeg
traffic_sign/validation/stop/stop*.jpeg
ich den Befehl:
python build_image_data.py --train_directory=./train --output_directory=./ \
--validation_directory=./validation --labels_file=mylabels.txt \
--train_shards=1 --validation_shards=1 --num_threads=1
Die Datensatzdatei wurde erstellt und enthält nur viele Bytes.
Ich habe keine Ahnung, wie man das löst, ich weiß nicht, ob ich einen Fehler bei der Erstellung des Datensatzes gemacht habe. Aber das Bild sollte 72x72x3
sein, also weiß ich nicht, warum es einen Tensor in meinem Modell mit 14040
Werten gibt. Und die Tatsache, dass ich einen Tensor nicht auswerten kann und das Programm einfach hängt, erlaubt mir nicht zu debuggen.
Hilfe VIEL
geschätzt