You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/02/22 17:21:30 UTC

[GitHub] jeremiedb edited a comment on issue #14061: error when try resize on pixel video to perform image-recognition analysis in R

jeremiedb edited a comment on issue #14061: error when try resize on pixel video to perform image-recognition analysis in R
URL: https://github.com/apache/incubator-mxnet/issues/14061#issuecomment-466111001
 
 
   @jasperDD 
   
   Data should be handled as arrays in mxnet. 
   For images, each observation is 3D (HxWxC). To store multiple observations, a 4th dimension is therefore needed. Data fed to the network will be of shape [HxWxCxBatchSize]. 
   
   For images, you could use the following approach to convert videos in arrays of images of the appropriate format: 
   
   ```
   library(imager)
   
   fname <- system.file('extdata/tennis_sif.mpeg',package='imager')
   tennis <- load.video(fname, frames = 10, fps = 4)
   dim(tennis)
   tennis_split <- imsplit(tennis, axis = "z")
   
   img_array <- array(dim = c(352, 240, 3, 10))
   for (i in 1:10) {
     img_array[,,,i] <- array(tennis_split[[i]], dim = c(352, 240, 3))
   }
   
   img_1 <- as.cimg(img_array[,,,1])
   dim(img_1)
   plot(img_1)
   ```
   
   What the above does is to extract 10 frames from the video, at a sample rate of 4 images per second. 
   Then the `imsplit` is used to create a list of images. The loop is used to create an `img_array ` that is in a compatible format with mxnet. 
   Note that works for tests but will likely be inefficient for training datasets of decent size. 
   Converting the frames from video into jpeg and then converting that collection of jpeg files into a RecordIO through im2rec utility would provide an highly efficient image iterator for training on large image dataset. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services