def __getitem__(self, index): image, labels = self.dataset[index] np_arr = np.asarray(image) ptimage = PTImage.from_numpy_array(np_arr) objects = [] for t in labels: box = Box.from_xywh(t['bbox']) obj_type = self.coco.loadCats([t['category_id']])[0]['name'] # convert segmentation to polygon using the pycocotools # note the segmentation could in one of several formats, for example the custom coco RLE, # to convert the RLE back to polygon is bit of a pain so I will just ignore those right now # according the COCO site, most of the data is in polygon form (not sure why theres a discrepency?) # and I'd rather not store 2D binary masks with every object. polygon = t.get('segmentation') # reshape to 2d poly, assume its convex hull? polys = [] if polygon and isinstance(polygon, list): for seg in polygon: polys.append( Polygon( np.array(seg).reshape((int(old_div(len(seg), 2)), 2)))) objects.append(Object(box, obj_type=obj_type, polygons=polys)) frame = Frame.from_image_and_objects(ptimage, objects) return frame
def __getitem__(self,index): pil_img,label = self.dataset[index] # assert 2D here np_arr = np.asarray(pil_img) np_arr = np.expand_dims(np_arr, axis=2) # create the PTImage, and object that span the frame # add extra channel dimension ptimage = PTImage.from_numpy_array(np_arr) obj = Object(Box(0,0,pil_img.size[0],pil_img.size[1])) frame = Frame.from_image_and_objects(ptimage,[obj]) return frame