pytorch / accimage Goto Github PK
View Code? Open in Web Editor NEWhigh performance image loading and augmenting routines mimicking PIL.Image interface
License: BSD 2-Clause "Simplified" License
high performance image loading and augmenting routines mimicking PIL.Image interface
License: BSD 2-Clause "Simplified" License
This is what I get when I applying RandomHorizontalFlip():
As you can see the upper part of some images is totally disrupted.
Here is how I use the accimage:
`
import accimage
def get_img_loader(batch_size, shuffle=True, num_workers=8, mode='train', img_size=227):
t_dir = os.path.join(imagenet_ssd_dir, 'train')
v_dir = os.path.join(imagenet_ssd_dir, 'val')
transform_t = Compose([
RandomResizedCrop(img_size, (1.0, 1.0), (1.0, 1.0)),
RandomHorizontalFlip(),
ToTensor(),
# Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
transform_v = Compose([
CenterCrop(img_size),
ToTensor(),
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
if mode == 'val':
data_folder = ImageFolder(v_dir, transform_v, loader=accimage.Image)
else:
data_folder = ImageFolder(t_dir, transform_t, loader=accimage.Image)
return DataLoader(data_folder, batch_size=batch_size,shuffle=shuffle, num_workers=num_workers)
`
Are there any plans to offer PNG support?
test.py loads chicago.jpg by default but this file is not shipped with the source code.
Could you make it pip installable? None from here.
window system can't able to install accimage
Hi,
is it possible to convert an image that was loaded to numpy? I would like to load images with accimage but then chain a custom image transform in CV2. np.asarray() seems to do nothing.
Thanks!
$ sudo python setup.py install
running install
running build
running build_ext
building 'accimage' extension
creating build
creating build/temp.linux-x86_64-3.6
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/opt/jpeg-turbo/include -I/opt/intel/ipp/include -I/home/user1/anaconda3/envs/mxgpu/include/python3.6m -c accimagemodule.c -o build/temp.linux-x86_64-3.6/accimagemodule.o
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/opt/jpeg-turbo/include -I/opt/intel/ipp/include -I/home/user1/anaconda3/envs/mxgpu/include/python3.6m -c jpegloader.c -o build/temp.linux-x86_64-3.6/jpegloader.o
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/opt/jpeg-turbo/include -I/opt/intel/ipp/include -I/home/user1/anaconda3/envs/mxgpu/include/python3.6m -c imageops.c -o build/temp.linux-x86_64-3.6/imageops.o
imageops.c:5:10: fatal error: ippi.h: No such file or directory
5 | #include <ippi.h>
| ^~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
PIL could open image directly from io.BytesIO, like
import io
image_buffer = io.BytesIO()
image_buffer.write(image_string)
image_buffer.seek(0)
image = Image.open(image_buffer)
This is helpful for loading image from a database. Thanks!
Travis CI is dead and we need to move away.
Currently accimage is used as a backend for torchvision, however it's not clear how to build it (what dependencies are required etc). I have been trying to build it this morning and it doesn't play nice if libjpeg is already in the system.
Would it be possible to release a distribution (a wheel or conda tar) of this so it's easier to install?
As a side note, this would allow us to easily install accimage as part of the travis job in torchvision so that we can run the tests that require accimage.
How much faster is accimage
than Pillow{,-SIMD}
? Some rough numbers, even say a single sentence in the root README, would be helpful.
FWIW Pillow has some benchmarks here: https://python-pillow.org/pillow-perf/
We should add some OSS license to the package. I'd opt for 2-clause BSD.
Probably jpeg_mem_src
would help (accepts a offset and count).
When loading graysacle images by accimage.Image('a.jpg'), it outputs 3 channels images instead of 1. Any plan to fix it? Thanks.
(swin) D:\vit\Swin-Transformer>python main.py --eval --cfg configs/swin_tiny_patch4_window7_224.yaml --resume swin_tiny_patch4_window7_224.--data-path
D:\vit\Swin-Transformer\MINIST
usage: Swin Transformer training and evaluation script --cfg FILE
[--opts OPTS [OPTS ...]]
[--batch-size BATCH_SIZE]
[--data-path DATA_PATH]
[--zip]
[--cache-mode {no,full,part}]
[--resume RESUME]
[--accumulation-steps ACCUMULATION_STEPS]
[--use-checkpoint]
[--amp-opt-level {O0,O1,O2}]
[--output PATH]
[--tag TAG] [--eval]
[--throughput]
Swin Transformer training and evaluation script: error: the following arguments are required: --cfg
I run conda install -c conda-forge accimage
I get
PackagesNotFoundError: The following packages are not available from current channels:
Current channels:
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
Traceback (most recent call last):
File "main.py", line 365, in
main(config)
File "main.py", line 86, in main
dataset_train, dataset_val, data_loader_train, data_loader_val, mixup_fn = build_loader(config)
File "D:\vit\Swin-Transformer\data\build.py", line 24, in build_loader
dataset_train, config.MODEL.NUM_CLASSES = build_dataset(is_train=True, config=config)
File "D:\vit\Swin-Transformer\data\build.py", line 83, in build_dataset
dataset = datasets.ImageFolder(root, transform=transform)
File "C:\Users\86183\anaconda3\envs\swin\lib\site-packages\torchvision\datasets\folder.py", line 229, in init
is_valid_file=is_valid_file)
File "C:\Users\86183\anaconda3\envs\swin\lib\site-packages\torchvision\datasets\folder.py", line 108, in init
classes, class_to_idx = self._find_classes(self.root)
File "C:\Users\86183\anaconda3\envs\swin\lib\site-packages\torchvision\datasets\folder.py", line 137, in _find_classes
classes = [d.name for d in os.scandir(dir) if d.is_dir()]
FileNotFoundError: [WinError 3] The system could mot find the specified path: 'D:\vit\Swin-Transformer\data\MINIST\train'
Installing and switching to the accimage backend breaks my transforms.RandomResizedCrop
. The fix I've found is modifying crop()
in torchvisions.transforms.functional
so that it does
img.crop((int(j), int(i), int(j + w), int(i + h)))
instead of
img.crop((j, i, j + w, i + h))
(sidenote: this library is deliciously fast)
Hi, I was writing some augmentation transforms and I noticed that all operations are done in place.
I forked and added a .copy() method for my use, but I wonder if this is the correct way of doing it.
I like accimage quite as it is 4 to 6 times faster in my profiling than either going thru opencv or PIL to tensor.
I like, as well, that accimage operates in place by default, but as it stands, accimage breaks transformations that rely on data copies, such as FiveCrop. PIL default behaviour always returns a copy.
On my augmentation library Im changing the FiveCrop to bypass accimage by running Image.copy() if accimage.
img = ...
import PIL
import accimage
import torchvision.transforms as ttrans
fcrop = ttrans.Compose([ttrans.FiveCrop(100),
ttrans.Lambda(lambda crops: torch.stack([ttrans.ToTensor()(crop) for crop in crops]))])
aim = PIL.Image.open(img)
f = fcrop(aim)
# OK
fcrop = ttrans.Compose([ttrans.FiveCrop(100),
ttrans.Lambda(lambda crops: torch.stack([ttrans.ToTensor()(crop) for crop in crops]))])
aim = accimage.Image(img)
f = fcrop(aim)
# Fails
If you are interested you can look at my forked solution. BUT it is a half way solution since it requires a fix to torvision.transforms.
and what is the channel sequence i.e BRG or RGB
(found it whilst downloading resnet from https://github.com/pytorch/vision , but unclear what it is / why it is?)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.