dtype=theano.config.floatX) * preprocess['Xstd']) + preprocess['Xmean'] def style_transfer(H, V): s, c = style_amount, 1.0 s, c = s / (s + c), c / (s + c) return s * T.mean((gram_matrix(H) - G)**2) + c * T.mean((H - network_C[0](C))**2) Xstyl = (S * preprocess['Xstd']) + preprocess['Xmean'] Xcntn = (C * preprocess['Xstd']) + preprocess['Xmean'] Xtrsf = N Xtrsf = constrain(Xtrsf, network_C[0], network_C[1], preprocess, style_transfer, iterations=250, alpha=0.01) Xtrsfvel = np.mean(np.sqrt(Xtrsf[:,-7:-6]**2 + Xtrsf[:,-6:-5]**2), axis=2)[:,:,np.newaxis] Xcntnvel = np.mean(np.sqrt(Xcntn[:,-7:-6]**2 + Xcntn[:,-6:-5]**2), axis=2)[:,:,np.newaxis] Xtail = Xtrsfvel * (Xcntn[:,-7:] / Xcntnvel) Xtail[:,-5:] = Xcntn[:,-5:] Xtrsf = constrain(Xtrsf, network_C[0], network_C[1], preprocess, multiconstraint( foot_sliding(Xtail[:,-4:]), joint_lengths(), trajectory(Xtail[:,:3])), alpha=0.01, iterations=100) Xtrsf[:,-7:] = Xtail Xstyl = np.concatenate([Xstyl, Xstyl], axis=2) from AnimationPlot import animation_plot animation_plot([Xstyl, Xcntn, Xtrsf], interval=15.15)
# 2021 # 13283 for _ in range(10): index = rng.randint(X.shape[0].eval()) print(index) Xorgi = np.array(X[index:index + 1].eval()) Xnois = ((Xorgi * rng.binomial(size=Xorgi.shape, n=1, p=0.5)) / 0.5).astype(theano.config.floatX) Xrecn = np.array(network(Xnois).eval()) Xorgi = (Xorgi * preprocess['Xstd']) + preprocess['Xmean'] Xnois = (Xnois * preprocess['Xstd']) + preprocess['Xmean'] Xrecn = (Xrecn * preprocess['Xstd']) + preprocess['Xmean'] Xrecn = constrain(Xrecn, network[0], network[1], preprocess, multiconstraint(foot_sliding(Xorgi[:, -4:].copy()), joint_lengths(), trajectory(Xorgi[:, -7:-4])), alpha=0.01, iterations=50) Xrecn[:, -7:-4] = Xorgi[:, -7:-4] animation_plot([Xnois, Xrecn, Xorgi], interval=15.15)
batchsize = 1 window = X.shape[2] X = theano.shared(X, borrow=True) network = create_core(batchsize=batchsize, window=window, dropout=0.0, depooler=lambda x,**kw: x/2) network.load(np.load('network_core.npz')) from AnimationPlot import animation_plot for _ in range(10): index = rng.randint(X.shape[0].eval()) Xorgi = np.array(X[index:index+1].eval()) Xnois = Xorgi.copy() Xnois[:,16*3-1:17*3] = 0.0 Xrecn = np.array(network(Xnois).eval()) Xorgi = (Xorgi * preprocess['Xstd']) + preprocess['Xmean'] Xnois = (Xnois * preprocess['Xstd']) + preprocess['Xmean'] Xrecn = (Xrecn * preprocess['Xstd']) + preprocess['Xmean'] Xrecn = constrain(Xrecn, network[0], network[1], preprocess, multiconstraint( foot_sliding(Xorgi[:,-4:].copy()), joint_lengths(), trajectory(Xorgi[:,-7:-4])), alpha=0.01, iterations=50) Xrecn[:,-7:-4] = Xorgi[:,-7:-4] animation_plot([Xnois, Xrecn, Xorgi], interval=15.15)
network_first, network_second, network = create_network( batchsize=T.shape[0], window=T.shape[2], hidden=T.shape[1]) network_func = theano.function([input], network(input), allow_input_downcast=True) start = time.clock() X = network_func(T) X = (X * preprocess['Xstd']) + preprocess['Xmean'] Xtail = (T * preprocess['Xstd'][:, -7:]) + preprocess['Xmean'][:, -7:] X = constrain(X, network_second[0], network_second[1], preprocess, multiconstraint(foot_sliding(Xtail[:, -4:]), joint_lengths(), trajectory(Xtail[:, :3])), alpha=0.01, iterations=10) X[:, -7:] = Xtail ############# animation_plot([X[0:1, :, :200], X[10:11, :, :200], X[20:21, :, :200]], interval=15.15) X = np.swapaxes(X, 1, 2) joints = X[:, :, :-7].reshape((X.shape[0], X.shape[1], -1, 3)) joints = -Quaternions( data[scene + '_rot'][:, cstart:cend])[:, :, np.newaxis] * joints
#Y shape:(1,12,240) network_func = theano.function([], network(Y[i:i + 1])) Y_pad_ori = np.array(Y_pad[i:i + 1]) Xorig = np.array(X[i:i + 1]) print('X shape: ', X.shape) #X shape: 121,73,240 print('Xorig shape: ', Xorig.shape) #Xorig shape : 1,73,240 start = time.clock() print('before network_func') Xrecn = network_func() # meaning that Y is inserted into network function then output will be Xrecn print('Xrecn shape: ', Xrecn.shape) #Xrecn shape: (1,73,240) Xorig = (Xorig * preprocess['Xstd']) + preprocess['Xmean'] Xrecn = (Xrecn * preprocess['Xstd']) + preprocess['Xmean'] Y_pad_ori = (Y_pad_ori * preprocess['Xstd']) + preprocess['Xmean'] print print('before constrain') #here Xrecn already same as Xorig, but next is add constraint Xrecn = constrain(Xrecn, network_second[0], network_second[1], preprocess, multiconstraint(foot_sliding(Xrecn[:, -4:].copy()), joint_lengths()), alpha=0.01, iterations=50) #print(data_kicking_cmu[i]) animation_plot([Xorig], interval=15.15)
print('Footsteps: %0.4f' % (time.clock() - start)) ############# network_first, network_second, network = create_network( Torig.shape[2], Torig.shape[1]) network_func = theano.function([input], network(input), allow_input_downcast=True) start = time.clock() Xrecn = network_func(Torig) Xrecn = (Xrecn * preprocess['Xstd']) + preprocess['Xmean'] Xtraj = ((Torig * preprocess['Xstd'][:, -7:]) + preprocess['Xmean'][:, -7:]).copy() print('Synthesis: %0.4f' % (time.clock() - start)) Xnonc = Xrecn.copy() Xrecn = constrain(Xrecn, network_second[0], network_second[1], preprocess, multiconstraint(foot_sliding(Xtraj[:, -4:]), trajectory(Xtraj[:, :3]), joint_lengths()), alpha=0.01, iterations=250) Xrecn[:, -7:] = Xtraj animation_plot([Xnonc, Xrecn], interval=15.15)
feet = np.array([9,10,11,12,13,14,21,22,23,24,25,26]) Y = X[:,feet] batchsize = 1 window = X.shape[2] network_first = create_regressor(batchsize=batchsize, window=window, input=Y.shape[1], dropout=0.0) network_second = create_core(batchsize=batchsize, window=window, dropout=0.0, depooler=lambda x,**kw:x/2) network_second.load(np.load('network_core.npz')) network = Network(network_first, network_second[1], params=network_first.params) network.load(np.load('network_regression_kick.npz')) from AnimationPlot import animation_plot for i in range(len(X)): network_func = theano.function([], network(Y[i:i+1])) Xorig = np.array(X[i:i+1]) start = time.clock() Xrecn = network_func() Xorig = (Xorig * preprocess['Xstd']) + preprocess['Xmean'] Xrecn = (Xrecn * preprocess['Xstd']) + preprocess['Xmean'] Xrecn = constrain(Xrecn, network_second[0], network_second[1], preprocess, multiconstraint( foot_sliding(Xrecn[:,-4:].copy()), joint_lengths()), alpha=0.01, iterations=50) animation_plot([Xorig, Xrecn], interval=15.15)
Xnois = np.concatenate([Xnois_Torso[:,0:3,:], Xnois_Leftleg, Xnois_Rightleg, Xnois_Torso[:,3:15,:], Xnois_Leftarm, Xnois_Rightarm, Xorgi[:,63:73,:]],axis=1) print(Xnois.shape) Xrecn = np.concatenate([Xrecn_Torso[:,0:3,:], Xrecn_Leftleg, Xrecn_Rightleg, Xrecn_Torso[:,3:15,:], Xrecn_Leftarm, Xrecn_Rightarm, Xorgi[:,63:73,:]], axis=1) Xorgi = (Xorgi * preprocess['Xstd']) + preprocess['Xmean'] Xnois = (Xnois * preprocess['Xstd']) + preprocess['Xmean'] Xrecn = (Xrecn * preprocess['Xstd']) + preprocess['Xmean'] np.save("./denoise/Xorgi.npy",Xorgi) np.save("./denoise/Xnois.npy",Xnois) print(Xorgi[:,-7:-4].shape) # H'=argmin[Pos(H)+Bone(H)+Traj(H)] Xrecn = constrain(Xrecn, network[0], network[1], preprocess, multiconstraint( foot_sliding(Xorgi[:,-4:].copy()),#foot sliding information(-4,-3,-2,-1) joint_lengths(), trajectory(Xorgi[:,-7:-4])), alpha=0.01, iterations=50)#input trajectory(-7,-6,-5) Xrecn[:,-7:-4] = Xorgi[:,-7:-4] np.save("./denoise/Xrecn.npy",Xrecn) print("construction done") animation_plot([Xnois, Xrecn, Xorgi], interval=15.15) """ Xnois = ((Xorgi * rng.binomial(size=Xorgi.shape, n=1, p=0.5)) / 0.5).astype(theano.config.floatX) #Xnois = (Xorgi + 0.05*np.random.randn(1,73,240)+0.1).astype(theano.config.floatX) Xrecn = np.array(network(Xnois).eval()) #print(Xrecn.shape)