PKU-ICST-MIPL / DRLIH_TMM2020

3 stars 3 forks source link

get_images functions #5

Open burhanbarakli opened 2 years ago

burhanbarakli commented 2 years ago

in dataloader.py:

self.trans1=trans.Compose([trans.CenterCrop(224),trans.RandomHorizontalFlip(),trans.ToTensor(),normalize2,]) self.trans2=trans.Compose([trans.CenterCrop(224),trans.ToTensor(),]) self.trans3=trans.Compose([trans.RandomCrop(224),trans.RandomHorizontalFlip(),trans.ToTensor(),normalize,]) self.trans4=trans.Compose([trans.CenterCrop(224),trans.ToTensor(),normalize,])

def get_image(self,classid,imageid): image_path=self.path+'/'+str(classid)+'/'+str(imageid)+'.jpg'; print('get img',image_path) ori_img=Image.open(image_path) img=self.trans3(ori_img) return img

def get_image3(self,classid,imageid): image_path=self.path+'/'+str(classid)+'/'+str(imageid)+'.jpg'; print('get img',image_path) ori_img=Image.open(image_path) img=self.trans4(ori_img) return img

def get_batch_cifar_nus(self,batch_size=5): li1= list(range(self.start,self.end)) ori=torch.zeros(batch_size,3,224,224) pos=torch.zeros(batch_size,3,224,224) neg=torch.zeros(batch_size,3,224,224) for ix in range(0,batch_size): random.shuffle(li1) random.shuffle(self.li) ori[ix]=self.get_image(self.li[0],li1[0]) pos[ix]=self.get_image(self.li[0],li1[1]) neg[ix]=self.get_image(self.li[1],li1[2]) return ori,pos,neg

def get_valid(self,classidx,batch_size,bias): pic=torch.zeros(batch_size,3,224,224) for ix in range(bias,bias+batch_size): pic[ix-bias]=self.get_image3(classidx,ix) return pic

in train.py you get images by def get_image function and in test_util.py you get images in def get_valid by self.get_image3(classidx,ix). But these two get_images funtions use different trans.Compose functions. One of the functions is img=self.trans3(ori_img) and the other is img=self.trans4(ori_img)!

my guess is that both functions should use the same trans function! am i right?

magicfisk commented 2 years ago

No.

In the training stage, we use RandomHorizontalFlip to improve the diversity of the data. But in the test stage, it is unnecessary to do RandomHorizontalFlip.

burhanbarakli commented 2 years ago

Cifar10 images 32x32 dimension. And img=self.trans3(ori_img) with RandomHorizontalFlip get an error. Required crop size (224, 224) is larger then input image size (32, 32)

But the other trans function works with 32x32 dimension. (trans1, trans2 and trans4 works)

Did you change the size of the input images on main image folder etc.? Due to the error I got, I changed the 32x32 image to 224x224 in the get_image function. Then I used the get_image function and the randomhorizontal transs function. As a result, I reached a very low map score. Code is below,

def get_image(self,classid,imageid): image_path=self.path+'/'+str(classid)+'/'+str(imageid+1)+'.jpg' ori_img=Image.open(image_path) ori_img=ori_img.resize((224,224)) img=self.trans3(ori_img) return img