Repository: towhee-io/towhee

Issue #347: [Enhancement]: Should be more elegant to handle exceptions
Created: 2021-12-25T08:07:57Z
Is there an existing issue for this?

 I have searched the existing issues

What would you like to be added?
This is not user friendly.
Downloading: "https://download.pytorch.org/models/resnet50-0676ba61.pth" to /Users/ryjiang/.cache/torch/hub/checkpoints/resnet50-0676ba61.pth
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 97.8M/97.8M [00:05<00:00, 18.1MB/s]
Traceback (most recent call last):
  File "index.py", line 9, in <module>
    output = embedding_pipeline('towhee_logo.png')
  File "/usr/local/lib/python3.7/site-packages/towhee/__init__.py", line 73, in __call__
    out_df = self._pipeline(in_df)
  File "/usr/local/lib/python3.7/site-packages/towhee/engine/pipeline.py", line 91, in __call__
    return graph_ctx.result()
  File "/usr/local/lib/python3.7/site-packages/towhee/engine/graph_context.py", line 75, in result
    raise RuntimeError(op.err_msg)
RuntimeError: preprocessing:0 runs failed, error msg: [Errno 2] No such file or directory: 'towhee_logo.png'


Why is this needed?

Prevents program from crashing if an error occurs
Better error message could save a lot of time for developers to debug

Anything else?
No response

Duplicate issue #344: [Bug]: Test image pipeline “ error msg: img should be PIL Image” Input image list hope that the error is not supported image list
Created: 2021-12-24T10:59:47Z
Is there an existing issue for this?

 I have searched the existing issues

Current Behavior
test  pipeline:
    pipeline_names = [ "image-embedding", 
                       "towhee/video_embedding_resnet50",
                       "towhee/img_object_embedding", 
                       "towhee/image-embedding-efficientnetb5",
                       "towhee/image-embedding-efficientnetb7", 
                       "towhee/image-embedding-resnet101",
                       "towhee/image-embedding-resnet50", 
                       "towhee/image-embedding-swinbase",
                       "towhee/image-embedding-swinlarge", 
                       "towhee/image-embedding-vitlarge"]

test script :
    def test_embedding_image_list(self, pipeline_name):
        """
        target: test embedding with image list
        method:  embedding with image list
        expected: raise exception
        """
        N = 3
        img_list = []
        img = cf.create_image()
        for i in range(N):
            img_list.append(img)
        embedding_pipeline = pipeline(pipeline_name)
        try:
            embedding = embedding_pipeline(img_list)
        except RuntimeError as e:
            assert "img should be PIL Image" in str(e)

        return True

error log:
Traceback (most recent call last):
  File "test_main.py", line 112, in <module>
    test_caller()
  File "test_main.py", line 104, in test_caller
    image_class_pipeline_runner()
  File "test_main.py", line 53, in image_class_pipeline_runner
    res = methodcaller(func, pipeline_name)(invalid_embedding_obj)
  File "/Users/jingjing/Workspace/towhee/tests/testcases/test_image_embedding.py", line 70, in test_embedding_image_list
    embedding = embedding_pipeline(img_list)
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/towhee/__init__.py", line 66, in __call__
    out_df = self._pipeline(in_df)
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/towhee/engine/pipeline.py", line 94, in __call__
    return graph_ctx.result()
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/towhee/engine/graph_context.py", line 77, in result
    raise OpFailedError(op.err_msg)
towhee.errors.OpFailedError: preprocessing:0 runs failed, error msg: img should be PIL Image. Got <class 'list'>, Traceback (most recent call last):
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/towhee/engine/operator_runner/runner_base.py", line 154, in _call_op
    outputs = self._op(**inputs)
  File "/Users/jingjing/.towhee/operators/pytorch_transform_operator&towhee$main/pytorch_transform_operator.py", line 52, in __call__
    return Outputs(self.tfms(img_tensor).unsqueeze(0))
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 61, in __call__
    img = t(img)
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 304, in forward
    return F.resize(img, self.size, self.interpolation, self.max_size, self.antialias)
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 419, in resize
    return F_pil.resize(img, size=size, interpolation=pil_interpolation, max_size=max_size)
  File "/Users/jingjing/miniconda3/envs/towhee/lib/python3.8/site-packages/torchvision/transforms/functional_pil.py", line 233, in resize
    raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
TypeError: img should be PIL Image. Got <class 'list'>

Expected Behavior
No response
Steps To Reproduce
No response
Environment
- Towhee version(e.g. v0.1.3 or 8b23a93): 0.3.1.dev18
- OS(Ubuntu or CentOS): 
- CPU/Memory: 
- GPU: 
- Others:
Anything else?
No response

Closing comment (2021-12-28T08:51:05Z): duplicate #347