StevenLiuWen / ano_pred_cvpr2018

Official implementation of Paper Future Frame Prediction for Anomaly Detection -- A New Baseline, CVPR 2018
435 stars 126 forks source link

Intended ways to create prediction and difference images #6

Closed Santana18 closed 6 years ago

Santana18 commented 6 years ago

I would like to output all prediction and difference images during inference and save them as jpgs. Is there a suggested or intended way of doing that with your code? Was diff_mask intended for storing difference images?

Thanks!

StevenLiuWen commented 6 years ago

@Santana18

  1. output prediction and save them as jpgs. You can change the codes in inference.py line 81 and 82 as followings:

    psnr, pred,  = sess.run([test_psnr_error, test_outputs],
                                feed_dict={test_video_clips_tensor: video_clip[np.newaxis, ...]})
    pred = test_outputs[0]
    pred = (pred + 1) / 2.0  # rescale the color space to [0, 1] 

    You can save pred as jpg by cv2 or other image processing packages.

  2. diff_mask is the operator to compute the difference between prediction image and ground truth image. If you want to save the prediction image and diff_mask as the same time, you can do followings: In inference.py line 43 to 46

    with tf.variable_scope('generator', reuse=None):
    print('testing = {}'.format(tf.get_variable_scope().name))
    test_outputs = generator(test_inputs, layers=4, output_channel=3)
    test_psnr_error = psnr_error(gen_frames=test_outputs, gt_frames=test_gt)
    diff_mask_tensor = diff_mask(test_outputs, test_gt)

    In inference.py line 81 to 82

    psnr, pred, diff = sess.run([test_psnr_error, test_outputs, diff_mask_tensor], 
                                feed_dict={test_video_clips_tensor: video_clip[np.newaxis, ...]})
    pred = (pred[0] + 1) / 2.0   # rescale the color space to [0, 1]
    diff = diff[0]

    You can save pred and diff as jpg by cv2 or other image processing packages.

Santana18 commented 6 years ago

Thanks a lot! You are awesome!

Got it to work!