vqdang / hover_net

Simultaneous Nuclear Instance Segmentation and Classification in H&E Histology Images.
MIT License
537 stars 224 forks source link

compute_stats.py, #93

Closed zerodohero closed 3 years ago

zerodohero commented 3 years ago

In compute_stats.py, there is the following code
true_centroid = (true_info["inst_centroid"]).astype("float32") true_inst_type = (true_info["inst_type"]).astype("int32") But there is no ["inst_centroid"] property in the predicted generated.mat file
image So I ran compute_stats.py with the following error image How do you fix the code??

zerodohero commented 3 years ago

Also, I'm going to command the following, and I'm going to make sure that the path is correct image image

vqdang commented 3 years ago

Above is due to mismatch between 2 saving formats. Old version portion

        pred_info = sio.loadmat(os.path.join(pred_dir, basename + ".mat"))
        # dont squeeze, may be 1 instance exist
        pred_centroid = (pred_info["inst_centroid"]).astype("float32")
        pred_inst_type = (pred_info["inst_type"]).astype("int32")

        if pred_centroid.shape[0] != 0:
            pred_inst_type = pred_inst_type[:, 0]
        else:  # no instance at all
            pred_centroid = np.array([[0, 0]])
            pred_inst_type = np.array([0])

will match with this

        with open('%s/%s.json' % (pred_dir, base_name), "r") as handle:
            pred_info = json.load(handle)['nuc']
        pred_centroid = np.array([v['centroid'] for v in pred_info.values()]).astype(np.float32)
        pred_inst_type = np.array([v['type'] for v in pred_info.values()]).astype(np.int32)
        del pred_info

        if pred_centroid.shape[0] != 0:
            pred_inst_type = pred_inst_type[:, 0]
        else:  # no instance at all
            pred_centroid = np.array([[0, 0]])
            pred_inst_type = np.array([0])
zerodohero commented 3 years ago

ok , However, I don't see it in the code with open('%s/%s.json' % (pred_dir, base_name), "r") as handle: pred_info = json.load(handle)['nuc'] pred_centroid = np.array([v['centroid'] for v in pred_info.values()]).astype(np.float32) pred_inst_type = np.array([v['type'] for v in pred_info.values()]).astype(np.int32) del pred_info

    if pred_centroid.shape[0] != 0:
        pred_inst_type = pred_inst_type[:, 0]
    else:  # no instance at all
        pred_centroid = np.array([[0, 0]])
        pred_inst_type = np.array([0])
zerodohero commented 3 years ago

To emphasize, I am using tiles, not WSI, and the code you mentioned is not in the latest version of compute_stats.py with open('%s/%s.json' % (pred_dir, base_name), "r") as handle: pred_info = json.load(handle)['nuc'] pred_centroid = np.array([v['centroid'] for v in pred_info.values()]).astype(np.float32) pred_inst_type = np.array([v['type'] for v in pred_info.values()]).astype(np.int32) del pred_info

    if pred_centroid.shape[0] != 0:
        pred_inst_type = pred_inst_type[:, 0]
    else:  # no instance at all
        pred_centroid = np.array([[0, 0]])
        pred_inst_type = np.array([0])

And I'm just replacing the block of code that you pointed out, so I get an error.I got an error after changing the path to JSON, because it was one-dimensional, but this code gave it a two-dimensional one.

vqdang commented 3 years ago

Change

    if pred_centroid.shape[0] != 0:
        pred_inst_type = pred_inst_type[:, 0]
    else:  # no instance at all
        pred_centroid = np.array([[0, 0]])
        pred_inst_type = np.array([0])

to

    # no instance at all
    if pred_centroid.shape[0] == 0:
        pred_centroid = np.array([[0, 0]])
        pred_inst_type = np.array([0])

This portion is mainly for sanity check.

vqdang commented 3 years ago

Close due to inactivity.