내 모델을 공급하기 위해 tensorflow 레코드를 만들고 싶습니다. 지금까지 다음 코드를 사용하여 uint8 numpy 배열을 TFRecord 형식으로 저장했습니다. 나는이 예제 코드float numpy 배열이있는 tensorflow 레코드
features = tf.parse_single_example(example, features={
'image_raw': tf.FixedLenFeature([], tf.string),
'map_raw': tf.FixedLenFeature([], tf.string),
'label_raw': tf.FixedLenFeature([], tf.string),
})
image = tf.decode_raw(features['image_raw'], tf.uint8)
image.set_shape(params.IMAGE_HEIGHT*params.IMAGE_WIDTH*3)
image = tf.reshape(image_, (params.IMAGE_HEIGHT,params.IMAGE_WIDTH,3))
map = tf.decode_raw(features['map_raw'], tf.uint8)
map.set_shape(params.MAP_HEIGHT*params.MAP_WIDTH*params.MAP_DEPTH)
map = tf.reshape(map, (params.MAP_HEIGHT,params.MAP_WIDTH,params.MAP_DEPTH))
label = tf.decode_raw(features['label_raw'], tf.uint8)
label.set_shape(params.NUM_CLASSES)
하고 잘 작동하고 읽을
def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
def _bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def _floats_feature(value):
return tf.train.Feature(float_list=tf.train.FloatList(value=[value]))
def convert_to_record(name, image, label, map):
filename = os.path.join(params.TRAINING_RECORDS_DATA_DIR, name + '.' + params.DATA_EXT)
writer = tf.python_io.TFRecordWriter(filename)
image_raw = image.tostring()
map_raw = map.tostring()
label_raw = label.tostring()
example = tf.train.Example(features=tf.train.Features(feature={
'image_raw': _bytes_feature(image_raw),
'map_raw': _bytes_feature(map_raw),
'label_raw': _bytes_feature(label_raw)
}))
writer.write(example.SerializeToString())
writer.close()
. 이제 uint8 대신 float numpy 배열 인 배열 "map"을 사용하여 동일한 작업을 수행하려고합니다.이 작업을 수행하는 방법에 대한 예제를 찾을 수 없었습니다. 나는 _floats_feature 함수를 시도했다. _floats_feature는 배열에 스칼라를 전달하면 작동하지만 배열에는 그렇지 않다. with uint8 직렬화는 tostring() 메서드로 수행 할 수 있습니다.
어떻게 float numpy 배열을 serialize 할 수 있습니까? 어떻게 다시 읽을 수 있습니까?
야로 슬라브는 수레 목록이 필요하다고 언급했는데, num_arr은 목록이 아니므로 어떻게 든 플랫 화해야하고 모델에 전달하기 전에 모양을 수정해야합니다. – cberkay