Exemplo n.º 1
0
def FasterRCNN():
    st.title("FasterRCNN")
    f = open("FasterRCNN.txt", "r")
    st.markdown(f.readline(), unsafe_allow_html=True)
    st.image("faster_show.png", use_column_width=True)
    st.markdown(f.readline(), unsafe_allow_html=True)

    FRCNN, session = frcnn("faster_rcnn_face_0010.h5")
    class_names = ["BG", "Face"]
    file = st.file_uploader("Upload image")

    if file:
        ImgNet = ImageNetwork(file, FRCNN, session)
        r, image = fast_predict(ImgNet)

        frcnn_visualize.display_instances(image,
                                          r['rois'],
                                          None,
                                          r['class_ids'],
                                          class_names,
                                          r['scores'],
                                          title="",
                                          show_mask=False)

        st.image(file, caption="Uploaded Image", use_column_width=True)
        st.image("FasterRCNN_output.jpg",
                 caption="Faces Detected",
                 use_column_width=True)
    # except:
    #     st.write("File Uploaded is not an image. Please upload am Image")
    return
Exemplo n.º 2
0
image_id = random.choice(dataset.image_ids)
image, image_meta, gt_class_id, gt_bbox =\
    data.load_image_gt(dataset, config, image_id)
info = dataset.image_info[image_id]
print("image ID: {}.{} ({}) {}".format(info["source"], info["id"], image_id,
                                       dataset.image_reference(image_id)))
# Run object detection
results = model.detect([image], verbose=1)

# Display results
ax = get_ax(1)
r = results[0]
visualize.display_instances(image,
                            r['rois'],
                            r['class_ids'],
                            dataset.class_names,
                            r['scores'],
                            ax=ax,
                            title="Predictions")
log("gt_class_id", gt_class_id)
log("gt_bbox", gt_bbox)

#%% Precision-Recall
# Draw precision-recall curve
AP, precisions, recalls, overlaps = utils.compute_ap(gt_bbox, gt_class_id,
                                                     r['rois'], r['class_ids'],
                                                     r['scores'])
visualize.plot_precision_recall(AP, precisions, recalls)

#%%
# Grid of ground truth objects and their predictions
Exemplo n.º 3
0
# Load trained weights
model.load_weights(model_path, by_name=True)

#%% Test on a random image
image_id = random.choice(dataset_val.image_ids)
original_image, image_meta, gt_class_id, gt_bbox =\
    data.load_image_gt(dataset_val, inference_config, image_id)

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

visualize.display_instances(original_image,
                            gt_bbox,
                            gt_class_id,
                            dataset_train.class_names,
                            ax=get_ax())

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

r = results[0]
visualize.display_instances(original_image,
                            r['rois'],
                            r['class_ids'],
                            dataset_val.class_names,
                            r['scores'],
                            ax=get_ax())
AP, precisions, recalls, overlaps =\
    utils.compute_ap(gt_bbox, gt_class_id, r["rois"], r["class_ids"], r["scores"])
print(AP)