pycaffeに基づいてゼロからmnistを書く(第1編)--txtファイルを生成する


問題:
1.F0725 23:05:55.042811  4306 common.cpp:158] Check failed: error == cudaSuccess (10 vs. 0)  invalid device ordinal *** Check failure stack trace: ***
set_にいるからデバイス上では2番目のgpuに設定されていますが、gpuが1つしかないため、エラーが発生するので、gpuをset_に実行する必要があります.device(0)
caffe.set_device(1)

2.F0725 23:28:49.673435  4586 image_data_layer.cpp:148] Check failed: cv_img.data Could not load 
*** Check failure stack trace: ***

           ,    ,         

  ,          ,       ,    txt           ,       ,        

--------------------------------------------------------------------------------
     :   txt               

      :
# -*- coding: utf-8 -*-
__author__ = 'xuy'

"""
    txt  ,              ,      

   :
      label(        )



"""




import commands
import os
import re
import random




train_root_dir='mnist/train'
test_root_dir='mnist/test'

train_save_name=train_root_dir+'/mytrain.txt'
test_save_name=test_root_dir+'/mytest.txt'
fw_train=open(train_save_name,'w')#        
fw_test=open(test_save_name,'w')
for parent,dirnames,filenames in os.walk(train_root_dir):#    :    1.    2.       (    ) 3.      
#    train             
    for filename in filenames:

        pattern_train=r'(\d{0,10}.png$)'
        pattern_train_png_filename=re.search(pattern_train,filename)
        if pattern_train_png_filename !=None:
            train_png_filename=pattern_train_png_filename.group(0)#    png        ,          
            train_all_file_name=os.path.join(parent,train_png_filename)#        
            # print "the full filename is: ",train_all_file_name

            train_label_FileName=train_all_file_name[-11:-10]
            # print "the train label is :",train_label_FileName

            train_WriteFile_content=train_all_file_name+' '+train_label_FileName+'
' # shuffle_train_WriteFile_content=random.sample(train_WriteFile_content,len(train_WriteFile_content)) fw_train.write(train_WriteFile_content) # print "parent is:" + parent # print "filename is:" + filename # all_file_name=os.path.join(parent,filename) # print "the full filename is: ",all_file_name # for parent,dirnames,filenames in os.walk(test_root_dir): for filename in filenames: pattern_test=r'(\d{0,10}.png$)' pattern_test_png_filename=re.search(pattern_test,filename) if pattern_test_png_filename !=None: test_png_filename=pattern_test_png_filename.group(0) test_all_file_name=os.path.join(parent,test_png_filename) # print "the full filename is: ",test_all_file_name test_label_FileName=test_all_file_name[-11:-10] test_WriteFile_content=test_all_file_name+' '+test_label_FileName+'
' # random.shuffle(test_WriteFile_content) # shuffle_test_WriteFile_content=random.sample(test_WriteFile_content,len(test_WriteFile_content)) fw_test.write(test_WriteFile_content) fw_train.close() fw_test.close()

このとき生成されるファイルには順序があり,訓練時の精度が高くなく,実験時には10%以上しかないため,順序を乱す必要がある.
システムコマンド:shuf train.txt >shuf_train.txt,これにより乱順のtxtファイルが生成されるので,次の編に進み,ネットワーク構造+トレーニングを構築することができる.