【发布时间】:2017-05-05 09:35:34
【问题描述】:
我很难找到用于这种转变的资源。我看到一些示例代码中的输入数据采用 .pkl 格式,而 mnist 数据集采用 .idx3-ubyte 格式。用于计算视觉的数据集格式也各不相同。我不熟悉任何格式,如果能对这个问题有所了解,我将不胜感激。谢谢。
更新:现在我使用下面的代码成功地以 .tfrecords 格式加载了我的图像,但由于 cnn 似乎无法读取这种格式,我仍在尝试修改 .pkl 格式的代码。但是,我的运行都失败了。
cwd='/Users/Downloads/tflearn_train/'
classes={'0','1'} #classify into 2 types
writer= tf.python_io.TFRecordWriter("train.tfrecords") #file to be produced
for index,name in enumerate(classes):
class_path=cwd+name+'/'
for img_name in os.listdir(class_path):
if (not img_name.startswith('.') and img_name != 'Thumbs.db'):
img_path=class_path+img_name #the path of every pic
img=Image.open(img_path,"r")
img= img.resize((224,224))
img_raw=img.tobytes()#transform pic into binary
example = tf.train.Example(features=tf.train.Features(feature={
"label": tf.train.Feature(int64_list=tf.train.Int64List(value=[index])),
'img_raw': tf.train.Feature(bytes_list=tf.train.BytesList(value=[img_raw]))
}))
writer.write(example.SerializeToString())
writer.close()
以上工作正常。但我试着把
write_file = open('train.pkl', 'wb')
cPickle.dump(example, write_file, -1)
cPickle.dump(example.features.feature['label'].int64_list.value, write_file, -1)
write_file.close()
循环内部和外部。到目前为止,当使用 cPickle.load 时,我未能制作一个看起来像其他 .pkl 文件的 .pkl 文件
感谢您的每一个意见。
【问题讨论】:
标签: python image neural-network pickle conv-neural-network