pytorch exchange channels and problems in numpy

Format pytorch network input image is (C, H, W), and the shape numpy image is (H, W, C)

Therefore, the general need to change the channel, the shape is converted into the numpy torch in shape.

Methods as below:

# A numpy data type is 
A = A.transpose (0,1,2) # not changed: (H, W, C) A = A.transpose (2,0,1) # is converted to: (c, h, w)

This torch can be entered directly into the network.

Guess you like

Origin www.cnblogs.com/mengxiangtiankongfenwailan/p/11994242.html