def test_upload_fusion_segment_with_label(self, accesskey, url, tmp_path): gas_client = GAS(access_key=accesskey, url=url) dataset_name = get_dataset_name() dataset_client = gas_client.create_dataset(dataset_name, is_fusion=True) dataset_client.create_draft("draft-1") dataset_client.upload_catalog(Catalog.loads(CATALOG)) segment = FusionSegment("segment1") segment.sensors.add(Sensor.loads(LIDAR_DATA)) path = tmp_path / "sub" path.mkdir() for i in range(10): frame = Frame() local_path = path / f"hello{i}.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) data.label = Label.loads(LABEL) frame[LIDAR_DATA["name"]] = data segment.append(frame) dataset_client.upload_segment(segment) segment1 = FusionSegment(name="segment1", client=dataset_client) assert len(segment1) == 10 assert segment1[0][LIDAR_DATA["name"]].path == "hello0.txt" assert ( segment1[0][LIDAR_DATA["name"]].path == segment[0][LIDAR_DATA["name"]].target_remote_path ) assert segment1[0][LIDAR_DATA["name"]].label # todo: match the input and output label gas_client.delete_dataset(dataset_name)
def test_upload_frame_with_label(self, accesskey, url, tmp_path): gas_client = GAS(access_key=accesskey, url=url) dataset_name = get_dataset_name() dataset_client = gas_client.create_dataset(dataset_name, is_fusion=True) dataset_client.create_draft("draft-1") dataset_client.upload_catalog(Catalog.loads(CATALOG)) segment_client = dataset_client.get_or_create_segment("segment1") segment_client.upload_sensor(Sensor.loads(LIDAR_DATA)) path = tmp_path / "sub" path.mkdir() for i in range(5): frame = Frame() local_path = path / f"hello{i}.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) data.label = Label.loads(LABEL) frame[LIDAR_DATA["name"]] = data segment_client.upload_frame(frame, timestamp=i) frames = segment_client.list_frames() assert len(frames) == 5 assert frames[0][LIDAR_DATA["name"]].path == "hello0.txt" assert frames[0][LIDAR_DATA["name"]].label # todo: match the input and output label gas_client.delete_dataset(dataset_name)
def test_delete_frame(self, accesskey, url, tmp_path): gas_client = GAS(access_key=accesskey, url=url) dataset_name = get_dataset_name() dataset_client = gas_client.create_dataset(dataset_name, is_fusion=True) dataset_client.create_draft("draft-1") dataset_client.upload_catalog(Catalog.loads(BOX2D_CATALOG)) segment_client = dataset_client.get_or_create_segment("segment1") segment_client.upload_sensor(Sensor.loads(LIDAR_DATA)) path = tmp_path / "sub" path.mkdir() for i in range(5): frame = Frame() local_path = path / f"hello{i}.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) data.label = Label.loads(LABEL) frame[LIDAR_DATA["name"]] = data segment_client.upload_frame(frame, timestamp=i) frame_1_id = segment_client.list_frames()[0].frame_id segment_client.delete_frame(frame_1_id) frame_ids = [frame.frame_id for frame in segment_client.list_frames()] assert frame_1_id not in frame_ids gas_client.delete_dataset(dataset_name)
def test_copy_fusion_segment(self, accesskey, url, tmp_path): gas_client = GAS(access_key=accesskey, url=url) dataset_name = get_dataset_name() gas_client.create_dataset(dataset_name, is_fusion=True) dataset = FusionDataset(name=dataset_name) segment = dataset.create_segment("Segment1") segment.sensors.add(Sensor.loads(LIDAR_DATA)) dataset._catalog = Catalog.loads(CATALOG) path = tmp_path / "sub" path.mkdir() for i in range(10): frame = Frame() local_path = path / f"hello{i}.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) data.label = Label.loads(LABEL) frame[LIDAR_DATA["name"]] = data segment.append(frame) dataset_client = gas_client.upload_dataset(dataset) segment_client = dataset_client.copy_segment("Segment1", "Segment2") assert segment_client.name == "Segment2" with pytest.raises(InvalidParamsError): dataset_client.copy_segment("Segment1", "Segment3", strategy="push") segment2 = FusionSegment("Segment2", client=dataset_client) assert segment2[0][LIDAR_DATA["name"]].path == "hello0.txt" assert ( segment2[0][LIDAR_DATA["name"]].path == segment[0][LIDAR_DATA["name"]].target_remote_path ) assert segment2[0][LIDAR_DATA["name"]].label gas_client.delete_dataset(dataset_name)
def test_upload_frame_with_order(self, accesskey, url, tmp_path): gas_client = GAS(access_key=accesskey, url=url) dataset_name = get_dataset_name() dataset_client = gas_client.create_dataset(dataset_name, is_fusion=True) dataset_client.create_draft("draft-1") segment_client = dataset_client.get_or_create_segment("segment1") segment_client.upload_sensor(Sensor.loads(LIDAR_DATA)) path = tmp_path / "sub" path.mkdir() # If noe setting frame id in frame, set timestamp(order) when uploading for i in reversed(range(5)): frame = Frame() local_path = path / f"hello{i}.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) frame[LIDAR_DATA["name"]] = data segment_client.upload_frame(frame, timestamp=i) # Set frame id in frame for i in range(5, 10): frame = Frame(frame_id=ulid.from_timestamp(i)) local_path = path / f"goodbye{i}.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) frame[LIDAR_DATA["name"]] = data segment_client.upload_frame(frame) # Both setting frame id in frame and set timestamp(order) when uploading are not allowed i = 10 frame = Frame(frame_id=ulid.from_timestamp(i)) local_path = path / f"goodbye{i}.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) frame[LIDAR_DATA["name"]] = data with pytest.raises(FrameError): segment_client.upload_frame(frame, timestamp=i) # Neither setting frame id in frame nor set timestamp(order) when uploading is not allowed frame = Frame() local_path = path / f"goodbye{i}.txt" local_path.write_text("CONTENT") data = Data(local_path=str(local_path)) frame[LIDAR_DATA["name"]] = data with pytest.raises(FrameError): segment_client.upload_frame(frame) frames = segment_client.list_frames() assert len(frames) == 10 assert frames[0][LIDAR_DATA["name"]].path == "hello0.txt" assert frames[5][LIDAR_DATA["name"]].path == "goodbye5.txt" assert not frames[0][LIDAR_DATA["name"]].label # todo: match the input and output label gas_client.delete_dataset(dataset_name)
def test_loads(self): camera_1 = Sensor.loads(_CAMERA_DATA) assert camera_1.extrinsics == Transform3D(_TRANSLATION, _ROTATION) assert camera_1.intrinsics == CameraIntrinsics(fx=1, fy=1, cx=1, cy=1, skew=0, p1=1, p2=1, k1=1, k2=1)
def test_sensor(self, accesskey, url): gas_client = GAS(access_key=accesskey, url=url) dataset_name = get_dataset_name() dataset_client = gas_client.create_dataset(dataset_name, is_fusion=True) dataset_client.create_draft("draft-1") segment_client = dataset_client.get_or_create_segment("segment1") for sensor_data in SENSORS_DATA: segment_client.upload_sensor(Sensor.loads(sensor_data)) sensors = segment_client.get_sensors() assert sensors == Sensors.loads(SENSORS_DATA) segment_client.delete_sensor(SENSORS_DATA[0]["name"]) sensors = segment_client.get_sensors() assert len(sensors) == 4 assert sensors == Sensors.loads(SENSORS_DATA[1:]) gas_client.delete_dataset(dataset_name)
def test_upload_frame_with_auth_data(self, accesskey, url, config_name): gas_client = GAS(access_key=accesskey, url=url) try: cloud_client = gas_client.get_cloud_client(config_name) except ResourceNotExistError: pytest.skip(f"skip this case because there's no {config_name} config") auth_data = cloud_client.list_auth_data("tests")[:5] dataset_name = get_dataset_name() dataset_client = gas_client.create_dataset(dataset_name, True, config_name=config_name) dataset_client.create_draft("draft-1") segment_client = dataset_client.get_or_create_segment("segment1") segment_client.upload_sensor(Sensor.loads(LIDAR_DATA)) for index, data in enumerate(auth_data): frame = Frame() frame[LIDAR_DATA["name"]] = data segment_client.upload_frame(frame, timestamp=index) frames = segment_client.list_frames() assert len(frames) == len(auth_data) assert frames[0][LIDAR_DATA["name"]].path == auth_data[0].path.split("/")[-1] gas_client.delete_dataset(dataset_name)