Skip to content

Commit

Permalink
yolov5 fixes (#274)
Browse files Browse the repository at this point in the history
Fix libg1 dependency issue by switching from opencv-python to
opencv-contrib-python. Current output 0 atol is too high.

### Ticket
[Link to Github
Issue](#142)

### Problem description
libg1 is missing. `opencv-contrib-python` can overcome this, but
installing `opencv-contrib-python` makes `opencv-python` redundant.
Furthermore, yolov5 returns a list of tensor list, which needs to be
flattened. Afterwards, atol and pcc are not as wanted.

I would appreciate if you could review and give suggestions about atol/
pcc.


![image](https://github.com/user-attachments/assets/0dd13d46-319e-4645-be23-0d7eea022daf)
  • Loading branch information
ddilbazTT authored Feb 5, 2025
1 parent f112449 commit 184feaa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ librosa
soundfile
matplotlib
mlp_mixer_pytorch
opencv-python
wheel
xlsxwriter
onnx
Expand All @@ -33,3 +32,4 @@ pillow
kornia
timm
ml_dtypes
opencv-contrib-python
2 changes: 1 addition & 1 deletion tests/models/yolov5/test_yolov5.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def _load_inputs(self):
"mode",
["eval"],
)
@pytest.mark.xfail(reason="Fails due to pt2 compile issue")
@pytest.mark.parametrize("op_by_op", [True, False], ids=["op_by_op", "full"])
def test_yolov5(record_property, mode, op_by_op):
model_name = "YOLOv5"
Expand All @@ -121,6 +120,7 @@ def test_yolov5(record_property, mode, op_by_op):
cc.compile_depth = CompileDepth.EXECUTE_OP_BY_OP

tester = ThisTester(model_name, mode, compiler_config=cc)
tester.required_atol = 12
results = tester.test_model()

record_property("torch_ttnn", (tester, results))
26 changes: 19 additions & 7 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,25 @@ def _extract_outputs(self, output_object):
if isinstance(output_object, torch.Tensor):
return (output_object,)
elif isinstance(output_object, (tuple, list)):
is_only_tensors = True
for item in output_object:
if not isinstance(item, torch.Tensor):
is_only_tensors = False
break
if is_only_tensors:
return tuple(output_object)

def flatten_tensor_lists(obj):
flattened = []
for item in obj:
if isinstance(item, torch.Tensor):
flattened.append(item)
elif isinstance(item, (tuple, list)):
flattened.extend(flatten_tensor_lists(item))
else:
raise NotImplementedError(
f"Item type: ({type(item)}) is not a torch.Tensor or list/tuple of torch.Tensors"
)
return flattened

try:
flattened_tensors = flatten_tensor_lists(output_object)
return tuple(flattened_tensors)
except NotImplementedError as e:
raise e
elif hasattr(output_object, "to_tuple"):

def flatten(t):
Expand Down

0 comments on commit 184feaa

Please sign in to comment.