Ejemplo n.º 1
0
 def forward(self, x):
     if self.upsample:
         x = F.UpSampling(x, scale=self.upsample, sample_type='nearest')
     """
     if self.reflection_padding != 0:
         x = self.reflection_pad(x)
     """
     out = self.conv2d(x)
     return out
Ejemplo n.º 2
0
def test_upsampling():
    print("test upsampling")
    tmp_dir = DIR + "upsampling/"

    os.makedirs(tmp_dir + "0/", exist_ok=True)
    shape = np.random.randint(low=3, high=5, size=(4))
    print(shape)
    a = np.random.randint(low=-127, high=127, size=shape)
    np.save(tmp_dir + "0/in_0.npy", a.astype("int32"))
    params = {'method': 'NEAREST_NEIGHBOR', 'layout': 'NCHW', 'scale': 1}
    save_dict(params, tmp_dir + "0/attr.txt")
    params = {'scale': 1, 'sample_type': 'nearest'}
    b = nd.UpSampling(nd.array(a), **params)
    np.save(tmp_dir + "0/out_0.npy", b.asnumpy().astype("int32"))
    print(b.shape)
    print(b)

    os.makedirs(tmp_dir + "1/", exist_ok=True)
    shape = np.random.randint(low=3, high=4, size=(4))
    print(shape)
    a = np.random.randint(low=-127, high=127, size=shape)
    np.save(tmp_dir + "1/in_0.npy", a.astype("int32"))
    params = {'method': 'NEAREST_NEIGHBOR', 'layout': 'NCHW', 'scale': 2}
    save_dict(params, tmp_dir + "1/attr.txt")
    params = {'scale': 2, 'sample_type': 'nearest'}
    b = nd.UpSampling(nd.array(a), **params)
    np.save(tmp_dir + "1/out_0.npy", b.asnumpy().astype("int32"))
    print(b.shape)

    os.makedirs(tmp_dir + "2/", exist_ok=True)
    shape = np.random.randint(low=2, high=4, size=(4))
    print(shape)
    a = np.random.randint(low=-127, high=127, size=shape)
    np.save(tmp_dir + "2/in_0.npy", a.astype("int32"))
    params = {'method': 'NEAREST_NEIGHBOR', 'layout': 'NCHW', 'scale': 3}
    save_dict(params, tmp_dir + "2/attr.txt")
    params = {'scale': 3, 'sample_type': 'nearest'}
    b = nd.UpSampling(nd.array(a), **params)
    np.save(tmp_dir + "2/out_0.npy", b.asnumpy().astype("int32"))
    print(b.shape)
    print(b)
Ejemplo n.º 3
0
 def forward(self, x):
     if self.upsample:
         x = F.UpSampling(x, scale=self.upsample, sample_type='nearest')
     out = self.conv2d(x)
     return out