def load_demo_images(paths):
    paths = [os.path.join(paths, x) for x in os.listdir(paths)]
    img_h = cfg.CONST.IMG_H
    img_w = cfg.CONST.IMG_W

    model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True)
    """
    imgs = []
    for path in paths:
        img = Image.open(path)
        #img = segment(path)
        #img = transforms.ToPILImage()(img)
        img = img.resize((img_h, img_w), Image.ANTIALIAS)
        img = preprocess_img(img, train=False)
        imgs.append([np.array(img).transpose( \
                        (2, 0, 1)).astype(np.float32)])
    """

    imgs = segment(paths, model)
    result = []
    for img in imgs:
        img = transforms.ToPILImage()(img)
        img = img.resize((img_h, img_w), Image.ANTIALIAS)
        img = preprocess_img(img, train=False)
        result.append([np.array(img).transpose( \
                        (2, 0, 1)).astype(np.float32)])

    ims_np = np.array(result).astype(np.float32)

    return torch.from_numpy(ims_np)
Esempio n. 2
0
def load_demo_images():
    ims = []
    for i in range(3):
        im = Image.open('imgs/%02d.png' % i)
        im = preprocess_img(im, train=False)[0]
        ims.append([np.array(im).transpose((2, 0, 1)).astype(np.float32)])
    return np.array(ims)
Esempio n. 3
0
def load_demo_images():
    ims = []
    for i in range(3):
        im = preprocess_img(Image.open('imgs/%d.jpg' % i).resize((127, 127)),
                            train=False)
        ims.append([np.array(im).transpose((2, 0, 1)).astype(np.float32)])
        plt.imshow(im)
        plt.show()
    return np.array(ims)
Esempio n. 4
0
def load_demo_images(imgs='./imgs/', maxrange=3):
    global demo_imgs
    ims = []
    # print("maxrange", maxrange)
    for i in range(maxrange):
        im = preprocess_img(
            # Image.open(imgs + '%d.jpg' %  #进来的时候是127*127*3
            Image.open(imgs + '0%d.png' %  #进来的时候是127*127*3
                       i).resize((127, 127)),
            train=False)
        ims.append([np.array(im).transpose((2, 0, 1)).astype(np.float32)])
    # return np.array(ims)
    demo_imgs = np.array(ims)
Esempio n. 5
0
def load_demo_images():
    img_h = cfg.CONST.IMG_H
    img_w = cfg.CONST.IMG_W

    imgs = []

    for i in range(3):
        img = Image.open('imgs/%d.png' % i)
        img = img.resize((img_h, img_w), Image.ANTIALIAS)
        img = preprocess_img(img, train=False)
        imgs.append([np.array(img).transpose( \
                        (2, 0, 1)).astype(np.float32)])
    ims_np = np.array(imgs).astype(np.float32)
    return torch.from_numpy(ims_np)
Esempio n. 6
0
def load_imgs(taken_time):
    assert (os.path.isdir(taken_time))

    img_h = cfg.CONST.IMG_H
    img_w = cfg.CONST.IMG_W

    imgs = []

    for file in os.listdir(taken_time):
        if file[-4:] in [".JPG", ".png"]:
            img = Image.open(os.path.join(taken_time, file))
            img = img.resize((img_h, img_w), Image.ANTIALIAS)
            img = preprocess_img(img, train=False)
            imgs.append([np.array(img).transpose( \
                         (2, 0, 1)).astype(np.float32)])
            plt.imshow(img)
            plt.show()
    return np.array(imgs)
Esempio n. 7
0
    def load_img(self, category, model_id, image_id):
        image_fn = get_rendering_file(category, model_id, image_id)
        im = Image.open(image_fn)

        t_im = preprocess_img(im, self.train)
        return t_im
Esempio n. 8
0
def load_img(category, model_id, img_id, train=False):
    img_fn = get_rendering_file(category, model_id, img_id)
    im = Image.open(img_fn)
    
    t_im = preprocess_img(im, train=train)
    return t_im