Giter VIP home page Giter VIP logo

Comments (5)

nitish11 avatar nitish11 commented on July 23, 2024 1

I modified the test code and it's generating and saving the images.
Please find below very simple version of test.py

import os
import cv2
import numpy as np
from PIL import Image

from util import util
from options.test_options import TestOptions
from models.pix2pix_model import Pix2PixModel
from data.base_dataset import get_params, get_transform

#Loading the trained model
opt = TestOptions().parse()
model = Pix2PixModel(opt)
model.eval()

#Loading Semantic Label
label_path = 'datasets/test_sketch/annotations/validation/test_val_00000002.png'
label = Image.open(label_path)
params = get_params(opt, label.size)
transform_label = get_transform(opt, params, method=Image.NEAREST, normalize=False)
label_tensor = transform_label(label) * 255.0
label_tensor[label_tensor == 255] = opt.label_nc
print("-- Label tensor :", np.shape(label_tensor))

#Creating data_dictionary
data_i = {}
data_i['label'] = label_tensor.unsqueeze(0)
data_i['path'] = [None]
data_i['image'] = [None]
data_i['instance'] = [None]

#Inference code
generated = model(data_i, mode='inference')

for b in range(generated.shape[0]):
    generated_image = generated[b]
    # generated_image = np.moveaxis(generated_image.cpu().detach().numpy(), 0, -1)
    generated_image = util.tensor2im(generated_image)
    generated_image_path_ = generated_image_path[:-4]+str(b)+".png"
    print('---- generated image ', generated_image_path_, np.shape(generated_image))
    cv2.imwrite(generated_image_path_, generated_image)

To run this code,

python test.py --name ade20k_pretrained --dataset_mode ade20k --dataroot datasets/test_sketch/ --gpu_ids -1 --results_dir results/test_sketch

from spade.

taesungp avatar taesungp commented on July 23, 2024

For this, you will need to modify the code of the dataset class (CocoDataset for example) to be able to load the layouts only.

The image generation process entirely depends on the label layout, and does not depend on the validation image. Therefore, the output result will not change even if you change the image. The groud-truth RGB image is merely used for comparison.

from spade.

MrWwei avatar MrWwei commented on July 23, 2024

@jmoberreuter have you solved the issue?

from spade.

nitish11 avatar nitish11 commented on July 23, 2024

@jmoberreuter @MrWwei Have you resolved the issue?
@taesungp Could you please explain a bit more about changes to be made.

from spade.

nitish11 avatar nitish11 commented on July 23, 2024

I got the solution, the dataloader code is using the val_img path for reference.
data_i in dataloader is a dictionary with following keys: dict_keys(['label', 'instance', 'image', 'path'])
data_i[path] contains list of name of validation images, but it is not being used in Evaluation code in inference mode.

from spade.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.