def minor_rotation(x, z):
"""
Assuming a batch size of 1.
More specifically: x is (1, depth, channels, height, width) and z is (1, height*width*depth, classes)
"""
from scipy.ndimage.interpolation import rotate as rotate_scipy
from breze.learn.data import one_hot
z_original_shape = z.shape
n_classes = z.shape[-1]
ang = float(np.random.uniform(-90, 90))
axes = np.random.permutation(3)[:2]
nx = np.transpose(x, (0, 2, 3, 4, 1))
nz = np.reshape(z, (1, x.shape[3], x.shape[4], x.shape[1], n_classes))
nz = np.transpose(nz, (0, 4, 1, 2, 3))
nx[0] = [rotate_scipy(modality, ang, axes=axes, order=3, reshape=False) for modality in nx[0]]
nx = np.transpose(nx, (0, 4, 1, 2, 3))
nz[0] = [rotate_scipy(class_map, ang, axes=axes, order=3, reshape=False) for class_map in nz[0]]
nz = nz[0].argmax(axis=0)
nz = np.reshape(nz, (-1,))
nz = np.reshape(one_hot(nz, n_classes), z_original_shape)
nx = np.asarray(nx, dtype=x.dtype)
nz = np.asarray(nz, dtype=z.dtype)
return (nx, nz)
transformations.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录