- Deep Learning with PyTorch
- Vishnu Subramanian
- 179字
- 2021-06-24 19:16:24
4-D tensors
One common example for four-dimensional tensor types is a batch of images. Modern CPUs and GPUs are optimized to perform the same operations on multiple examples faster. So, they take a similar time to process one image or a batch of images. So, it is common to use a batch of examples rather than use a single image at a time. Choosing the batch size is not straightforward; it depends on several factors. One major restriction for using a bigger batch or the complete dataset is GPU memory limitations—16, 32, and 64 are commonly used batch sizes.
Let's look at an example where we load a batch of cat images of size 64 x 224 x 224 x 3 where 64 represents the batch size or the number of images, 244 represents height and width, and 3 represents channels:
#Read cat images from disk
cats = glob(data_path+'*.jpg')
#Convert images into numpy arrays
cat_imgs = np.array([np.array(Image.open(cat).resize((224,224))) for cat in cats[:64]])
cat_imgs = cat_imgs.reshape(-1,224,224,3)
cat_tensors = torch.from_numpy(cat_imgs)
cat_tensors.size()
Output - torch.Size([64, 224, 224, 3])
- Arduino入門基礎教程
- 極簡Spring Cloud實戰
- Intel FPGA/CPLD設計(高級篇)
- 電腦組裝、維護、維修全能一本通(全彩版)
- Learning Game Physics with Bullet Physics and OpenGL
- VCD、DVD原理與維修
- Hands-On Machine Learning with C#
- 計算機組裝與維護(第3版)
- 電腦高級維修及故障排除實戰
- 微型計算機系統原理及應用:國產龍芯處理器的軟件和硬件集成(基礎篇)
- 圖解計算機組裝與維護
- 筆記本電腦芯片級維修從入門到精通(圖解版)
- Arduino項目開發:智能生活
- 嵌入式系統原理及應用:基于ARM Cortex-M4體系結構
- Mastering Quantum Computing with IBM QX