def standardize_X(shape, X): if not numpy_array(X): X = np.asarray(X) if len(shape) == 4 and len(X.shape) == 2: return X.reshape(-1, shape[2], shape[3], shape[1]).transpose(0, 3, 1, 2) else: return X
def standardize_Y(shape, Y): if not numpy_array(Y): Y = np.asarray(Y) if len(Y.shape) == 1: Y = Y.reshape(-1, 1) if len(Y.shape) == 2 and len(shape) == 2: if shape[-1] != Y.shape[-1]: return one_hot(Y, n=shape[-1]) else: return Y else: return Y
def ZeroOneScale(X): if not numpy_array(X): X = np.asarray(X) return X / 255.
def Standardize(X): if not numpy_array(X): X = np.asarray(X) return X / 127.5 - 1.
def ImgToConv(X): if not numpy_array(X): X = np.asarray(X) return X.transpose(0, 3, 1, 2)
def FlatToImg(X, w, h, c): if not numpy_array(X): X = np.asarray(X) return X.reshape(-1, w, h, c)