From c60e974049b9a2c490fd94a378a5697fff251142 Mon Sep 17 00:00:00 2001 From: Clefspear99 <43016747+Clefspear99@users.noreply.github.com> Date: Fri, 6 Nov 2020 10:39:23 -0600 Subject: [PATCH 1/6] Update for Pytorch 1.7 --- SR.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SR.py b/SR.py index 2a526959..7e7c6a30 100644 --- a/SR.py +++ b/SR.py @@ -58,7 +58,7 @@ reals_sr.append(real_) Gs_sr.append(Gs[-1]) NoiseAmp_sr.append(NoiseAmp[-1]) - z_opt = torch.full(real_.shape, 0, device=opt.device) + z_opt = torch.full(real_.shape, 0, dtype=torch.float32, device=opt.device) m = nn.ZeroPad2d(5) z_opt = m(z_opt) Zs_sr.append(z_opt) From 5a79d60679abb307c75a7de45497a4c6c934f3cb Mon Sep 17 00:00:00 2001 From: Clefspear99 <43016747+Clefspear99@users.noreply.github.com> Date: Fri, 6 Nov 2020 10:40:36 -0600 Subject: [PATCH 2/6] Update for Pytorch 1.7 --- SinGAN/manipulate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SinGAN/manipulate.py b/SinGAN/manipulate.py index 0d96c90f..6634d4a3 100755 --- a/SinGAN/manipulate.py +++ b/SinGAN/manipulate.py @@ -22,7 +22,7 @@ def generate_gif(Gs,Zs,reals,NoiseAmp,opt,alpha=0.1,beta=0.9,start_scale=2,fps=10): - in_s = torch.full(Zs[0].shape, 0, device=opt.device) + in_s = torch.full(Zs[0].shape, 0, dtype=torch.float32, device=opt.device) images_cur = [] count = 0 @@ -89,7 +89,7 @@ def generate_gif(Gs,Zs,reals,NoiseAmp,opt,alpha=0.1,beta=0.9,start_scale=2,fps=1 def SinGAN_generate(Gs,Zs,reals,NoiseAmp,opt,in_s=None,scale_v=1,scale_h=1,n=0,gen_start_scale=0,num_samples=50): #if torch.is_tensor(in_s) == False: if in_s is None: - in_s = torch.full(reals[0].shape, 0, device=opt.device) + in_s = torch.full(reals[0].shape, 0, dtype=torch.float32, device=opt.device) images_cur = [] for G,Z_opt,noise_amp in zip(Gs,Zs,NoiseAmp): pad1 = ((opt.ker_size-1)*opt.num_layer)/2 From 8fadfc66d98213eb6c864bfdff1040ab05a9b29f Mon Sep 17 00:00:00 2001 From: Clefspear99 <43016747+Clefspear99@users.noreply.github.com> Date: Fri, 6 Nov 2020 10:41:59 -0600 Subject: [PATCH 3/6] Update for Pytorch 1.7 --- config.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config.py b/config.py index b4832200..1c12213d 100755 --- a/config.py +++ b/config.py @@ -35,8 +35,7 @@ def get_arguments(): parser.add_argument('--lr_g', type=float, default=0.0005, help='learning rate, default=0.0005') parser.add_argument('--lr_d', type=float, default=0.0005, help='learning rate, default=0.0005') parser.add_argument('--beta1', type=float, default=0.5, help='beta1 for adam. default=0.5') - parser.add_argument('--Gsteps',type=int, help='Generator inner steps',default=3) - parser.add_argument('--Dsteps',type=int, help='Discriminator inner steps',default=3) + parser.add_argument('--steps',type=int, help='Generator / Discriminator inner steps',default=3) parser.add_argument('--lambda_grad',type=float, help='gradient penelty weight',default=0.1) parser.add_argument('--alpha',type=float, help='reconstruction loss weight',default=10) From 1ef573d0f35045b59df76d55605dcee6b9e13f34 Mon Sep 17 00:00:00 2001 From: Clefspear99 <43016747+Clefspear99@users.noreply.github.com> Date: Fri, 6 Nov 2020 10:44:14 -0600 Subject: [PATCH 4/6] Update for Pytorch 1.7 --- SinGAN/training.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/SinGAN/training.py b/SinGAN/training.py index 645a8635..cd0f4aa9 100755 --- a/SinGAN/training.py +++ b/SinGAN/training.py @@ -77,7 +77,7 @@ def train_single_scale(netD,netG,reals,Gs,Zs,in_s,NoiseAmp,opt,centers=None): alpha = opt.alpha fixed_noise = functions.generate_noise([opt.nc_z,opt.nzx,opt.nzy],device=opt.device) - z_opt = torch.full(fixed_noise.shape, 0, device=opt.device) + z_opt = torch.full(fixed_noise.shape, 0, dtype=torch.float32, device=opt.device) z_opt = m_noise(z_opt) # setup optimizer @@ -105,7 +105,7 @@ def train_single_scale(netD,netG,reals,Gs,Zs,in_s,NoiseAmp,opt,centers=None): ############################ # (1) Update D network: maximize D(x) + D(G(z)) ########################### - for j in range(opt.Dsteps): + for j in range(opt.steps): # train with real netD.zero_grad() @@ -118,10 +118,10 @@ def train_single_scale(netD,netG,reals,Gs,Zs,in_s,NoiseAmp,opt,centers=None): # train with fake if (j==0) & (epoch == 0): if (Gs == []) & (opt.mode != 'SR_train'): - prev = torch.full([1,opt.nc_z,opt.nzx,opt.nzy], 0, device=opt.device) + prev = torch.full([1,opt.nc_z,opt.nzx,opt.nzy], 0, dtype=torch.float32, device=opt.device) in_s = prev prev = m_image(prev) - z_prev = torch.full([1,opt.nc_z,opt.nzx,opt.nzy], 0, device=opt.device) + z_prev = torch.full([1,opt.nc_z,opt.nzx,opt.nzy], 0, dtype=torch.float32, device=opt.device) z_prev = m_noise(z_prev) opt.noise_amp = 1 elif opt.mode == 'SR_train': @@ -164,13 +164,13 @@ def train_single_scale(netD,netG,reals,Gs,Zs,in_s,NoiseAmp,opt,centers=None): errD = errD_real + errD_fake + gradient_penalty optimizerD.step() - errD2plot.append(errD.detach()) + ############################ # (2) Update G network: maximize D(G(z)) ########################### - for j in range(opt.Gsteps): + netG.zero_grad() output = netD(fake) #D_fake_map = output.detach() @@ -190,7 +190,8 @@ def train_single_scale(netD,netG,reals,Gs,Zs,in_s,NoiseAmp,opt,centers=None): rec_loss = 0 optimizerG.step() - + + errD2plot.append(errD.detach()) errG2plot.append(errG.detach()+rec_loss) D_real2plot.append(D_x) D_fake2plot.append(D_G_z) @@ -255,7 +256,7 @@ def draw_concat(Gs,Zs,reals,NoiseAmp,in_s,mode,m_noise,m_image,opt): return G_z def train_paint(opt,Gs,Zs,reals,NoiseAmp,centers,paint_inject_scale): - in_s = torch.full(reals[0].shape, 0, device=opt.device) + in_s = torch.full(reals[0].shape, 0, dtype=torch.float32, device=opt.device) scale_num = 0 nfc_prev = 0 From 82d39ea1e1dde40925747ee54d71ff1068304d4d Mon Sep 17 00:00:00 2001 From: Clefspear99 <43016747+Clefspear99@users.noreply.github.com> Date: Thu, 24 Mar 2022 14:35:33 -0500 Subject: [PATCH 5/6] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e6b3fd2f..5c8a491c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +My version has minor bugfixes to update it to moder python versions. + # SinGAN [Project](https://tamarott.github.io/SinGAN.htm) | [Arxiv](https://arxiv.org/pdf/1905.01164.pdf) | [CVF](http://openaccess.thecvf.com/content_ICCV_2019/papers/Shaham_SinGAN_Learning_a_Generative_Model_From_a_Single_Natural_Image_ICCV_2019_paper.pdf) From ac3830739aa48bac7ec90a11cb3e265b3d7e365e Mon Sep 17 00:00:00 2001 From: Clefspear99 <43016747+Clefspear99@users.noreply.github.com> Date: Thu, 14 Apr 2022 12:06:07 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c8a491c..845eb63c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -My version has minor bugfixes to update it to moder python versions. +My version has minor bugfixes to update it to modern python versions. # SinGAN