Hi,
The problem is that this script will load ALL your images into your computer main memory. If you have many of them, you may not have enough RAM to do so. For example Imagenet which is 150+GB will most likely not fit in memory !