Skip to content

COCODemo Returning Original Image #54

@cskarthik7

Description

@cskarthik7

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions