# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 3d_thuync
#     language: python
#     name: 3d_thuync
# ---

# # Libraries

# +
import numpy as np
import os, cv2, pickle, cvut
from matplotlib import pyplot as plt

from pcdet.utils import common_utils
from pcdet.datasets import build_dataloader
from pcdet.config import cfg, log_config_to_file, cfg_from_list, cfg_from_yaml_file

# Move to the root directory
if not 'workdir' in globals():
    workdir = os.getcwd()
    workdir = "/".join(workdir.split('/')[:-1])
# %cd "$workdir"

# Create cache folder
os.makedirs("cache", exist_ok=True)
# -

# # Load pickle result

# +
infer_result_file = "output/cfgs/kitti_models/pv_rcnn/default/eval/epoch_8369/val/default/result.pkl"
with open(infer_result_file, 'rb') as fp:
    det_results = pickle.load(fp)

print("Detection size:", len(det_results))
print(det_results[0].keys())
print()
for key, val in det_results[0].items():
    print(key, val.shape)
# -

obj_dix = 0
print("frame_id:", det_results[0]['frame_id'])
print("name:", det_results[0]['name'][obj_dix])
print("truncated:", det_results[0]['truncated'][obj_dix])
print("occluded:", det_results[0]['occluded'][obj_dix])
print("alpha:", det_results[0]['alpha'][obj_dix])
print("bbox:", det_results[0]['bbox'][obj_dix])
print("dimensions:", det_results[0]['dimensions'][obj_dix])
print("location:", det_results[0]['location'][obj_dix])
print("rotation_y:", det_results[0]['rotation_y'][obj_dix])
print("score:", det_results[0]['score'][obj_dix])
print("boxes_lidar:", det_results[0]['boxes_lidar'][obj_dix])

# +
sample_idx = 2000
image_dir = "/dataset/kitti/training/image_2"
image_file = os.path.join(image_dir, det_results[sample_idx]['frame_id']+'.png')
image = cv2.imread(image_file)[...,::-1]

bboxes = det_results[sample_idx]['bbox']
classnames = det_results[sample_idx]['name']
scores = det_results[sample_idx]['score']

CLASSES = ['Car', 'Pedestrian', 'Cyclist']
labels = np.array([CLASSES.index(item) for item in classnames])

selected_indicators = scores > 0.3
bboxes = bboxes[selected_indicators]
labels = labels[selected_indicators]

image = cvut.draw_bboxes(image, bboxes, labels=labels, classnames=CLASSES, color=None)
plt.figure(figsize=(35,35))
plt.imshow(image)
plt.show()
# -



StarcoderdataJupyterScriptsDedupFiltered