我在TensorFlow中使用傳輸學習。我需要使用Inception V3模型來計算圖片的特徵向量。我的代碼JPG格式圖片的計算沒有問題,但是PNG格式的計算會出錯。如何使用Inception v3模型來計算傳輸學習中的PNG圖像的特徵向量
# read model
with gfile.FastGFile(os.path.join(MODEL_DIR, MODEL_FILE), 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
bottleneck_tensor, jpeg_data_tensor = tf.import_graph_def(graph_def, return_elements=[BOTTLENECK_TENSOR_NAME, JPEG_DATA_TENSOR_NAME])
......
# get imagepath
image_path = get_image_path(image_lists, INPUT_DATA, index, category)
# read image
image_data = gfile.FastGFile(image_path, 'rb').read()
# calculate the feature vector
# **This statement is wrong when png images**
bottleneck_values = sess.run(bottleneck_tensor, {jpeg_data_tensor: image_data})
控制檯錯誤包括:
......
Not a JPEG file: starts with 0x89 0x50
......
InvalidArgumentError (see above for traceback): Invalid JPEG data, size 19839
[[Node: import/DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_import/DecodeJpeg/contents_0)]]
我想錯了鑰匙是讀取代碼的圖片,但我不知道如何修改它支持PNG格式,可有人幫我?
謝謝
謝謝。我找到了一個解決方案。儘管我無法修改它以支持PNG格式,但我可以讀取PNG圖像並將其轉換爲JPEG格式。 –