深度学习常用命令

通用命令:

1. 通过PIL的Image读取图片, img_path 为文件地址

# 通过PIL的Image读取图片
img = Image.open(img_path)

2. 将pillow图片转换为ndarray.

# 将pillow图片转换为ndarray
# np.asarray 可以把一个pillow对象转换为ndarray
np.asarray(img).shape

3.数组转置, 维度调整.

npimg = img.numpy()
plt.imshow(np.transpose(npimg, (1, 2, 0)))


TensorFlow:


pytorch:

1. np.squeeze():  图片形状从(1, 28, 28) 变为(28, 28).

# 去掉1所在的维度
import numpy as np
img = np.squeeze(img)

2.pytorch中直接 显示图片. open后面为文件地址.

img = Image.open(all_img_path[0])
img

你可能感兴趣的:(深度学习,深度学习,python,numpy)