liruilong940607 / Pose2Seg

Code for the paper "Pose2Seg: Detection Free Human Instance Segmentation" @ CVPR2019.
http://www.liruilong.cn/projects/pose2seg/index.html
MIT License
532 stars 136 forks source link

How to run model for new images ? #18

Open gumush opened 5 years ago

gumush commented 5 years ago

I want to run model to process my images. My data has not grand truth annotations and keypoints. How can i process my images ?

`import argparse
import numpy as np
from tqdm import tqdm

from modeling.build_model import Pose2Seg
from datasets.CocoDatasetInfo import CocoDatasetInfo, annToMask
from pycocotools import mask as maskUtils
import cv2, os
import matplotlib
import matplotlib.pyplot as plt

from skimage import data, io, filters

import os
import cv2
import json
model = Pose2Seg().cuda()
model.init('pose2seg_release.pkl')
ImageRoot = './data/coco2017/val2017'
AnnoFile = './data/coco2017/annotations/person_keypoints_val2017_pose2seg.json'
datainfos = CocoDatasetInfo(ImageRoot, AnnoFile, onlyperson=True, loadimg=True)
model.eval()
results_segm = []
imgIds = []
rawdata = datainfos[1]
img = rawdata['data']
print(rawdata['image'])
image_id = rawdata['id']
height, width = img.shape[0:2]
gt_kpts = np.float32(rawdata['gt_keypoints']).transpose(0, 2, 1)  # (N, 17, 3)
gt_segms = rawdata['segms']
gt_masks = np.array([annToMask(segm, height, width) for segm in gt_segms])
output = model([img], [gt_kpts], [gt_masks])
for mask in output[0]:
    maskencode = maskUtils.encode(np.asfortranarray(mask))
    maskencode['counts'] = maskencode['counts'].decode('ascii')
    results_segm.append({
        "image_id": image_id,
        "category_id": 1,
        "score": 1.0,
        "segmentation": maskencode
    })
imgIds.append(image_id)` 

model need inputs as keypoints and masks.

output = model([img], [gt_kpts], [gt_masks])

I need to create mask and keypoints from my image and visualize them Great work , thanks.