wufeim/NeMo

Incorrect try-except block.

Opened this issue · 3 comments

The following try-except block is incorrect and may cause no data being saved if the code fails partway.

try:
    # Prepare 3D annotations for NeMo training
    if not skip_3d_anno and (mesh_manager is not None and direction_dicts is not None):

        save_parameters["true_cad_index"] = save_parameters["cad_index"]
        if single_mesh:
            save_parameters["cad_index"] = 1

        kps, vis = mesh_manager.get_one(save_parameters)
        idx = save_parameters["cad_index"] - 1
        weights = cal_point_weight(
            direction_dicts[idx],
            mesh_manager.loader[idx][0],
            save_parameters,
        )

        save_parameters["kp_weights"] = np.abs(weights)
        save_parameters["cropped_kp_list"] = kps
        save_parameters["visible"] = vis

    np.savez(
        os.path.join(save_annotation_path, curr_img_name), **save_parameters
    )
    Image.fromarray(img_cropped).save(
        os.path.join(save_image_path, curr_img_name + ".JPEG")
    )
    save_image_names.append(
        (get_anno(record, "cad_index", idx=obj_id), curr_img_name)
    )
except:
    continue
wufeim commented

I see your point. The idea of this try-except block is that if we fail to produce keypoints for some reason, we will skip this sample since it cannot be used for training. Is there a a reason why you need this failed sample without keypoint annotations?

It failed due to numpy alias changes (I opened an issue for that. I guess defining the exact exception instead of a broad except may be the solution here.

wufeim commented

Okay I see. I will fix it!