(model, image,all_classes,all_parts, thresh,text_size,hole_scale,island_scale,semantic, refimg=None, reftxt=None, audio_pth=None, video_pth=None)
| 15 | metadata = MetadataCatalog.get('coco_2017_train_panoptic') |
| 16 | |
| 17 | def interactive_infer_image(model, image,all_classes,all_parts, thresh,text_size,hole_scale,island_scale,semantic, refimg=None, reftxt=None, audio_pth=None, video_pth=None): |
| 18 | t = [] |
| 19 | t.append(transforms.Resize(int(text_size), interpolation=Image.BICUBIC)) |
| 20 | transform1 = transforms.Compose(t) |
| 21 | image_ori = transform1(image['image']) |
| 22 | mask_ori = transform1(image['mask']) |
| 23 | width = image_ori.size[0] |
| 24 | height = image_ori.size[1] |
| 25 | image_ori = np.asarray(image_ori) |
| 26 | images = torch.from_numpy(image_ori.copy()).permute(2,0,1).cuda() |
| 27 | all_classes, all_parts=all_classes.strip().strip("\"[]").split(':'),all_parts.strip().strip("\"[]").split(':') |
| 28 | |
| 29 | |
| 30 | data = {"image": images, "height": height, "width": width} |
| 31 | |
| 32 | mask_ori = np.asarray(mask_ori)[:,:,0:1].copy() |
| 33 | mask_ori = torch.from_numpy(mask_ori).permute(2,0,1)[0] |
| 34 | points=mask_ori.nonzero().float().to(images.device) |
| 35 | if len(points)==0: |
| 36 | point_=point=points.new_tensor([[0.5,0.5,0.006,0.006]]) |
| 37 | else: |
| 38 | point_=points.mean(0)[None] |
| 39 | point=point_.clone() |
| 40 | point[0, 0] = point_[0, 0] / mask_ori.shape[0] |
| 41 | point[0, 1] = point_[0, 1] / mask_ori.shape[1] |
| 42 | point = point[:, [1, 0]] |
| 43 | point=torch.cat([point,points.new_tensor([[0.005,0.005]])],dim=-1) |
| 44 | data['targets'] = [dict()] |
| 45 | data['targets'][0]['points']=point |
| 46 | data['targets'][0]['pb']=point.new_tensor([0.]) |
| 47 | |
| 48 | |
| 49 | batch_inputs = [data] |
| 50 | masks,ious = model.model.evaluate_demo(batch_inputs,all_classes,all_parts) |
| 51 | |
| 52 | pred_masks_poses = masks |
| 53 | reses=[] |
| 54 | ious=ious[0,0] |
| 55 | ids=torch.argsort(ious,descending=True) |
| 56 | |
| 57 | text_res='' |
| 58 | try: |
| 59 | thresh=float(thresh) |
| 60 | except Exception: |
| 61 | thresh=0.0 |
| 62 | mask_ls=[] |
| 63 | ious_res=[] |
| 64 | areas=[] |
| 65 | for i,(pred_masks_pos,iou) in enumerate(zip(pred_masks_poses[ids],ious[ids])): |
| 66 | iou=round(float(iou),2) |
| 67 | texts=f'{iou}' |
| 68 | mask=(pred_masks_pos>0.0).cpu().numpy() |
| 69 | area=mask.sum() |
| 70 | conti=False |
| 71 | if iou<thresh: |
| 72 | conti=True |
| 73 | for m in mask_ls: |
| 74 | if np.logical_and(mask,m).sum()/np.logical_or(mask,m).sum()>0.95: |
nothing calls this directly
no test coverage detected