logo
Browse Source

Update

Signed-off-by: shiyu22 <shiyu.chen@zilliz.com>
main
shiyu22 3 years ago
parent
commit
2f535105d0
  1. 8
      README.md
  2. BIN
      readme_res/operator.png
  3. 3
      test_transform_image_operator_template.py
  4. 2
      transform_image_operator_template.py
  5. 2
      transform_image_operator_template.yaml

8
README.md

@ -23,12 +23,12 @@ __init__(self, size: int)
- supported types: `int`
```python
int__call__(self, img: Union[Image.Image, torch.Tensor, str])
int__call__(self, img_path: Union[Image.Image, torch.Tensor, str])
```
**Args:**
- img:
- img_path:
- the input image to be processed
- supported type: `PIL.image`, `torch.Tensor` or `str` (path of the image)
@ -46,8 +46,6 @@ You can get the required python package by [requirements.txt](https://zilliverse
## **How it works**
The `towhee/transform-image-operator-template` Operator is used for image transformation and is an important part of data preprocessing. It can be added to the pipeline and is usually used as the first custom operator of the pipeline. For example, it's the first Operator named processing within [image-embedding-pipeline-template](https://hub.towhee.io/towhee/image-embedding-pipeline-template) pipeline, and it is the red box in the picture below.
![img](./readme_res/operator.png)
The `towhee/transform-image-operator-template` Operator is used for image transformation and is an important part of data preprocessing. It can be added to the pipeline and is usually used as the first custom operator of the pipeline. For example, it's the first Operator named processing within [image-embedding-pipeline-template](https://hub.towhee.io/towhee/image-embedding-pipeline-template) pipeline.
## **Reference**

BIN
readme_res/operator.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 KiB

3
test_transform_image_operator_template.py

@ -6,7 +6,6 @@ from config import TEST_IMG, SIZE
class TestTransformImageOperatorTemplate(unittest.TestCase):
test_img = Image.open(TEST_IMG)
tfms = transforms.Compose(
[
transforms.Resize(SIZE),
@ -19,7 +18,7 @@ class TestTransformImageOperatorTemplate(unittest.TestCase):
def test_transform_image(self):
op = TransformImageOperatorTemplate(SIZE)
outputs = op(self.test_img)
outputs = op(TEST_IMG)
print("The output tyep of operator:", type(outputs.img_transformed))
c = (self.img1.numpy() == outputs.img_transformed.numpy())
self.assertEqual(c.all(), True)

2
transform_image_operator_template.py

@ -29,7 +29,7 @@ class TransformImageOperatorTemplate(Operator):
super().__init__()
#user defined initialization
def __call__(self, img: Union[Image.Image, torch.Tensor, str]) -> NamedTuple('Outputs', [('img_transformed', torch.Tensor)]):
def __call__(self, img_path: Union[Image.Image, torch.Tensor, str]) -> NamedTuple('Outputs', [('img_transformed', torch.Tensor)]):
results = #user defined function: get the transformed image
Outputs = NamedTuple('Outputs', [('img_transformed', torch.Tensor)])
return Outputs(results)

2
transform_image_operator_template.yaml

@ -8,6 +8,6 @@ init:
size: int
call:
input:
img: Union[Image.Image, torch.Tensor, str]
img_path: Union[Image.Image, torch.Tensor, str]
output:
img_transformed: torch.Tensor
Loading…
Cancel
Save