def classify(rgb_img):

    config = CocoConfig()

    model = modellib.MaskRCNN(mode="inference",
                              model_dir="./models/",
                              config=config)
    model.load_weights(filepath="./models/mask_rcnn_moles_0030.h5",
                       by_name=True)

    class_names = ['Salmonella', 'Yersinia', 'Shigella', 'Negativo']
    r = model.detect([rgb_img])[0]

    image, caption = visualize.display_instances(rgb_img, r['rois'],
                                                 r['masks'], r['class_ids'],
                                                 class_names, r['scores'])
    K.clear_session()
    image = PIL.Image.fromarray(image, 'RGB')
    words = caption.split()
    filename = str(uuid.uuid4())
    filepath = "./static/img/test/{}.jpg".format(filename)
    image.save(filepath)

    return json.dumps([{
        "caption": words[0],
        "percent": words[1],
        "image_path": filepath
    }],
                      cls=NumpyEncoder)
示例#2
0
def maskrandommiddle(level_str, fig_name,rando):
    # game = 0;
    # while game < 100:
    # Load a random image from the images folder
    level = 2
    with graph.as_default():
        if rando == 0:
            file_names = os.path.join("D:\FYP\myfyp\Mask\images\middle", fig_name)
            image = skimage.io.imread(os.path.join("D:\FYP\myfyp\Mask\images\middle", file_names))
        else:
            file_names = next(os.walk("D:\FYP\myfyp\Mask\images\middle"))[2]
            image = skimage.io.imread(os.path.join("D:\FYP\myfyp\Mask\images\middle", random.choice(file_names)))
        # Run detection
        results = model.detect([image], verbose=1)
        # Visualize results
        r = results[0]
        label_list = visualize.display_instances(level, image, r['rois'], r['masks'], r['class_ids'],
                                                 class_names, r['scores'])
        return label_list[0], label_list[1], label_list[2]
示例#3
0
        'input_image_meta:0': image_metas.tolist()[0],
        'input_anchors:0': anchors.tolist()[0]
    }]
})
res = requests.post('http://86.56.135.139:31967/v1/models/skyn:predict',
                    data=data,
                    headers=headers)
decoded = json.loads(res.content.decode("utf-8"))['predictions'][0]

detections = np.array([decoded['mrcnn_detection/Reshape_1:0']])
mrcnn_mask = np.array([decoded['mrcnn_mask/Reshape_1:0']])

# Process detections
results = []
for i, image in enumerate(images):
    final_rois, final_class_ids, final_scores, final_masks =\
        model.unmold_detections(detections[i], mrcnn_mask[i],
                               image.shape, molded_images[i].shape,
                               windows[i])
    results.append({
        "rois": final_rois,
        "class_ids": final_class_ids,
        "scores": final_scores,
        "masks": final_masks,
    })

r = results[0]
print(r['scores'])
visualize.display_instances(img, r['rois'], r['masks'], r['class_ids'],
                            class_names, r['scores'])
示例#4
0
    mask = cv2.resize(mask, (128, 128))
    if mask is not None:
        print("*****Done*****")
    info = Metadata(data["meta"], data["dataset"], img, mask)

    train_data = info

    # processing the data
    dataset_train = MoleDataset()
    dataset_train.load_shapes(train_data, config.IMAGE_SHAPE[0],
                              config.IMAGE_SHAPE[1])
    dataset_train.prepare()

    image = dataset_train.load_image(0)

    mask, class_ids = dataset_train.load_mask(0)
    visualize.test_display_image(image, mask, class_ids,
                                 dataset_train.class_names)
    r = model.detect([image])[0]

    c = visualize.display_instances(image,
                                    r['rois'],
                                    r['masks'],
                                    r['class_ids'],
                                    class_names,
                                    r['scores'],
                                    figsize=(7, 5))
    print("++++++++++DONE++++++++++++")

print("complete")
示例#5
0
# Test on a random image
for i in range(10):
    image_id = np.random.choice(dataset_val.image_ids)
    original_image, image_meta, gt_class_id, gt_bbox, gt_mask =\
        modellib.load_image_gt(dataset_val, inference_config,
                            image_id, use_mini_mask=False)

    log("original_image", original_image)
    log("image_meta", image_meta)
    log("gt_class_id", gt_class_id)
    log("gt_bbox", gt_bbox)
    log("gt_mask", gt_mask)

    visualize.display_instances(original_image,
                                gt_bbox,
                                gt_mask,
                                gt_class_id,
                                dataset_train.class_names,
                                figsize=(8, 8))

    r = model.detect([original_image], verbose=1)[0]

    def get_ax(rows=1, cols=1, size=8):
        _, ax = plt.subplots(rows, cols, figsize=(size * cols, size * rows))
        return ax

    visualize.display_instances(original_image,
                                r['rois'],
                                r['masks'],
                                r['class_ids'],
                                dataset_val.class_names,
                                r['scores'],