Giter Site home page Giter Site logo

Comments (7)

moein-shariatnia avatar moein-shariatnia commented on May 29, 2024 2

sir, How to do prediction on single image?

Hey,
If you are following along the Colab notebook, you can use the following code snippet to do prediction on a single image and visualize the final result. Note that you need to define the model (as noted in the notebook) and load the pretrained weights that I've provided there:

img = PIL.Image.open("black_and_white.jpg")
img = img.resize((256, 256))
# to make it between -1 and 1
img = transforms.ToTensor()(img)[:1] * 2. - 1.
model.eval()
with torch.no_grad():
    preds = model.net_G(img.unsqueeze(0).to(device))
plt.imshow(lab_to_rgb(img.unsqueeze(0), preds.cpu())[0])

I hope this helps you out. Please let me know if there is any problem. Good Luck!

from deep-learning.

masudrehman avatar masudrehman commented on May 29, 2024

thanks it worked

from deep-learning.

masudrehman avatar masudrehman commented on May 29, 2024

from deep-learning.

moein-shariatnia avatar moein-shariatnia commented on May 29, 2024

from deep-learning.

masudrehman avatar masudrehman commented on May 29, 2024

from deep-learning.

radudiaconu0 avatar radudiaconu0 commented on May 29, 2024

sir, How to do prediction on single image?

Hey,

If you are following along the Colab notebook, you can use the following code snippet to do prediction on a single image and visualize the final result. Note that you need to define the model (as noted in the notebook) and load the pretrained weights that I've provided there:


img = PIL.Image.open("black_and_white.jpg")

img = img.resize((256, 256))

# to make it between -1 and 1

img = transforms.ToTensor()(img)[:1] * 2. - 1.

model.eval()

with torch.no_grad():

    preds = model.net_G(img.unsqueeze(0).to(device))

plt.imshow(lab_to_rgb(img.unsqueeze(0), preds.cpu())[0])

I hope this helps you out. Please let me know if there is any problem. Good Luck!

Why we transforms it between -1 and 1 and not 0 1

from deep-learning.

moein-shariatnia avatar moein-shariatnia commented on May 29, 2024

Why we transforms it between -1 and 1 and not 0 1
@radudiaconu0

The model has been trained in this way so the evaluation must be done in the same way.
The generator architecture contains a Tanh function in the last layer, so, the generated image is between -1 and 1. So, the real images coming to discriminator should be in the same range. That's the reason why we scale between -1 and 1 in the dataset.

from deep-learning.

Related Issues (9)

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.