glob
copied
3 changed files with 56 additions and 0 deletions
@ -1,2 +1,39 @@ |
|||||
# glob |
# glob |
||||
|
|
||||
|
*author: junjie.jiang* |
||||
|
|
||||
|
|
||||
|
<br /> |
||||
|
|
||||
|
|
||||
|
## Desription |
||||
|
|
||||
|
Wrapper of python glob.glob |
||||
|
|
||||
|
The parameters are consistent with it. |
||||
|
|
||||
|
<br /> |
||||
|
|
||||
|
|
||||
|
## Code Example |
||||
|
|
||||
|
### Example |
||||
|
|
||||
|
```python |
||||
|
from towhee import DataLoader, pipe, ops |
||||
|
p = ( |
||||
|
pipe.input('image_path') |
||||
|
.map('image_path', 'image', ops.image_decode.cv2()) |
||||
|
.map('image', 'vec', ops.image_embedding.timm(model_name='resnet50')) |
||||
|
.output('vec') |
||||
|
|
||||
|
) |
||||
|
|
||||
|
for data in DataLoader(ops.data_source.glob('./*.jpg')): |
||||
|
print(p(data).to_list(kv_format=True)) |
||||
|
|
||||
|
# batch |
||||
|
for data in DataLoader(ops.data_source.glob('./*.jpg'), batch_size=10): |
||||
|
p.batch(data) |
||||
|
``` |
||||
|
|
||||
|
@ -0,0 +1,4 @@ |
|||||
|
from .path_glob import PathGlob |
||||
|
|
||||
|
def glob(*args, **kwargs): |
||||
|
return PathGlob(*args, **kwargs) |
@ -0,0 +1,15 @@ |
|||||
|
from glob import glob |
||||
|
|
||||
|
from towhee.operator.base import PyOperator |
||||
|
|
||||
|
|
||||
|
class PathGlob(PyOperator): |
||||
|
""" |
||||
|
Wrapper of glob.glob |
||||
|
""" |
||||
|
def __init__(self, pathname, *, recursive=False): |
||||
|
self._pattern = pathname |
||||
|
self._recursive = recursive |
||||
|
|
||||
|
def __call__(self): |
||||
|
return glob(self._pattern, recursive=self._recursive) |
Loading…
Reference in new issue