def eval(gt, pred): ''' Input size : (BS, C, H, W) ''' gt = (gt + 1.) * 127.5 pred = (pred + 1.) * 127.5 gt = np.clip(gt, 0., 255.).astype(np.uint8) pred = np.clip(pred, 0., 255.).astype(np.uint8) batch_size = np.shape(gt)[0] ssim = np.zeros([batch_size]) psnr = np.zeros([batch_size]) mse = np.zeros([batch_size]) for bs in range(batch_size): for c in range(gt[bs].shape[0]): ssim[bs] += ssim_metric(gt[bs][c], pred[bs][c]) psnr[bs] += psnr_metric(gt[bs][c], pred[bs][c]) mse[bs] += mse_metric(gt[bs], pred[bs]) psnr /= 3 ssim /= 3 return mse, ssim, psnr
def eval_seq(gt, pred): mse_l = [] ssim_l = [] psnr_l = [] l_pred = [] aa = [] T = len(gt) print("T",T) bs = gt[0].shape[0] print("bs",bs) ssim = np.zeros((bs, T)) psnr = np.zeros((bs, T)) mse = np.zeros((bs, T)) for i in range(bs): for t in range(T): for c in range(gt[t][i].shape[0]): ssim[i, t] += ssim_metric(gt[t][i][c], pred[t][i][c]) psnr[i, t] += psnr_metric(gt[t][i][c], pred[t][i][c]) ssim[i, t] /= gt[t][i].shape[0] psnr[i, t] /= gt[t][i].shape[0] mse[i, t] = mse_metric(gt[t][i], pred[t][i]) mse_l.append(mse) ssim_l.append(ssim) psnr_l.append(psnr) #l_pred=list(map(sum, zip(mse_l, ssim_l, psnr_l))) print('mse_l',mse_l) print('ssim_l',ssim_l) print('psnr_l',psnr_l) #print("l_pred val:", l_pred) #print('score at at eval_seq',score(l_pred, gt)) #mse_ll.append(mse) return mse, ssim, psnr
def eval_seq(gt, pred): T = len(gt) bs = gt[0].shape[0] for t in range(T): pred[t] = np.maximum(pred[t], 0) pred[t] = np.minimum(pred[t], 1) ssim = np.zeros((bs, T)) psnr = np.zeros((bs, T)) mse = np.zeros((bs, T)) mae = np.zeros((bs, T)) sharp = np.zeros((bs, T)) for i in range(bs): for t in range(T): mse[i, t] = mse_metric(gt[t][i], pred[t][i]) mae[i, t] = mae_metric(gt[t][i], pred[t][i]) sharp[i, t] = sharp_metric(pred[t][i]) x = np.uint8(gt[t][i] * 255) gx = np.uint8(pred[t][i] * 255) for c in range(gt[t][i].shape[0]): ssim[i, t] += ssim_metric(x[c], gx[c]) psnr[i, t] += psnr_metric(x[c], gx[c]) ssim[i, t] /= gt[t][i].shape[0] psnr[i, t] /= gt[t][i].shape[0] return np.sum(mse, axis=0), np.sum(mae, axis=0), np.sum(ssim, axis=0), np.sum(psnr, axis=0), np.sum(sharp, axis=0)
def eval_seq_batch(gt, pred): T = len(gt) bs = gt[0].shape[0] ssim = np.zeros(T) psnr = np.zeros(T) mse = np.zeros(T) mae = np.zeros(T) sharp = np.zeros(T) for t in range(T): x = gt[t][:, 0, :, :] gx = pred[t][:, 0, :, :] gx = np.maximum(gx, 0) gx = np.minimum(gx, 1) mae[t] = batch_mae_frame_float(gx, x) mse_t = np.square(x - gx).sum() mse[t] = mse_t real_frm = np.uint8(x * 255) pred_frm = np.uint8(gx * 255) psnr[t] = batch_psnr(pred_frm, real_frm) for b in range(bs): sharp[t] += np.max( cv2.convertScaleAbs(cv2.Laplacian(pred_frm[b], 3))) score, _ = ssim_metric(pred_frm[b], real_frm[b], full=True) ssim[t] += score return mse, mae, ssim, psnr, sharp
def get_seq_psnr_ssim(self, context_frames, gen_frames): """Compute PSNR and SSIM from skimage""" assert context_frames.shape == gen_frames.shape n_channels = gen_frames.shape[-1] n_future = gen_frames.shape[1] batch_size = gen_frames.shape[0] _psnr_by_step = np.zeros([batch_size, n_future]) _ssim_by_step = np.zeros([batch_size, n_future]) for b in range(batch_size): for t in range(n_future): for chan in range(n_channels): _psnr_by_step[b, t] += psnr_metric( context_frames[b, t, :, :, chan], gen_frames[b, t, :, :, chan]) _ssim_by_step[b, t] += ssim_metric( context_frames[b, t, :, :, chan], gen_frames[b, t, :, :, chan]) _psnr_by_step[b, t] /= n_channels _ssim_by_step[b, t] /= n_channels return _psnr_by_step, _ssim_by_step
def eval_seq(gt, pred): T = len(gt) bs = gt[0].shape[0] ssim = np.zeros((bs, T)) psnr = np.zeros((bs, T)) mse = np.zeros((bs, T)) for i in range(bs): for t in range(T): for c in range(gt[t][i].shape[0]): ssim[i, t] += ssim_metric(gt[t][i][c], pred[t][i][c]) psnr[i, t] += psnr_metric(gt[t][i][c], pred[t][i][c]) ssim[i, t] /= gt[t][i].shape[0] psnr[i, t] /= gt[t][i].shape[0] mse[i, t] = mse_metric(gt[t][i], pred[t][i]) return mse, ssim, psnr