0
我可能在這裏做了一些愚蠢的事情,但我不確定爲什麼會出現這個錯誤。tf.train.Features TypeError:不允許位置參數
此代碼:
example = tf.train.Example(features=tf.train.Features(feature={
'image/height': _int64_feature(FLAGS.img_height),
'image/width': _int64_feature(FLAGS.img_width),
'image/colorspace': _bytes_feature(tf.compat.as_bytes(colorspace)),
'image/channels': _int64_feature(channels),
'image/format': _bytes_feature(tf.compat.as_bytes(image_format)),
'image/label': _bytes_feature(label_img_buffer),
'image/label_path': _bytes_feature(tf.compat.as_bytes(os.path.basename(lbl_path))),
'image/fn_0': _bytes_feature(tf.compat.as_bytes(os.path.basename(ex_paths[0]))),
'image/encoded_0': _bytes_feature(tf.compat.as_bytes(ex_image_buffers[0])),
'image/fn_1': _bytes_feature(tf.compat.as_bytes(os.path.basename(ex_paths[1]))),
'image/encoded_1': _bytes_feature(tf.compat.as_bytes(ex_image_buffers[1])),
'image/fn_2': _bytes_feature(tf.compat.as_bytes(os.path.basename(ex_paths[2]))),
'image/encoded_2': _bytes_feature(tf.compat.as_bytes(ex_image_buffers[2]))}))
return example
但這代碼不起作用(拋出類型錯誤的文章標題):
feature_dict={
'image/height': _int64_feature(FLAGS.img_height),
'image/width': _int64_feature(FLAGS.img_width),
'image/colorspace': _bytes_feature(tf.compat.as_bytes(colorspace)),
'image/channels': _int64_feature(channels),
'image/format': _bytes_feature(tf.compat.as_bytes(image_format)),
'image/label': _bytes_feature(label_img_buffer),
'image/label_path': _bytes_feature(tf.compat.as_bytes(os.path.basename(lbl_path))),
}
for idx, image in sorted(ex_image_buffers.iteritems()):
img_key = 'image/encoded_' + str(idx)
fn_key = 'image/fn_' + str(idx)
feature_dict[img_key] = _bytes_feature(tf.compat.as_bytes(image))
feature_dict[fn_key] = _bytes_feature(tf.compat.as_bytes(os.path.basename(ex_paths[idx])))
example = tf.train.Example(features=tf.train.Features(feature_dict))
return example
ex_image_buffers是一個列表。
據我所知,tf.train.Features以一個字典作爲參數,並且我在第一個例子和第二個例子中組裝了相同的字典(我認爲)。第二個允許我根據其他代碼調整字典,所以我寧願避免對不同字段進行硬編碼。
想法?謝謝你的幫助!
謝謝,這工作。感謝幫助。爲什麼這個要求在這裏? – user3325669
我沒有設計API,所以我不能說。您正在使用該類的構造函數,文檔(https://www.tensorflow.org/api_docs/python/tf/train/Features)僅顯示'** kwargs'作爲輸入。 –
@JimParker鏈接到您提供的文檔沒有任何內容。有沒有辦法知道這些方法做什麼,因爲文檔主要是所有方法的列表。 – deadcode