imagenet-multiGPU.torch icon indicating copy to clipboard operation
imagenet-multiGPU.torch copied to clipboard

how to save my image data into torch format (.t7)

Open zq1314 opened this issue 7 years ago • 3 comments

default this is my image data @Smerity @bobbens @pedropgusmao @soumith @ppwwyyxx

zq1314 avatar Aug 09 '18 08:08 zq1314

@Smerity @bobbens @pedropgusmao @soumith @ppwwyyxx

zq1314 avatar Aug 09 '18 08:08 zq1314

how prepare my dataset in torch file format (.t7)?? @Smerity @bobbens @pedropgusmao @soumith @ppwwyyxx

zq1314 avatar Aug 09 '18 09:08 zq1314

Dear zq1314;

I wrote a lua code before for this kind of work. You can edit it how you need.


require 'image'

torch.setdefaulttensortype('torch.FloatTensor')

dirname = '.'
dirs = io.popen('ls ' .. dirname)
counter = 0
for dir in dirs:lines() do
	
	files = io.popen('ls ' .. dir)

	for file in files:lines() do
	if(string.sub(file,-3)=="jpg") then
		counter = counter + 1
   	end 
	end  

end

classcnt = 0
local allpics = torch.Tensor(counter,3,231,231)
local allclass = torch.Tensor(counter)

dirname = '.'
dirs = io.popen('ls ' .. dirname)
counter = 0
for dir in dirs:lines() do
	
	files = io.popen('ls ' .. dir)

if(not string.find(dir,"%.")) then
print(dir)
 classcnt = classcnt + 1  end 
	for file in files:lines() do
	if(string.sub(file,-3)=="jpg") then
		counter=counter+1
		local img = image.load(dir.."/"..file,3)
		allpics[counter]= img
		allclass[counter] = classcnt
   	end 
	end  

end

torch.save("data.t7",allpics)
torch.save("classes.t7",allclass)

mhmtsarigul avatar Nov 07 '18 16:11 mhmtsarigul