def prepare_binary_classification_data(real, fake):
import numpy as np
shape = real.shape[1:]
both = np.concatenate((real, fake),axis=0)
both = np.reshape(both, (len(both), -1)) # flatten
data_dim = both.shape[1]
both2 = np.pad(both, ((0,0),(0,1)), 'constant') # default 0
both2[:len(real),-1] = 1 # tag true
np.random.shuffle(both2)
train_in = np.reshape(both2[:int(0.9*len(both2)), :data_dim], (-1, *shape))
train_out = both2[:int(0.9*len(both2)), -1]
test_in = np.reshape(both2[int(0.9*len(both2)):, :data_dim], (-1, *shape))
test_out = both2[int(0.9*len(both2)):, -1]
return train_in, train_out, test_in, test_out
评论列表
文章目录