torchvision icon indicating copy to clipboard operation
torchvision copied to clipboard

Reading images benchmarks

Open dfalbel opened this issue 4 years ago • 0 comments

Looks like jpeg and png are faster than magick for reading images. We should probably use them instead:

file <- "~/Downloads/tiny-imagenet/tiny-imagenet-200/train/n01443537/images/n01443537_0.JPEG"

bench::mark(
  jpeg = jpeg::readJPEG(file),
  magick = as.integer(magick::image_data(magick::image_read(file), "rgb"))/255, 
  check = FALSE
)
#> # A tibble: 2 x 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 jpeg          115µs 157.19µs     6189.  121.49KB    13.8 
#> 2 magick        950µs   1.11ms      862.    5.45MB     2.04

file <- "~/Documents/torch/man/figures/torch.png"

bench::mark(
  png = png::readPNG(file),
  magick = as.integer(magick::image_data(magick::image_read(file), "rgb"))/255, 
  check = FALSE
)
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # A tibble: 2 x 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 png           150ms    170ms      5.84     127MB     3.89
#> 2 magick        404ms    411ms      2.44     148MB     2.44

Created on 2020-08-29 by the reprex package (v0.3.0)

dfalbel avatar Aug 29 '20 17:08 dfalbel