output_np = np.swapaxes(output_np, 1, 2) #(batch, frames, featureDim) output_np = np.reshape(output_np, (-1, featureDim)) output_np = np.swapaxes(output_np, 0, 1) #(featureDim, frames) inputData_np_ori = np.swapaxes(inputData_np_ori, 1, 2) #(batch, frames, featureDim) inputData_np_ori = np.reshape(inputData_np_ori, (-1, featureDim)) inputData_np_ori = np.swapaxes(inputData_np_ori, 0, 1) # outputData_np_ori = np.swapaxes(outputData_np_ori,1,2) #(batch, frames, 73) # outputData_np_ori = np.reshape(outputData_np_ori,(-1,featureDim73)) # outputData_np_ori = np.swapaxes(outputData_np_ori,0,1) faceData = [output_np, inputData_np_ori] glViewer.SetFaceParmData(faceData, False) glViewer.init_gl() continue #Save Speaking prediction pred = output.data.cpu().numpy() pred_all = np.concatenate((pred_all, pred[:, -1]), axis=0) test_X_vis = np.concatenate((test_X_vis, inputData_np_ori), axis=0) #Computing Accuracy pred_binary = pred_all[:] >= 0.5 pred_binary = pred_binary[:, -1] from sklearn.metrics import accuracy_score test_Y_cropped = test_Y[:len(pred_binary), -1]
plt.title('Prediction (probability)') #plt.ion() plt.show() #plt.pause(1) bVisualize = False if bVisualize: #by jhugestar sys.path.append('/ssd/codes/glvis_python/') #from glViewer import SetFaceParmData,setSpeech,setSpeechGT,setSpeech_binary, setSpeechGT_binary, init_gl #opengl visualization import glViewer maxFrameNum = 2000 frameNum = test_X_vis.shape[0] startIdx = 0 test_X_vis = np.swapaxes( test_X_vis, 0, 1) #(frames, 200) ->(200, frames) where num can be thought as frames while startIdx < frameNum: endIdx = min(frameNum, startIdx + maxFrameNum) glViewer.setSpeechGT_binary([test_Y_cropped[startIdx:endIdx]]) glViewer.setSpeech_binary([pred_binary[startIdx:endIdx]]) glViewer.SetFaceParmData([test_X_vis[:, startIdx:endIdx]]) glViewer.init_gl() startIdx += maxFrameNum
sampleNum = 1 for _ in range(100): sample_2 = torch.randn(sampleNum, 100) #0.5 # print(sample_2[:10]) faceData = [] for model in model_list: for iter in [1.0, 3.0]: sample_2_iter = Variable(sample_2 * iter).cuda() output = model.decode(sample_2_iter) #De-standardaize output_np = output.data.cpu().numpy() #(batch, featureDim, frames) output_np = output_np * Xstd + Xmean output_np = np.swapaxes(output_np, 1, 2) #(batch, frames, featureDim) output_np = np.reshape(output_np, (-1, featureDim)) output_np = np.swapaxes(output_np, 0, 1) #(featureDim, frames) #faceData = [output_np] faceData.append(output_np) glViewer.SetFaceParmData(faceData) glViewer.init_gl()
output_np = output_np * Xstd + Xmean output_np = np.swapaxes(output_np, 1, 2) #(batch, frames, featureDim) output_np = np.reshape(output_np, (-1, featureDim)) output_np = np.swapaxes(output_np, 0, 1) #(featureDim, frames) faceData.append(output_np) inputData_np_ori = np.swapaxes(inputData_np_ori, 1, 2) #(batch, frames, featureDim) inputData_np_ori = np.reshape(inputData_np_ori, (-1, featureDim)) inputData_np_ori = np.swapaxes(inputData_np_ori, 0, 1) faceData.append(inputData_np_ori) #recon, flipped, original #faceData = [output_np, inputData_np_ori] glViewer.SetFaceParmData(faceData, bComputeNormal=False) glViewer.init_gl() continue #Save Speaking prediction pred = output.data.cpu().numpy() pred_all = np.concatenate((pred_all, pred[:, -1]), axis=0) test_X_vis = np.concatenate((test_X_vis, inputData_np_ori), axis=0) #Computing Accuracy pred_binary = pred_all[:] >= 0.5 pred_binary = pred_binary[:, -1] from sklearn.metrics import accuracy_score test_Y_cropped = test_Y[:len(pred_binary), -1]
# bodyData_pred = body_mean.copy()[0,:66,:] #Mirroring (buyer) (73) # bodyData_pred = np.repeat(bodyData_pred,bodyData[0].shape[1],axis=1)*HOLDEN_DATA_SCALING # """ # bodyData_gt = bodyData[1][:-7,:]*HOLDEN_DATA_SCALING #GT # bodyData_gt = bodyData_gt[:,:bodyData_pred.shape[1]] # skelErr = ( bodyData_pred - bodyData_gt)**2 #66, frames # skelErr = np.reshape(skelErr, (3,22,-1)) #3,22, frames # skelErr = np.sqrt(np.sum(skelErr, axis=0)) #22,frames # skelErr = np.mean(skelErr,axis=0) #frames # skeletonErr_list.append(skelErr) if bVisualize == False: continue glViewer.SetFaceParmData(faceData, False) glViewer.init_gl() # Compute error ##Draw Error Figure avg_skelErr_list = [] total_avg_skelErr = 0 cnt = 0 for p in skeletonErr_list: avgValue = np.mean(p) avg_skelErr_list.append(avgValue) print(avgValue) total_avg_skelErr += avgValue * len(p) cnt += len(p)
bad_test = train_X_raw[pIdx] bad_test = np.max(np.max(bad_test, axis=2), axis=1) import matplotlib.pyplot as plt plt.plot(bad_test) plt.show() ##Debug: visualize sys.path.append('/ssd/codes/glvis_python/') import glViewer testParam = train_X_raw[2, [9482, 11381, 15670, 15671, 15672, 17707], :, :100] testParam = np.reshape(testParam, (-1, 100)) testParam = np.swapaxes(testParam, 0, 1) glViewer.SetFaceParmData([testParam]) glViewer.init_gl() # train_X = train_X[:-1:10,:,:] # train_Y = train_Y[:-1:10,:] test_data = np.load(datapath + test_dblist[0] + '.npz') test_X_raw = test_data[ 'clips'] #Input (3, numClip, chunkLengh, featureDim:200) test_speech_raw = test_data['speech'] #Input (3, numClip, chunkLengh) #Attach speech signal test_X_raw = test_X_raw[:, :, :, :1] test_speech_raw = np.expand_dims(test_speech_raw, 3) test_X_raw = np.concatenate((test_X_raw, test_speech_raw), axis=3)
pred = pred.data.cpu().numpy() pred = (pred * Ystd[:, :, :featureDim]) + Ymean[:, :, :featureDim] pred = pred[:, -1, :] #(batch, feature) vis_data = np.reshape(pred, (-1, featureDim)) vis_data = np.swapaxes(vis_data, 0, 1) #GT visualization vis_data_gt = outputData_np_ori[:, -1, :] #(batch, features) vis_data_gt = np.swapaxes(vis_data_gt, 0, 1) #(features, batch) #GT visualization (input) vis_data_input = inputData_np_ori[:, -1, :] #(batch, features) vis_data_input = np.swapaxes(vis_data_input, 0, 1) #(features, batch) glViewer.SetFaceParmData([vis_data_input, vis_data_gt, vis_data]) glViewer.init_gl() continue #Save Speaking prediction pred = output.data.cpu().numpy() pred_all = np.concatenate((pred_all, pred[:, -1]), axis=0) test_X_vis = np.concatenate((test_X_vis, inputData_np_ori), axis=0) #Computing Accuracy pred_binary = pred_all[:] >= 0.5 pred_binary = pred_binary[:, -1] from sklearn.metrics import accuracy_score test_Y_cropped = test_Y[:len(pred_binary), -1]