Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deepen_to_t4): add paint label downloader #107

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ee0b18f
[update] download paint dataset
nanoshimarobot Mar 5, 2024
46d82d5
[update] 1フレーム分だけ書き込みできた
nanoshimarobot Mar 18, 2024
a3e9fa6
[fix] annotation bug
nanoshimarobot Mar 21, 2024
f5aaf3c
[fix] decompressed labelの位置オフセット計算ミス
nanoshimarobot Mar 26, 2024
74742e9
[update] paint annotation downloader
nanoshimarobot May 16, 2024
c298485
Merge branch 'main' into feat/ground_seg_annotation
nanoshimarobot May 16, 2024
3ad8679
[remove] prev paint annotation downloader
nanoshimarobot May 23, 2024
ecc3477
[remove] unused paramater file
nanoshimarobot May 24, 2024
a785f28
[update] config file for paint annotaion downloader
nanoshimarobot May 24, 2024
5bf2283
[update] modified config for paint downloader
nanoshimarobot May 24, 2024
5ba44bf
[refactor] download_paint_annotations
nanoshimarobot May 24, 2024
abfc575
Merge branch 'main' into feat/ground_seg_annotation
nanoshimarobot May 24, 2024
154b6cd
[fix] gitignore, configs
nanoshimarobot May 24, 2024
395533d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2024
dea76e4
Merge branch 'main' into feat/ground_seg_annotation
nanoshimarobot Jun 6, 2024
9c1d990
Merge branch 'main' into feat/ground_seg_annotation
nanoshimarobot Jun 11, 2024
57a4d33
[update] add return type hint
nanoshimarobot Jun 16, 2024
54f0bce
[update] add checks for the existence of environment variables
nanoshimarobot Jun 16, 2024
a7538d4
[remove] unnecessary debug output
nanoshimarobot Jun 16, 2024
69ce89a
[update] exit if response contains HTTP status error
nanoshimarobot Jun 16, 2024
f803a38
[update] add main()
nanoshimarobot Jun 16, 2024
58c4e78
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 16, 2024
f674d9c
Merge branch 'main' into feat/ground_seg_annotation
nanoshimarobot Jun 16, 2024
a4eb462
Merge branch 'main' into feat/ground_seg_annotation
nanoshimarobot Jun 21, 2024
701d23a
[remove] unused module
nanoshimarobot Jun 24, 2024
f0f3e9a
Merge branch 'main' into feat/ground_seg_annotation
nanoshimarobot Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions config/convert_deepen_to_t4_paint_sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
task: convert_deepen_to_t4
description:
visibility:
full: "No occlusion of the object."
most: "Object is occluded, but by less than 50%."
partial: "The object is occluded by more than 50% (but not completely)."
none: "The object is 90-100% occluded and no points/pixels are visible in the label."
camera_index:
CAM_FRONT: 0
CAM_FRONT_RIGHT: 1
CAM_BACK_RIGHT: 2
CAM_BACK: 3
CAM_BACK_LEFT: 4
CAM_FRONT_LEFT: 5

conversion:
input_base: ./data/non_annotated_t4_format
dataset_corresponding:
Dataset_name: dataset_id_in_Deepen_AI
108 changes: 108 additions & 0 deletions perception_dataset/deepen/download_paint_annotations_to_pcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import argparse
from datetime import date
import json
import os
from typing import List
ktro2828 marked this conversation as resolved.
Show resolved Hide resolved
import zlib

import numpy as np
import requests
from sensor_msgs.msg import PointField
ktro2828 marked this conversation as resolved.
Show resolved Hide resolved
import tqdm
import yaml

if os.environ.get("DEEPEN_CLIENT_ID") is None or os.environ.get("DEEPEN_ACCESS_TOKEN") is None:
raise ValueError(
'You need to properly set the environment variables "DEEPEN_CLIENT_ID" and "DEEPEN_ACCESS_TOKEN"'
)
else:
CLIENT_ID = os.environ["DEEPEN_CLIENT_ID"]
ACCESS_TOKEN = os.environ["DEEPEN_ACCESS_TOKEN"]

today = str(date.today()).replace("-", "")
NUM_DIMENSIONS = 5


def get_datasets(dataset_id: str, input_base_dir: str) -> None:
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "application/json",
}

if dataset_id is None:
print("Dataset ID not found")
return

DATASET_URL = f"https://tools.deepen.ai/api/v2/datasets/{dataset_id}/label_types/3d_point/paint_labels?stageId=QA"

try:
response = requests.get(DATASET_URL, headers=headers)
response.raise_for_status()
except requests.exceptions.RequestException as e:
raise SystemExit(e)

decompress_data = bytearray(zlib.decompress(bytearray(response.content)))

header_list = list(response.headers.values())
label_info = json.loads(header_list[3])
frame_size = list(label_info["frame_sizes"])

# [
# [l,l,l,l,...],
# [l,l,l,l,...],
# ...
# ]

label_list = []
offset = 0
for i in range(len(frame_size)):
offset += frame_size[i - 1] if i != 0 else 0
label_list.append(
np.array([decompress_data[offset + j] for j in range(frame_size[i])], dtype=np.uint32)
)

sample_data_file = os.path.join(input_base_dir, "annotation", "sample_data.json")
sample_data = json.load(open(sample_data_file, "r"))
sample_data = list(filter(lambda d: d["filename"].split(".")[-2] == "pcd", sample_data))

for i in tqdm.tqdm(range(0, len(sample_data))):
pcd_file_path = os.path.join(input_base_dir, sample_data[i]["filename"])
scan = np.fromfile(pcd_file_path, dtype=np.float32)
points: np.ndarray = scan.reshape((-1, NUM_DIMENSIONS)) # 行数,列数
labelled_points: np.ndarray = np.concatenate(
[points, label_list[i].reshape(-1, 1)], 1, dtype=np.float32
)
labelled_points.tofile(pcd_file_path)


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--config",
type=str,
default="config/convert_deepen_to_t4.yaml",
)
parser.add_argument(
"--output_dir",
type=str,
default=".",
help="the directory where the annotation file is saved.",
)
args = parser.parse_args()

with open(args.config) as f:
config = yaml.safe_load(f)

assert (
config["task"] == "convert_deepen_to_t4"
), f"use config file of convert_deepen_to_t4 task: {config['task']}"
dataset_id = list(config["conversion"]["dataset_corresponding"].values())
input_base_dir = os.path.join(
config["conversion"]["input_base"], os.listdir(config["conversion"]["input_base"])[0]
)

get_datasets(dataset_id[0], input_base_dir)
ktro2828 marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
main()
Loading