저는 tfrecords에서 'image'(2000)와 'landmarks'(388)을 읽습니다.tfrecords에서 데이터를 읽을 때의 모양에 대해서
이것은 코드의 일부입니다.
label = tf.decode_raw(features['label'], tf.float32) # problem is here
#Error: InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 582 values, but the requested shape has 388
또는 'float16과'로 : 여기
label = tf.decode_raw(features['label'], tf.float16) # problem is here
#Error: InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 1164 values, but the requested shape has 388
내가 'float32'에서 'float64'을 변경할 때
filename_queue = tf.train.string_input_producer([savepath])
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(serialized_example, features={'label': tf.FixedLenFeature([], tf.string), 'img_raw':tf.FixedLenFeature([], tf.string), })
image = tf.decode_raw(features['img_raw'], tf.uint8)
image = tf.reshape(image, [224, 224, 3])
image = tf.cast(image, tf.float32)
label = tf.decode_raw(features['label'], tf.float64) # problem is here
label = tf.cast(label, tf.float32)
label = tf.reshape(label, [388])
오류가
InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 291 values, but the requested shape has 388.
입니다 어떻게 tfrecords를 만들었습니까? (간단하게하기 위해 코드를 단순화했습니다)
writer = tf.python_io.TFRecordWriter(savepath)
for i in range(number_of_images):
img = Image.open(ImagePath[i]) # load one image from path
landmark = landmark_read_from_csv[i] # shape of landmark_read_from_csv is (number_of_images, 388)
example = tf.train.Example(features=tf.train.Features(feature={
"label": tf.train.Feature(bytes_list=tf.train.BytesList(value=[landmark.tobytes()])),
'img_raw': tf.train.Feature(bytes_list=tf.train.BytesList(value=[img.tobytes()]))}))
writer.write(example.SerializeToString())
writer.close()
내가 3 개 질문이 있습니다
- 이유는 데이터 형식 후 모양 변화가 변경된 않습니다를?
- 적절한 데이터 유형을 선택하는 방법은 무엇입니까? (때로는 'tf.float64'를 사용하여 이미지를 성공적으로 디코딩 할 수 있지만 때로는 다른 데이터 세트를 사용하여 'tf.uint8')
- tfrecords를 생성하는 데 문제가 있습니까?
감사합니다. 원본 데이터 세트의 데이터 유형을 확인하는 것을 잊었습니다. – wyp