facebookresearch / deepmask

Torch implementation of DeepMask and SharpMask

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

access precomputed proposals

opened this issue · comments

Hi,
I am trying use the precomputed proposals from deepmask which are in json format. I am new to json and do not know how to access the output from the json files. Could anyone guide me on how to access the json files and get the segments from it so that I can visualize them? i cannot find any such instruction set online. Thanks

commented

Are you talking about viewing the ground truth segments from MS COCO, or the outputed proposals from deepmask?

Sorry I wasn't clear about the question. I want to access and visualize the output from deepmask on mscoco which are provided on the github site in json format. I cannot re-run the deepmask since I do not have access to GPU and I am a newbie to deep learning. I need segmentations for the mscoco images and deepmask seems to be the only one that has precomputed output. Hope I am not confusing everyone.

commented

My mistake - I didn't see the precomputed proposals section. I haven't downloaded them but it says that they are provided in COCO JSON format (as you said!). Assuming this is the same as the file that I got from coco then this should work, using the coco PythonApi (https://github.com/pdollar/coco).

from pycocotools.coco import COCO
import matplotlib.pyplot as plt
import skimage.io as io

#Load the annotations
annFile = #path to the JSON file
coco = COCO(annFile)

#Load an image
imaged = 1 #for example
img_filename = coco.loadImgs(imgid)[0]['file_name']
I = io.imread(img_filename)
plt.figure(); plt.axis('off')
plt.imshow(I)

#Get annotations from JSON file
annIds = coco.getAnnIds(imgid)
anns = coco.loadAnns(annIds)

#Plot them onto the image
coco.showAnns(anns)
plt.show()

I will give it a try and see if it work. Thanks.

Hi,
I get errors when I run the above. When I run the coco.loadImgs I get Keyerror.
img_filename = coco.loadImgs(imgid)[0]['file_name'] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pycocotools/coco.py", line 232, in loadImgs return [self.imgs[ids]] KeyError: 1

If I skip the loadImgs and run the getAnnIds I get empty [] in annIds
>>>annIds = coco.getAnnIds(imgIds=400)
>>>annIds
>>> []

commented

Make sure type(imgid) = int

It is int.
>>>type(imgid)
<type 'int'>
Could it be that the deepmask json's are a little different in format that mscoco? This is how it says on the mscoco website:

a binary mask containing an object segment should be encoded to RLE using the MaskApi function encode().
and this is what the deepmask website says;

The proposals are divided into chunks of 500 images each (that is, each JSON contains 1000 proposals per image for 500 images).

commented

Can you post your whole code, and also which precomputed proposals you downloaded?

This is the first chunk where I get the KeyError:
from pycocotools.coco import COCO
import matplotlib.pyplot as plt
import skimage.io as io
annFile = /Users/myname/Downloads/deepmask/train-smin=-2.5-smax=1/jsons/props-1-500.json
coco = COCO(annFile)
imgid = 1
img_filename = coco.loadImgs(imgid)[0]['file_name']

commented

Does imgid == 1 exist in the data?

image_ids = coco.getImgIds()
if not 1 in image_ids:
    print "1 is not a valid imageID"
    imgid = image_ids[0]

If this is the problem, then it was my fault for using 1 as an example ID. Sorry about that - my code has an imgid = 1.

So here is what I am looking for:
On this deepmask website https://github.com/facebookresearch/deepmask, at the very bottom is COCO sgements [train|val|..]. I need to access any one of them. I don't know if the names of the proposals i.e. segments are the same as the images. The mscoco website says the format of json is [{
"image_id" : int,
"category_id" : int,
"segmentation" : RLE,
"score" : float,
}]

I tried imgid = 20, 400, 500 etc. but all give me same error. Your snippet above gives me empty list.
image_ids = []

On another note, does anyone have other segmentation method (state of the art) that works on
COCO images, maybe little easier to run that deep learning method as I do not have access to GPU or even precomputed segments that exist? Thanks