Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform interpolation between Input and Output #1648

Open
obeidahmad opened this issue Apr 24, 2024 · 0 comments
Open

Perform interpolation between Input and Output #1648

obeidahmad opened this issue Apr 24, 2024 · 0 comments

Comments

@obeidahmad
Copy link

obeidahmad commented Apr 24, 2024

My idea is to take a certain input generate its latent space, same for the output. Then perform latent space interpolation from the input to output.

However, I can't seem to find a way to get the latent space of a certain image.

I did the following:

gen = define_G(
    input_nc=3,
    output_nc=3,
    ngf=64,
    netG="unet_256",
    norm="batch",
    use_dropout=True,
    init_type="normal",
    init_gain=0.02,
    gpu_ids=[0, 1],
)
device = torch.device("cuda:1")

# Load model gen
model_path = "facades_label2photo.pth"
state_dict = torch.load(model_path, map_location=str(device))
if hasattr(state_dict, "_metadata"):
    del state_dict._metadata
state_dict = OrderedDict([(f"module.{k}", v) for k, v in state_dict.items()])
gen.load_state_dict(state_dict)
gen.eval()

# get input image
input_image_path = "datasets/facades/test/1.jpg"
img = Image.open(input_image_path).convert('RGB')
width, height = img.size
start_col = width // 2
end_col = width
start_row = 0
end_row = height
img = img.crop((start_col, start_row, end_col, end_row))


# Encode the input image to obtain the latent vector
with torch.no_grad():
    latent_vector = gen.encoder(img)

However, it seems the model does not have an encoder function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant