Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Universal image reader designed for seamless reading of images into multiple formats, including PIL Images, Torch Tensors, and NumPy arrays.

License

NotificationsYou must be signed in to change notification settings

aredden/functis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

functis is a universal image reader designed for seamless reading of images into multiple formats, including PIL Images, torch Tensors via torchvision.io, and NumPy arrays via OpenCV. It offers flexibility in device placement, image format, color modes, data types, and output types.

Features

  • Read Modes: Supports multiple reading backends includingtorch,np,pil, andnvjpeg.

    note: torch is torchvision.io, np uses cv2, and nvjpeg is a private library I have yet to expose publically.

  • Device Placement: Place your data on any CUDA device or CPU.
  • Image Format: Choose betweenhwc orchw formats.
  • Color Modes: Multiple color options includingrgb,bgr,rgba,bgra, andgrayscale.
  • Data Types: Supportsuint8,float32, andfloat16 fortorch,nvjpeg andnp backends.
  • Output Types: Get the result inpil,np, ortorch formats.

Installation

git clone https://github.com/aredden/functiscd functispython -m pip install.

Usage

Basic Usage

fromfunctisimportImageReaderimreader=ImageReader().with_reader("torch").with_device("cuda:0").with_format("hwc")image=imreader.read("./your_image.jpg")

Reading Multiple Images from a Directory

forimageinimreader.read_dir("./your_image_directory"):# process or view your image    ...# For recursive reading...forimageinimreader.read_dir("./your_image_directory",recursive=True):# process or view your image    ...# Also will optionally include paths...forpath,imageinimreader.read_dir("./your_image_directory",return_paths=True):# process or view your image    ...

Reading a List of Images

Can also return paths, similar to read_dir.

forimageinimreader.read_list(list_of_your_images):# process or view your image    ...

Reading images as bytes

Relatively new feature (as of oct 11 2023)

withopen("./your_image.jpg","rb")asf:image=imreader.read(f.read())

Inspiration for this idea is that I wanted to have a way to efficienctly read images of all types from a web api, here is a simple fastapi example:

fromtypingimportAnnotatedfromfastapiimportFastAPI,Bodyapp=FastAPI()inference_client= ...@app.post("/inference",tags=["inference"])asyncdefinference(image_bytes:Annotated[bytes,Body(media_type="application/octet-stream")]):globalinference_clientimage=imreader.read(image_bytes)withtorch.no_grad():results_json=inference_client.infer(image)returnresults_json

Options

  • Read Modes:torch,np,pil,nvjpeg # torch nvjpeg reader is not public yet.
  • Device:cuda:<index>,cuda,cpu
  • Format:hwc,chw
  • Color Mode:rgb,bgr,rgba,bgra,grayscale
  • Data Type:uint8,float32,float16 (only for torch and np)
  • Image Type:pil,np,torch

Contributing

We welcome contributions! Please see ourcontributing guidelines for more details.

About

Universal image reader designed for seamless reading of images into multiple formats, including PIL Images, Torch Tensors, and NumPy arrays.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp