2017-05-05 3 views
0

이 변환을위한 리소스를 찾는 데 어려움이 있습니다. mnist 데이터 집합이 .idx3-ubyte 인 동안 일부 샘플 코드의 입력 데이터는 .pkl 형식으로 표시됩니다. 그리고 컴퓨팅 비전에 사용되는 데이터 세트의 형식은 다양합니다. 어떤 형식에도 익숙하지 않고 일부 문제가이 문제에 부딪 힐 수 있다면 고맙겠습니다. 고맙습니다.jpg 데이터 세트를 CNN에 대한 .pkl로 신속하게 변환하는 방법은 무엇입니까?


업데이트 : 지금은 성공적으로 아래의 코드를 사용하여 .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 파일을 만들지 못했습니다.

모든 입력에 감사드립니다.

답변

0

Pickle은 데이터와 함께 python 개체의 구조에 대한 정보를 저장합니다. 간단한 텐서 (tensor)의 경우, 이것은 아마도 필요하지 않습니다.

대신, 이진 형식의 행렬 데이터를 파일로 덤프하고 다시 메모리에 다시로드하는 것이 일반적인 방법입니다. 나는 ".idx3-ubyte"가 MNIST 그림 데이터 세트에 사용 된 것과 같은 것이라고 생각합니다.

파이썬과 numpy를 사용하는 경우 npy.load 및 np.dump 함수를 사용하여 프로세스를 간소화하는 numpy의 .npy 형식을 사용하는 것이 더 좋습니다. https://docs.scipy.org/doc/numpy-1.12.0/reference/generated/numpy.load.html.

당신이 이진 데이터 덤프를로드해야하는 경우

는 입력 https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfile.html

+0

감사를 보라. 그 이미지와 레이블을 .tfrecords 형식으로 성공적으로로드했지만,이 형식으로 파일을로드하여 cnn을 학습하는 코드를 찾을 수 없습니다. –

+0

tf가 tensorflow를 의미한다고 가정 할 때,이 점에 대해서는 경험이 없습니다. 죄송합니다. – pixelou

관련 문제