我正在做一个Tensorflow CNN。读取tf.records
时,我不知道解码图像时适合哪种类型的数据。我在多个教程中看到,应该在进入模型之前进行重塑。我想知道我是否做对了。这是我的代码:
def read_file(filename_queue):
#Funcion para leer el archivo tf.record, y retornamos el next recrod
reader=tf.TFRecordReader()
_,serialized_example=reader.read(filename_queue)
#Se decodifica el tf.record retornando un diccionario
feature={'train/image':tf.FixedLenFeature([],tf.string),
'train/label':tf.FixedLenFeature([],tf.int64)}
features=tf.parse_single_example(serialized_example,features=feature)
#Convertimos el string a numeros de los decodificados features
image=tf.decode_raw(features['train/image'],tf.float32)* (1 / 255.0)
#Convertimos a datos
label=tf.cast(features['train/label'],dtype=tf.int32)
#Reshape data
image=tf.reshape(image,[224,224,3])
return image,label