chainer-partial_convolution_image_inpainting icon indicating copy to clipboard operation
chainer-partial_convolution_image_inpainting copied to clipboard

Replacement order

Open yuzhesu opened this issue 6 years ago • 1 comments

Excuse me, in the place2.py file, def get_example part, you use random to take out 8 pictures, if I want to take out the order from the first to the eighth, how can I change?

yuzhesu avatar Jul 15 '18 09:07 yuzhesu

Sorry for the late response. A simple workaround is as below,

change train.py

https://github.com/SeitaroShinagawa/chainer-partial_convolution_image_inpainting/blob/master/train.py#L92

    val_dataset = getattr(datasets, "place2_test")(paths.val_place2, mask_path="mask/256", flip=0, resize_to=args.resize_to, crop_to=args.crop_to)
    #val_iter = chainer.iterators.SerialIterator(val_dataset, 8)
    val_iter = chainer.iterators.SerialIterator(val_dataset, 8, shuffle=False) #make random shuffle false

changes in datasets/place2.py

https://github.com/SeitaroShinagawa/chainer-partial_convolution_image_inpainting/blob/master/datasets/place2.py#L67

class place2_test(datasets_base):
    def __init__(self, dataset_path, mask_path, flip=0, resize_to=-1, crop_to=-1):
        super(place2_test, self).__init__(resize_to=resize_to, crop_to=crop_to)
        self.dataset_path = dataset_path
        #self.trainAkey = glob.glob(dataset_path + "/*.jpg")
        #self.maskkey = glob.glob(mask_path + "/*.bmp")
        self.trainAkey = glob.glob(dataset_path + "/*.jpg")[:8] #use only 8 examples
        self.maskkey = glob.glob(mask_path + "/*.bmp")[:8] #use only 8 examples

https://github.com/SeitaroShinagawa/chainer-partial_convolution_image_inpainting/blob/master/datasets/place2.py#L96

   def get_example(self, i):
        np.random.seed(None)
        #idA = self.trainAkey[np.random.randint(0,len(self.trainAkey))]
        idA = self.trainAkey[i] #use index of get_example
        #idM = self.maskkey[np.random.randint(0,len(self.maskkey))]
        idM = self.maskkey[i] #use index of get_example

Additionaly, if you want to fix random crop, change place2.py as below, https://github.com/SeitaroShinagawa/chainer-partial_convolution_image_inpainting/blob/master/datasets/place2.py#L81

    def do_random_crop(self, img, crop_to=256):
        w, h, ch = img.shape
        limx = w - crop_to
        limy = h - crop_to
        #x = np.random.randint(0,limx)
        #y = np.random.randint(0,limy)
        x = int(limx*0.5) #fix crop position
        y = int(limy*0.5) #fix crop position 
        img = img[x:x+crop_to, y:y+crop_to]
        return img

Best,

SeitaroShinagawa avatar Jan 15 '19 15:01 SeitaroShinagawa