github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/python/examples/ais-etl/etl_convert_img_to_npy.py (about) 1 """ 2 ETL to convert images to numpy arrays. 3 Communication Type: hpush:// 4 5 Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 6 """ 7 8 from aistore import Client 9 import numpy as np 10 import cv2 11 12 client = Client( 13 "http://192.168.49.2:8080" 14 ) # ip addr of aistore cluster (in k8s or minikube) 15 16 17 def transform(input_bytes): 18 nparr = np.fromstring(input_bytes, np.uint8) 19 return cv2.imdecode(nparr, cv2.IMREAD_COLOR) 20 21 22 # other opencv packages dont work in dockerized environments 23 deps = ["opencv-python-headless==4.5.3.56"] 24 25 # initialize ETL 26 client.etl("etl-img-to-npy").init_code(transform=transform, dependencies=deps) 27 28 to_bck = client.bucket("to-bck") 29 30 # Transform bucket with given ETL name 31 job_id = client.bucket("from-bck").transform( 32 etl_name="etl-img-to-npy", to_bck=to_bck, ext={"jpg": "npy"} 33 ) 34 client.job(job_id).wait() 35 36 # load an object from transformed bucket 37 print(np.frombuffer(to_bck.object("obj-id.npy").get().read_all(), dtype=np.uint8))