Closed matinaz closed 2 months ago
The iterations aren't guaranteed to converge for arbitary denoisers. Some suggestions for now:
Reducing the ρ value didn't work, but I'll try the other two solutions. So, there is no problem with "MyFunctional" implementation?Is it OK that the call method returns 0.0 ?
I'm coming back since it seems that prox function in MyFunctional gets the same input in every iteration and it doesn't take into consideration the results of the denoisd output of the previous iteration. Watching the code, could you tell me if it might be due to a wrong implementation of myFunctional or wrong call in ADMM?
If the prox of g is seeing the same input on each iteration, then my first guess would be is that ρ is far too small so that the z variable update is almost the same on each iteration (it would be useful to take a look at the mathematical expression for the updates if this isn't clear).
This could be a problem indeed, but I thing something else is going on, since I get the same results even when I run ADMM using DNCNN as a denoiser inside prox of MyFunctional. Could it be something in the implementation of MyFunctional that doesn't let z get updated?
That does suggest it's an implementation issue rather than parameters or some more abstract algorithmic issue.
Any progress on this? Do you still want to keep the issue open?
Problem solved, so I close the issue. Your help was definitelly crucial. Thank you
We modified super-resolution to work with custom denoiser, however something must be wrong. The result gets worse iteration by iteration, while when trying another denoiser inside MyFunctional, the results remained the same. Might be something wrong with the implementation of MyFunctional that doesn't let ADMM take into consideration the result of the denoiser?
Below is the main code:
import jax import jax.numpy as jnp from jax import jit, grad from jax.scipy.ndimage import map_coordinates from jax.image import resize from jax import device_get import math from scipy import misc import jax.scipy as jsp import cv2 import skimage from skimage.metrics import structural_similarity as ssim import scico import scico.numpy as snp import scico.random import scico.examples import os import numpy as np from numpy import array import matplotlib.pyplot as plt from scico.metric import mse from scico import denoiser, functional, linop, loss, metric, plot from scico.data import kodim23 from scico.optimize.admm import ADMM, LinearSubproblemSolver from scico.solver import cg, minimize from scico.util import device_info from scico.functional import Functional from scipy.optimize import minimize import chandenoised2 from scico.optimize import LinearizedADMM from PIL import Image import matplotlib.pyplot as plt import imageio from skimage.util import random_noise
plot.config_notebook_plotting()
rate = 4 # downsampling rate σ = 2e-2 # noise standard deviation
σ=0
lambda_val=1.0
m = 0; variance = 0.01;
class MyFunctional(scico.functional.Functional):
def warp_flow(flow, img2):
def motionestimation(frame1, frame2):
Compute the Fourier transforms of the two frames
def downsample_image(img, rate):
print (img.shape)
def roll1(x, flow, a): if (a==1): r=warp_flow(flow, x) d=downsample_image(r, rate) else: d=downsample_image(x, rate) d=snp.roll(d,719,1) return d
for ii in range (1,2):
print(img.shape)
frame3=np.array(frames[4])
flow4=cv2.calcOpticalFlowFarneback(frame2.mean(-1), frame3.mean(-1), None, 0.5, 3, 15, 3, 5, 1.2, 0)
Afn4= lambda x: roll1(x,flow4, a=1)
s4=downsample_image(frame3, rate=rate)
noise, key = scico.random.randn(s4.shape, seed=0)
sn4=s4+ σ * noise
A4 = linop.LinearOperator(input_shape=input_shape, output_shape=output_shape, eval_fn=Afn4)
Chantas
g=h
And the code of the denoiser:
import cv2 import numpy as np from scipy.special import gamma from skimage.metrics import structural_similarity as ssim from PIL import Image from statistics import mean from numpy.fft import fft,fft2,ifft,ifft2,fftshift from numpy import real,conj,sort import numpy from numpy.linalg import norm import math from scico import denoiser, functional, linop, loss, metric, plot from skimage.transform import resize from skimage.util import random_noise import imageio import skimage
def myimresize(x, Nx, Ny, filtDFTcoef, decFac, extras): Nx = Nx + 2 extras Ny = Ny + 2 extras
if len(x.shape) == 3:
def myimresizeTranspose(x, Nx, Ny, filtDFTcoef, decFac, extras): Nx = Nx + 2 extras Ny = Ny + 2 extras x = np.zeros((Nx, Ny)) x[0:Nx:decFac, 0:Ny:decFac] = np.pad(x, [(extras // decFac, extras // decFac), (extras // decFac, extras // decFac)], mode='symmetric') y = np.real(np.fft.ifft2(fft2(x) * np.conj(filtDFTcoef))) y = y_[extras:Nx - extras, extras:Ny - extras] return y
def conjGradients(f, x0, b, iw, rw, rw2, maxiter, rtol): x = x0 r = b - Amat(x0, iw, rw, rw2) p = r rnormStart = np.sum(r 2) rnorm = rnormStart for iter in range(1, maxiter + 1): Ap = Amat(p, iw, rw, rw2) r_norm_sq = np.sum(r 2) p_Ap = np.sum(p * Ap)
def Amat(x, iw, rw, rw2): Nx = iw[4] Ny = iw[5] maxX = iw[6] maxY = iw[7]
def stat_rest(alpha, ssigma, g, Q, H1, Nx, Ny): NN = Nx * Ny G = fft2(g) Hf1 = np.abs(H1) 2 Qf = np.abs(Q) 2
def main( img2): imNumber = 1 decFactor = 1
pathHR = '/home/matina/Επιφάνεια εργασίας/scico/Vid4/city/030.png'
if name == "main": main()