question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to output result image from output?

See original GitHub issue

When i finished the model training. & load model & input a single image by:

# Image preprocessing
    image = cv2.imread(image_path, cv2.IMREAD_COLOR).astype(float)
    image = cv2.resize(image, dsize=(512,512))
    image_original = image.astype(np.uint8)
    image = torch.from_numpy(image.transpose(2, 0, 1)).float().unsqueeze(0)
    image = image.to(device)

    # Inference
    output = Model(image)

output is a tensor & shape is (5,512,512). like:

[[[  4916.116    5713.0825   6510.0493 ...   8198.43     7449.5635
     6700.7207]
  [  5698.8423   6637.15     7575.4585 ...   9693.137    8787.99
     7882.872 ]
  [  6481.569    7561.218    8640.867  ...  11187.843   10126.417
     9065.023 ]
  ...

if i want to invert the tensor to labelimage ,What should i do?

if i process output by softmax or argmax or torch.max ,the output will be null image like

[[0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 ...
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]]

It’s a weird question!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jfzhang95commented, Nov 26, 2018

What is your model setting? When I run:

    model = DeepLab(backbone='resnet', output_stride=16, num_classes=21).cuda()
    model.eval()
    input = torch.rand(1, 3, 513, 513).cuda()
    output = model(input)
    print(output.size())

The output size is (1, 21, 513, 513). Then run the following code

    prediction = output.data.cpu().numpy()
    prediction = np.argmax(prediction, axis=1)

I could get the final prediction and the shape of prediction is (513, 513).

Based on the example you provided, I guess the number of classes in your example is 5. So, when you get output, you could run pred=output.data.cpu().numpy() and pred=np.argmax(pred, axis=0) to get the prediction labels, just like what I do above.

Hope this could help you 😃

0reactions
albertchristiantocommented, Jul 25, 2019

@leedoge hi, I think i have solved this problem. but, maybe no. i forgot because it has already 1 month. You can check your input processing. like have you substract your image with imagenet mean ?

best regards, Albert Christianto

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating an Output Image File
To actually render the current image into an output file, first set up the graphics in VMD just as you wish the output...
Read more >
How to display an image as result of true in a function
So I'm playing around with some code and I'm trying to design a program that displays an image if a true statement results...
Read more >
Output an image of your source code (not-quite-a-Quine)
I have just implemented a solution in whitespace. The resulting image looks quite boring.
Read more >
ImageOutput: Writing Images - Read the Docs
You may request that the output image pixels be stored in any of several data types. This is done by setting the format...
Read more >
Output Image - an overview | ScienceDirect Topics
1. Hardware to output images to the screen and input devices to control the display. This might be called the computer graphics system....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found