2017-11-05 13 views
0

저는 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 개 질문이 있습니다

  1. 이유는 데이터 형식 후 모양 변화가 변경된 않습니다를?
  2. 적절한 데이터 유형을 선택하는 방법은 무엇입니까? (때로는 'tf.float64'를 사용하여 이미지를 성공적으로 디코딩 할 수 있지만 때로는 다른 데이터 세트를 사용하여 'tf.uint8')
  3. tfrecords를 생성하는 데 문제가 있습니까?

답변

2

나는 최근에 매우 비슷한 문제를 겪었으며 개인적인 경험을 통해 나는 100 % 확실하지는 않지만 내가 요구하는 것에 대한 답을 추측 할 수 있었다고 확신합니다. byte리스트로서 부호화하고 float16float32 동일한 바이트리스트의 절반의 길이를 가지고 있기 때문에 두 N float32 값의 순서로 판독 할 수있는 경우 다른 데이터 유형이 서로 다른 길이를 갖기 때문에

  1. 목록 항목 형상 변화 또는 float16 값의 두 배입니다. 즉, 데이터 유형을 변경할 때 디코드하려고 시도하는 byte 목록은 변경되지 않지만 변경 사항은이 배열 목록에서 변경 한 부분입니다.

  2. tfrecord 파일을 생성하는 데 사용하는 데이터의 데이터 유형을 확인하고 읽고있을 때 동일한 데이터 유형을 사용하여 byte_list를 디코딩해야합니다 (numpy 목록의 데이터 유형을 .dtype 속성).

  3. 아무 것도 볼 수 없지만 틀릴 수도 있습니다.

+0

감사합니다. 원본 데이터 세트의 데이터 유형을 확인하는 것을 잊었습니다. – wyp