timm
copied
Jael Gu
3 years ago
3 changed files with 149 additions and 10 deletions
@ -1,2 +1,78 @@ |
|||
# timm-image |
|||
# Image Embedding with Timm |
|||
|
|||
*author: Jael Gu, Filip* |
|||
|
|||
|
|||
|
|||
## Desription |
|||
|
|||
An image embedding operator implemented with pretrained models provided by [Timm](https://github.com/rwightman/pytorch-image-models). |
|||
|
|||
|
|||
|
|||
```python |
|||
from towhee import ops |
|||
import numpy as np |
|||
|
|||
img_encoder = ops.image_embedding.timm('resnet50') |
|||
fake_img = np.zeros((256, 256, 3)) |
|||
image_embedding = img_encoder(fake_img) |
|||
``` |
|||
|
|||
## Factory Constructor |
|||
|
|||
Create the operator via the following factory method |
|||
|
|||
***ops.image_embedding.timm(model_name)*** |
|||
|
|||
|
|||
|
|||
## Interface |
|||
|
|||
An image decode operator takes an image path as input. It decodes the image back to ndarray. |
|||
|
|||
|
|||
|
|||
**Parameters:** |
|||
|
|||
***img***: *numpy.ndarray* |
|||
|
|||
The decoded image data in numpy.ndarray. |
|||
|
|||
|
|||
|
|||
**Returns**: *numpy.ndarray* |
|||
|
|||
The image embedding extracted by model. |
|||
|
|||
|
|||
|
|||
## Code Example |
|||
|
|||
Load an image from path './dog.jpg' |
|||
and use the pretrained ResNet50 model ('resnet50') to generate an image embedding. |
|||
|
|||
*Write the pipeline in simplified style*: |
|||
|
|||
```python |
|||
import towhee.DataCollection as dc |
|||
|
|||
dc.glob(./dog.jpg) |
|||
.image_decode() |
|||
.image_embedding.timm('resnet50') |
|||
.show() |
|||
``` |
|||
|
|||
*Write a same pipeline with explicit inputs/outputs name specifications:* |
|||
|
|||
```python |
|||
from towhee import DataCollection as dc |
|||
|
|||
dc.glob['path'](./dog.jpg) |
|||
.image_decode['path', 'img']() |
|||
.image_embedding.timm['img', 'vec']('resnet50') |
|||
.select('img') |
|||
.show() |
|||
``` |
|||
|
|||
|
|||
|
@ -0,0 +1,19 @@ |
|||
# Copyright 2021 Zilliz. All rights reserved. |
|||
# |
|||
# Licensed under the Apache License, Version 2.0 (the "License"); |
|||
# you may not use this file except in compliance with the License. |
|||
# You may obtain a copy of the License at |
|||
# |
|||
# http://www.apache.org/licenses/LICENSE-2.0 |
|||
# |
|||
# Unless required by applicable law or agreed to in writing, software |
|||
# distributed under the License is distributed on an "AS IS" BASIS, |
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
# See the License for the specific language governing permissions and |
|||
# limitations under the License. |
|||
|
|||
from .timm_image import TimmImage |
|||
|
|||
|
|||
def timm(): |
|||
return TimmImage() |
Loading…
Reference in new issue