Reputation: 407
I am using Pybrain (neural Network library) in python for image processing. I have 196 files in a directory and it is saved in all_files in the code below. I tried to open each file and do processing on each file separately but it is taking all files data in one string, I want each file to open one by one, do processing and output here is my code:
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer
import glob
ds = SupervisedDataSet(121,121)
all_files = glob.glob('/home/vidula/Desktop/tp/inpt/./*.data')
for filename in all_files:
indata = tuple()
outdata = tuple()
with open(filename,'r')as file:
for line in file.readlines():
d = line.strip().split( ',' )
indata = indata + (d[0], )
outdata = outdata + ( d[1], )
ds.addSample(indata, outdata)
print outdata
Can anybody help me out?
Upvotes: 1
Views: 3206
Reputation: 172427
You need to reset indata and outdata before you read each file. ie
for filename in all_files:
indata = tuple()
outdata = tuple()
Upvotes: 2