こんにちは私はイメージ入力パイプを構築しようとしています。私の前処理トレーニングデータは、私はコードの次の行で作成しましたtfrecordsファイルに格納されている..tfrecordsバイナリファイル(タイプmissmatch)を読み書きする
def _bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
を
今img_raw = img.tostring() # typeof(img) = np.Array with shape (50, 80) dtype float64
img_label_text_raw = str.encode(img_lable)
example = tf.train.Example(features=tf.train.Features(feature={
'height': _int64_feature(height), #heigth (integer)
'width': _int64_feature(width), #width (integer)
'depth': _int64_feature(depth), #num of rgb channels (integer)
'image_data': _bytes_feature(img_raw), #raw image data (byte string)
'label_text': _bytes_feature(img_label_text_raw), #raw image_lable_text (byte string)
'lable': _int64_feature(lable_txt_to_int[img_lable])})) #label index (integer)
writer.write(example.SerializeToString())
を私はテンソルを再構築するために、バイナリデータを読み込もうそれから:
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
# Defaults are not specified since both keys are required.
features={
'label': tf.FixedLenFeature([], tf.int64),
'height': tf.FixedLenFeature([], tf.int64),
'width': tf.FixedLenFeature([], tf.int64),
'depth': tf.FixedLenFeature([], tf.int64),
'image_data': tf.FixedLenFeature([], tf.string)
})
label = features['label']
height = tf.cast(features['height'], tf.int64)
width = tf.cast(features['width'], tf.int64)
depth = tf.cast(features['depth'], tf.int64)
image_shape = tf.pack([height, width, depth])
image = tf.decode_raw(features['image_data'], tf.float64)
image = tf.reshape(image, image_shape)
images, labels = tf.train.shuffle_batch([image, label], batch_size=2,
capacity=30,
num_threads=1,
min_after_dequeue=10)
return images, labels
悲しいことに、これは動作しません。このエラーメッセージが表示されます:
ValueError: Tensor conversion requested dtype string for Tensor with dtype int64: 'Tensor("ParseSingleExample/Squeeze_label:0", shape=(), dtype=int64)' ...
TypeError: Input 'bytes' of 'DecodeRaw' Op has type int64 that does not match expected type of string.
いくつか私にこれを修正する方法のヒントを教えてもらえますか?
ありがとうございます!
UPDATE:
@mmryはどうもありがとうございました "read_and_decode" の完全なコードリスト。今度はバッチをシャッフルする際にコードが壊れます。 :
ValueError: All shapes must be fully defined: [TensorShape([Dimension(None), Dimension(None), Dimension(None)]), TensorShape([])]
どのような提案ですか?
こんにちは、あなたのtfrecordsで 'label_text'をシリアル化しました。次に、このデータをデコーダでどのように解析しますか?アドバイスをお願いしますか?ありがとう。 record_iteratorでstring_recordため – mining
record_iterator = tf.python_io.tf_record_iterator(パス=) : 例えば= tf.train.Example() example.ParseFromString(string_record) label_txt =(example.features.feature [ 'LABEL_TEXT '] .bytes_list .value [0] .decode( "utf-8")) –
monchi
上記の例では、すべてのデータ要素を繰り返して、lable文字列をデコードします。 – monchi