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

COCODemo Returning Original Image #54

Open
cskarthik7 opened this issue Oct 6, 2020 · 0 comments
Open

COCODemo Returning Original Image #54

cskarthik7 opened this issue Oct 6, 2020 · 0 comments

Comments

@cskarthik7
Copy link

Here is my script below!!!
I had trained configs/centermask/centermask_R_50_FPN_lite_res600_ms_bs16_4x.yaml and I wanted to check if I am able to visualize my predictions or not! How should I correct it to get my desired results?

import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
import os
import requests
from io import BytesIO
from PIL import Image
import numpy as np
from maskrcnn_benchmark.config import cfg
from predictor import COCODemo

config_file = "../configs/centermask/centermask_R_50_FPN_lite_res600_ms_bs16_4x.yaml"

update the config options with the config file

cfg.merge_from_file(config_file)
cfg.MODEL.WEIGHT = '../checkpoints/CenterMask-Lite-R-50-FPN-res600-ms-bs16-4x/model_0070000.pth'

manual override some options

cfg.merge_from_list(["MODEL.DEVICE", "cuda"])
coco_demo = COCODemo(
cfg,
min_image_size=500,
confidence_threshold=0.5,
)

def load(url):
"""
Given an url of an image, downloads the image and
returns a PIL image
"""
response = requests.get(url)
pil_image = Image.open(BytesIO(response.content)).convert("RGB")
# convert to BGR format
image = np.array(pil_image)[:, :, [2, 1, 0]]
return image

def imshow(img):
plt.imshow(img[:, :, [2, 1, 0]])

val_path='../datasets/val2017/' #this is the validation image data
imglistval = os.listdir(val_path)
for name in imglistval:
imgfile = val_path + name
pil_image = Image.open(imgfile).convert("RGB")
image = np.array(pil_image)[:, :, [2, 1, 0]]

predictions = coco_demo.run_on_opencv_image(image) # forward predict
plt.subplot(1, 2, 1)
plt.imshow(image[:,:,::-1])
plt.axis('off')

plt.subplot(1, 2, 2)
plt.imshow(predictions[:,:,::-1])
plt.axis('off')
plt.show()
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