Skip to content

Commit d04de2a

Browse files
committed
[fix] ruff formatting?
1 parent 26dd2f5 commit d04de2a

File tree

24 files changed

+162
-162
lines changed

24 files changed

+162
-162
lines changed

compressai_vision/codecs/encdec_utils/png_yuv.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ def __call__(self, input: Dict, file_prefix: str):
8989
images_in_folder = len(list(parent.glob(ext)))
9090
nb_frames = input["last_frame"] - input["frame_skip"]
9191

92-
assert images_in_folder == nb_frames, (
93-
f"input folder contains {images_in_folder} images, {nb_frames} were expected"
94-
)
92+
assert (
93+
images_in_folder == nb_frames
94+
), f"input folder contains {images_in_folder} images, {nb_frames} were expected"
9595

9696
input_info = [
9797
"-pattern_type",
@@ -122,9 +122,9 @@ def __call__(self, input: Dict, file_prefix: str):
122122

123123
# Use existing YUV (if found and indicated for use):
124124
if self.use_yuv:
125-
assert yuv_file is not None, (
126-
"Parameter 'use_yuv' set True but YUV file not found."
127-
)
125+
assert (
126+
yuv_file is not None
127+
), "Parameter 'use_yuv' set True but YUV file not found."
128128
size = yuv_file.stat().st_size
129129
bytes_per_luma_sample = {"yuv420p": 1.5}[chroma_format]
130130
bytes_per_sample = (input_bitdepth + 7) >> 3
@@ -135,9 +135,9 @@ def __call__(self, input: Dict, file_prefix: str):
135135
* bytes_per_sample
136136
* nb_frames
137137
)
138-
assert size == expected_size, (
139-
f"YUV found for input but expected size of {expected_size} bytes differs from actual size of {size} bytes"
140-
)
138+
assert (
139+
size == expected_size
140+
), f"YUV found for input but expected size of {expected_size} bytes differs from actual size of {size} bytes"
141141
shutil.copy(yuv_file, yuv_in_path)
142142
print(f"Using pre-existing YUV file: {yuv_file}")
143143
return (yuv_in_path, nb_frames, frame_width, frame_height, file_prefix)
@@ -204,9 +204,9 @@ def __call__(
204204
frame_width = video_info["width"]
205205
frame_height = video_info["height"]
206206

207-
assert "420" in video_info["format"].value, (
208-
f"Only support yuv420, but got {video_info['format']}"
209-
)
207+
assert (
208+
"420" in video_info["format"].value
209+
), f"Only support yuv420, but got {video_info['format']}"
210210
pix_fmt_suffix = "10le" if video_info["bitdepth"] == 10 else ""
211211
chroma_format = "yuv420p"
212212

compressai_vision/codecs/sic_sfu2022.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ def __init__(self, device: str, **kwargs):
151151
# root_url = "https://dspub.blob.core.windows.net/compressai/sic_sfu2022"
152152

153153
self.target_tlayer = int(kwargs["target_task_layer"])
154-
assert self.num_tasks == 2 or self.num_tasks == 3, (
155-
f"SIC_SFU2023 supports only 2 or 3 task layers, but got {self.num_tasks}"
156-
)
157-
assert self.target_tlayer < self.num_tasks, (
158-
f"target task layer must be lower than the number of tasks, \
154+
assert (
155+
self.num_tasks == 2 or self.num_tasks == 3
156+
), f"SIC_SFU2023 supports only 2 or 3 task layers, but got {self.num_tasks}"
157+
assert (
158+
self.target_tlayer < self.num_tasks
159+
), f"target task layer must be lower than the number of tasks, \
159160
but got {self.target_tlayer} < {self.num_tasks}"
160-
)
161161

162162
self.trg_vmodel = self.vmodels[self.target_tlayer]
163163

@@ -572,9 +572,9 @@ def compress(self, x, target_layer=0, feature_only=False):
572572
"models (the entropy coder is run sequentially on CPU)."
573573
)
574574

575-
assert target_layer < self.NUM_LAYERS, (
576-
f"Got the target layer {target_layer}, but should be less than {self.NUM_LAYERS}"
577-
)
575+
assert (
576+
target_layer < self.NUM_LAYERS
577+
), f"Got the target layer {target_layer}, but should be less than {self.NUM_LAYERS}"
578578

579579
y = self.g_a(x)
580580
z = self.h_a(y)

compressai_vision/codecs/std_codecs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ def encode(
480480
for partial in list_of_bitstreams:
481481
Path(partial).unlink()
482482

483-
assert Path(bitstream_path).is_file(), (
484-
f"bitstream {bitstream_path} was not created"
485-
)
483+
assert Path(
484+
bitstream_path
485+
).is_file(), f"bitstream {bitstream_path} was not created"
486486

487487
if not remote_inference:
488488
inner_codec_bitstream = load_bitstream(bitstream_path)
@@ -601,12 +601,12 @@ def decode(
601601
for file_path in sorted(Path(dec_path).glob(f"*{file_prefix}*.png")):
602602
rec_frames.append(str(file_path))
603603

604-
assert file_prefix in rec_frames[0], (
605-
f"Can't find a correct filename with {file_prefix} in {dec_path}"
606-
)
607-
assert len(rec_frames) == 1, (
608-
f"Number of retrieved file must be 1, but got {len(rec_frames)}"
609-
)
604+
assert (
605+
file_prefix in rec_frames[0]
606+
), f"Can't find a correct filename with {file_prefix} in {dec_path}"
607+
assert (
608+
len(rec_frames) == 1
609+
), f"Number of retrieved file must be 1, but got {len(rec_frames)}"
610610

611611
conversion_time = 0
612612
output = {"file_names": rec_frames}

compressai_vision/codecs/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ def reshape_frame_to_feature_pyramid(
257257
"""reshape a frame of channels into the feature pyramid"""
258258

259259
assert isinstance(x, (Tensor, Dict))
260-
assert packing_all_in_one is True, (
261-
"packing_all_in_one = False is not supported yet"
262-
)
260+
assert (
261+
packing_all_in_one is True
262+
), "packing_all_in_one = False is not supported yet"
263263

264264
top_y = 0
265265
tiled_frames = {}

compressai_vision/datasets/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ def __init__(self, root, dataset_name, imgs_folder, **kwargs):
246246
if kwargs["linear_mapper"] is True:
247247
mapper = LinearMapper()
248248
else:
249-
assert kwargs["cfg"] is not None, (
250-
"A proper mapper information via cfg must be provided"
251-
)
249+
assert (
250+
kwargs["cfg"] is not None
251+
), "A proper mapper information via cfg must be provided"
252252
mapper = DatasetMapper(kwargs["cfg"], False)
253253

254254
self.mapDataset = MapDataset(_dataset, mapper)

compressai_vision/datasets/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def __call__(self, dataset_dict):
140140
# Read image
141141
org_img = cv2.imread(dataset_dict["file_name"]) # return img in BGR by default
142142

143-
assert len(org_img.shape) == 3, (
144-
f"detect an input image with 2 chs, {dataset_dict['file_name']}"
145-
)
143+
assert (
144+
len(org_img.shape) == 3
145+
), f"detect an input image with 2 chs, {dataset_dict['file_name']}"
146146

147147
img_h, img_w, _ = org_img.shape
148148

@@ -221,9 +221,9 @@ def __call__(self, dataset_dict):
221221
# Read image
222222
org_img = cv2.imread(dataset_dict["file_name"]) # return img in BGR by default
223223

224-
assert len(org_img.shape) == 3, (
225-
f"detect an input image with 2 chs, {dataset_dict['file_name']}"
226-
)
224+
assert (
225+
len(org_img.shape) == 3
226+
), f"detect an input image with 2 chs, {dataset_dict['file_name']}"
227227

228228
dataset_dict["height"], dataset_dict["width"], _ = org_img.shape
229229

compressai_vision/evaluators/evaluators.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,9 @@ def digest_summary(summary):
725725
return ret
726726

727727
def mot_eval(self):
728-
assert len(self.dataset) == len(self._predictions), (
729-
"Total number of frames are mismatch"
730-
)
728+
assert len(self.dataset) == len(
729+
self._predictions
730+
), "Total number of frames are mismatch"
731731

732732
# skip the very first frame
733733
for gt_frame in self.dataset[1:]:
@@ -818,9 +818,9 @@ def __init__(
818818
assert self.seqinfo_path is not None, "Sequence Information must be provided"
819819

820820
def mot_eval(self):
821-
assert len(self.dataset) == len(self._predictions), (
822-
"Total number of frames are mismatch"
823-
)
821+
assert len(self.dataset) == len(
822+
self._predictions
823+
), "Total number of frames are mismatch"
824824

825825
self._save_all_eval_info(self._predictions)
826826
_pd_pd = self._format_pd_in_motchallenge(self._predictions)
@@ -874,9 +874,9 @@ def __init__(
874874
)
875875

876876
def mot_eval(self):
877-
assert len(self.dataset) == len(self._predictions), (
878-
"Total number of frames are mismatch"
879-
)
877+
assert len(self.dataset) == len(
878+
self._predictions
879+
), "Total number of frames are mismatch"
880880

881881
self._save_all_eval_info(self._predictions)
882882
_pd_pd = self._format_pd_in_motchallenge(self._predictions)

compressai_vision/model_wrappers/detectron2.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ def __init__(self, img_size: list):
387387
proposals, _ = self.proposal_generator(cdummy, x, None)
388388
results, _ = self.roi_heads(cdummy, x, proposals, None)
389389

390-
assert not torch.jit.is_scripting(), (
391-
"Scripting is not supported for postprocess."
392-
)
390+
assert (
391+
not torch.jit.is_scripting()
392+
), "Scripting is not supported for postprocess."
393393
return self.model._postprocess(
394394
results,
395395
[
@@ -423,9 +423,9 @@ def __init__(self, img_size: list):
423423
proposals, _ = self.proposal_generator(cdummy, x, None)
424424
results, _ = self.roi_heads(cdummy, x, proposals, None)
425425

426-
assert not torch.jit.is_scripting(), (
427-
"Scripting is not supported for postprocess."
428-
)
426+
assert (
427+
not torch.jit.is_scripting()
428+
), "Scripting is not supported for postprocess."
429429
return self.model._postprocess(
430430
results,
431431
[
@@ -461,9 +461,9 @@ def __init__(self, img_size: list):
461461
proposals, _ = self.proposal_generator(cdummy, fptensors, None)
462462
results, _ = self.roi_heads(cdummy, fptensors, proposals, None)
463463

464-
assert not torch.jit.is_scripting(), (
465-
"Scripting is not supported for postprocess."
466-
)
464+
assert (
465+
not torch.jit.is_scripting()
466+
), "Scripting is not supported for postprocess."
467467

468468
return self.model._postprocess(
469469
results,
@@ -483,9 +483,9 @@ def deeper_features_for_accuracy_proxy(self, x: Dict):
483483
d = {}
484484
for e, ft in enumerate(x["data"].values()):
485485
nft = ft.contiguous().to(self.device)
486-
assert nft.dim() == 3 or nft.dim() == 4, (
487-
f"Input feature tensor dimension is supposed to be 3 or 4, but got {nft.dim()}"
488-
)
486+
assert (
487+
nft.dim() == 3 or nft.dim() == 4
488+
), f"Input feature tensor dimension is supposed to be 3 or 4, but got {nft.dim()}"
489489
d[e] = nft.unsqueeze(0) if nft.dim() == 3 else nft
490490

491491
class dummy:
@@ -580,9 +580,9 @@ def __init__(self, img_size: list):
580580
proposals, _ = self.proposal_generator(cdummy, x, None)
581581
results, _ = self.roi_heads(cdummy, x, proposals, None)
582582

583-
assert not torch.jit.is_scripting(), (
584-
"Scripting is not supported for postprocess."
585-
)
583+
assert (
584+
not torch.jit.is_scripting()
585+
), "Scripting is not supported for postprocess."
586586

587587
processed_results = []
588588
for sem_seg_result, detector_result, input_per_image, image_size in zip(

compressai_vision/model_wrappers/jde.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ def _jde_process(self, pred, org_img_size: tuple, input_img_size: tuple):
243243
# removed tracks from the current frame
244244
current_removed_tracks = []
245245

246-
assert pred.size(1) == 54264, (
247-
f"Default number of proposals by JDE must be 54264, but got {pred.size(1)}"
248-
)
246+
assert (
247+
pred.size(1) == 54264
248+
), f"Default number of proposals by JDE must be 54264, but got {pred.size(1)}"
249249

250250
selected_pred = pred[:, pred[0, :, 4] > self.model_configs["conf_thres"]]
251251
# only check the objects detected with confidence greater than .5

compressai_vision/pipelines/base.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,14 @@ def _update_codec_configs_at_pipeline_level(self, total_num_frames):
175175
self._codec_skip_n_frames = self.configs["codec"]["skip_n_frames"]
176176
n_frames_to_be_encoded = self.configs["codec"]["n_frames_to_be_encoded"]
177177

178-
assert self._codec_skip_n_frames < total_num_frames, (
179-
f"Number of skip frames {self._codec_skip_n_frames} must be less than total number of frames {total_num_frames}"
180-
)
178+
assert (
179+
self._codec_skip_n_frames < total_num_frames
180+
), f"Number of skip frames {self._codec_skip_n_frames} must be less than total number of frames {total_num_frames}"
181181

182182
if n_frames_to_be_encoded == -1:
183183
n_frames_to_be_encoded = total_num_frames
184184

185-
assert n_frames_to_be_encoded, (
186-
f"Number of frames to be encoded must be greater than 0, but got {n_frames_to_be_encoded}"
187-
)
185+
assert n_frames_to_be_encoded, f"Number of frames to be encoded must be greater than 0, but got {n_frames_to_be_encoded}"
188186

189187
if (self._codec_skip_n_frames + n_frames_to_be_encoded) > total_num_frames:
190188
self.logger.warning(
@@ -202,9 +200,11 @@ def _update_codec_configs_at_pipeline_level(self, total_num_frames):
202200
self._codec_skip_n_frames > 0
203201
or self._codec_n_frames_to_be_encoded != total_num_frames
204202
):
205-
assert self.configs["codec"]["encode_only"], (
206-
"Encoding part of a sequence is only available when `codec.encode_only' is True"
207-
)
203+
assert self.configs[
204+
"codec"
205+
][
206+
"encode_only"
207+
], "Encoding part of a sequence is only available when `codec.encode_only' is True"
208208

209209
self._codec_end_frame_idx = (
210210
self._codec_skip_n_frames + self._codec_n_frames_to_be_encoded
@@ -219,18 +219,18 @@ def _prep_features_to_dump(features, n_bits, datacatalog_name):
219219
if n_bits == -1:
220220
data_features = features["data"]
221221
elif n_bits >= 8:
222-
assert n_bits == 8 or n_bits == 16, (
223-
"currently it only supports dumping features in 8 bits or 16 bits"
224-
)
225-
assert datacatalog_name in list(MIN_MAX_DATASET.keys()), (
226-
f"{datacatalog_name} does not exist in the pre-computed minimum and maximum tables"
227-
)
222+
assert (
223+
n_bits == 8 or n_bits == 16
224+
), "currently it only supports dumping features in 8 bits or 16 bits"
225+
assert (
226+
datacatalog_name in list(MIN_MAX_DATASET.keys())
227+
), f"{datacatalog_name} does not exist in the pre-computed minimum and maximum tables"
228228
minv, maxv = MIN_MAX_DATASET[datacatalog_name]
229229
data_features = {}
230230
for key, data in features["data"].items():
231-
assert data.min() >= minv and data.max() <= maxv, (
232-
f"{data.min()} should be greater than {minv} and {data.max()} should be less than {maxv}"
233-
)
231+
assert (
232+
data.min() >= minv and data.max() <= maxv
233+
), f"{data.min()} should be greater than {minv} and {data.max()} should be less than {maxv}"
234234
out, _ = min_max_normalization(data, minv, maxv, bitdepth=n_bits)
235235

236236
if n_bits <= 8:
@@ -258,12 +258,12 @@ def _post_process_loaded_features(features, n_bits, datacatalog_name):
258258
if n_bits == -1:
259259
assert "data" in features
260260
elif n_bits >= 8:
261-
assert n_bits == 8 or n_bits == 16, (
262-
"currently it only supports dumping features in 8 bits or 16 bits"
263-
)
264-
assert datacatalog_name in list(MIN_MAX_DATASET.keys()), (
265-
f"{datacatalog_name} does not exist in the pre-computed minimum and maximum tables"
266-
)
261+
assert (
262+
n_bits == 8 or n_bits == 16
263+
), "currently it only supports dumping features in 8 bits or 16 bits"
264+
assert (
265+
datacatalog_name in list(MIN_MAX_DATASET.keys())
266+
), f"{datacatalog_name} does not exist in the pre-computed minimum and maximum tables"
267267
minv, maxv = MIN_MAX_DATASET[datacatalog_name]
268268
data_features = {}
269269
for key, data in features["data"].items():

0 commit comments

Comments
 (0)