astra-vision / CoMoGAN

CoMoGAN: continuous model-guided image-to-image translation. CVPR 2021 oral.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Questions about code

DZY-cybe opened this issue · comments

Hi!
Thanks for your research and code!I have some questions about linear FIN.If I want to change a cyclic FIN to a linear FIN, do I just need to modify the definition of phi and the __apply_colormap function?I found that I also needed to change the code in many parts in comomunit.py and comomunit_model.py. Do you have any easy way?

The fast and easy way is to make the cyclic FIN collapse to a linear one by just implementing a physical model which is symmetrical for each sides of the cycle. To do this, implement a continuous linear physical model and just use one between cos(\phi) and sin(\phi) as controlling parameter. This will suffice to make the network work, slightly worse than with a linear FIN but it's good for quick testing other models. Does it answer your question?

Thanks for your reply, I'm a little confused about implementing a physical model which is symmetrical for each sides of the cycle.Can you use the iPhone → DSLR example from the paper to explain in detail how this is done?

Yes. Suppose that you want to implement the iPhone → DSLR linear model without modifying the code in the repo. I'm making a pseudocode example based on the dataloader.

def apply_blur_given_intensity(self, image, degree):
    # degree of intensity is between 0 and 1 and maps to a blur kernel size
    kernel_size = get_kernel_size(degree)
    return blur(image, kernel_size)
... 
# image loading and converting to tensor
A = load_image(source_index)

# Sample random phis
phi = random.random() * 2 * math.pi
phi_prime = random.random() * 2 * math.pi

# Extract cosine and sine
cos_phi = math.cos(phi)
cos_phi_prime = math.cos(phi_prime)
sin_phi = math.sin(phi)
sin_phi_prime = math.sin(phi_prime)

# apply blur model normalizing cos_phi between 0 and 1
A_cont = self.apply_blur_given_intensity(A, (cos_phi + 1) / 2) 
A_cont_compare = self.apply_blur_given_intensity(A, (cos_phi_prime + 1) / 2) 

...

return {'A': A, 'B': B, 'A_cont': A_cont, 'A_paths': A_path, 'B_paths': B_path, 'cos_phi': float(cos_phi),
    'sin_phi': float(continuity_sin), 'sin_phi_prime': float(sin_phi_prime),
    'cos_phi_prime': float(cos_phi_prime), 'A_cont_compare': A_cont_compare, 'phi': phi,
    'phi_prime': phi_prime,}

As you can see, the physical model, implemented by the function apply_blur_given_intensity, only depends on the cosine of phi, but I'm not changing the return dictionary structure. In this way, the cyclic FIN will discover that the desired blur will be the same regardless of the sign of the sin of phi.

Another example to make the cyclic FIN collapse to a linear behavior for the Day→Timelapse experiment would be to remove these lines from the dataloader.

Thanks for your patience in explaining and demonstrating, I get it.