Giter Club home page Giter Club logo

pytoflow's Introduction

pyTOFlow

This repository is based on the paper 'TOFlow: Video Enhancement with Task-Oriented Flow'. It contains some pre-trained models and all of the codes we used including training code, network structure and so on.

What's more, you can describe it as the python version of the TOFlow presented there -> toflow

Note: There are still some TODOs should be done now, it is welcome to create a pull request to improve this repository. Let's make it better for fun and application!

Video Demo

IMAGE ALT TEXT

Evaluation Result

Vimeo interp.

Methods PSNR SSIM
TOFlow 33.53 0.9668
TOFlow + Mask 33.73 0.9682
pyTOFlow 33.10 0.9631

Vimeo-Gaussian

Methods PSNR SSIM
TOFlow 29.10 0.9544
pyTOFlow 34.73 0.9518

Vimeo SR

Methods PSNR SSIM
TOFlow 33.08 0.9417
pyTOFlow 31.46 0.9230

Prerequisites

PyTorch

Our implementation is based on PyTorch 0.4.1 (https://pytorch.org/).

PIL and matplotlib

For loading images. Check on matplotlib v2.0.2, but it doesn't work on higher version of it like v3.1.0 (Noted that v2.0.2 is not the bar.) See Issue#6, Issue#7 for details.

opencv-python(cv2)

For processing videos.

CUDA [optional]

CUDA is suggested (https://developer.nvidia.com/cuda-toolkit) for fast inference. The demo code is still runnable without CUDA, but much slower.

FFmpeg [optional]

We use FFmpeg (http://ffmpeg.org/) for processing videos. That's ok if you don't have a FFmpeg, but maybe it will cost you lot of time to processing.

Installation

Our current release has been tested on Ubuntu 16.04 LTS.

Clone the repository

sh git clone https://github.com/Coldog2333/pytoflow.git

Install some required packages

Download tiny Vimeo dataset (1‰ of Vimeo-90K)

You would like to have a quick start to understand the whole features of pytoflow. Then you can download the tiny Vimeo dataset and have a try. The tiny Vimeo dataset is chosen randomly from the origin Vimeo dataset and the processed Vimeo-90K (mixed noise, blurred).

cd .
sh download_tiny_dataset.sh
unzip tiny.zip

Train

python3 train.py [[option] [value]]...

Options

  • --task: training task, like interp, denoising, super-resolution. valid values:[interp, denoise, denoising, sr, super-resolution]
  • --dataDir: the directory of the image dataset(Vimeo-90K)
  • --ex_dataDir: the directory of the preprocessed image dataset, for example, the Vimeo-90K mixed by Gaussian noise.
  • --pathlist: the text file records which are the images for train.
  • --gpuID [optional]: No. of the GPU you want to use. default: no gpu.
  • -h, --help: get help.

Examples

python3 train.py --task interp --dataDir ./tiny/vimeo_triplet/sequences --pathlist ./tiny/vimeo_triplet/tri_trainlist.txt --gpuID 1
python3 train.py --task denoising --dataDir ./tiny/vimeo_septuplet/sequences --ex_dataDir ./tiny/vimeo_septuplet/sequences_with_noise --pathlist ./tiny/vimeo_septuplet/sep_trainlist.txt --gpuID 1
python3 train.py --task super-resolution --dataDir ./tiny/vimeo_septuplet/sequences --ex_dataDir ./tiny/vimeo_septuplet/sequences_blur --pathlist ./tiny/vimeo_septuplet/sep_trainlist.txt --gpuID 1

Evaluate

python3 evaluate.py [[option] [value]]...

Options

  • --task: training task, like interp, denoising, super-resolution. valid values:[interp, denoise, denoising, sr, super-resolution]
  • --dataDir: the directory of the input image dataset(Vimeo-90K, Vimeo-90K with noise, blurred Vimeo-90K)
  • --pathlist: the text file records which are the images for train.
  • --model: the path of the model used.
  • --gpuID [optional]: No. of the GPU you want to use. default: no gpu.
  • -h, --help: get help.

Examples

python3 evaluate.py --task interp --dataDir ./tiny/vimeo_triplet/sequences --pathlist ./tiny/vimeo_triplet/tri_testlist.txt --model ./toflow_models/interp.pkl --gpuID 1
python3 evaluate.py --task denoising --dataDir ./tiny/vimeo_septuplet/sequences_with_noise --ex_dataDir ./tiny/vimeo_septuplet/sequences_with_noise --pathlist ./tiny/vimeo_septuplet/sep_testlist.txt --model ./toflow_models/denoise.pkl --gpuID 1
python3 evaluate.py --task super-resolution --dataDir ./tiny/vimeo_septuplet/sequences_blur --ex_dataDir ./tiny/vimeo_septuplet/sequences_blur --pathlist ./tiny/vimeo_septuplet/sep_testlist.txt --model ./toflow_models/sr.pkl --gpuID 1

Usage

python3 ./unstable/run.py --f1 ./unstable/example/im1.png --f2 ./unstable/example/im3.png --o ./unstable/example/out.png --gpuID 0

Options

  • --f1: filename of the first frame
  • --f2: filename of the second frame
  • --o [optional]: filename of the predicted frame. default: out.png, saving in the same directory of the input frames.
  • --gpuID [optional]: No of the GPU you want to use. default: no gpu.

References

  1. Xue T , Chen B , Wu J , et al. Video Enhancement with Task-Oriented Flow[J]. 2017.(http://arxiv.org/abs/1711.09078)
  2. Our SpyNet is based on sniklaus/pytorch-spynet

Acknowledgments

Thanks for the author of the origin paper @anchen1011, he gives me a lot of advice during the time I reproduce this paper and teaches me a lot. Then thanks for the School of Mathematics, Sun Yat-Sen University that provices me the computing server. I can do nothing without this powerful server. At last, thanks for the accompany of my teammates Qian and Junjie.

TODO

  • A relatively poor but much more cheaper version of pytoflow for application.

For example, we can omit the last resnet layer that requires an extra system resources but only promotes a little improvement. After a comprehensive ablation analysis, we can convincingly determine which structures we can omit without dropping too much performance.

  • To support the cases when batch size is larger than 1 while training and testing.

Maybe we can accelarate it with running more than 1 sequence of pictures at a time (using matrix multiplication, etc.)

pytoflow's People

Contributors

coldog2333 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pytoflow's Issues

problems when using pytoflow

when I use the code on Viemo90K, I have encountered a problem that the value range of processed
images of the model is out of (0, 1), have you encountered this similar problem? and could you
give me some help? thanks a lot!

Question About Super Resolution

Dear friend,
First all, we hope express our thanks for your hard work.
Second, we have an question: Why super resolution output size is same as input images ?
Best Regards,

SR results not clear

Hi,
Trying to reproduce the SR results but it the output of the image appears to be the same size as the input. Is there a way to validate SR?

run.py has some detail to modify

1、TOFlow(intPreprocessedHeight, intPreprocessedWidth,'interp', cuda_flag=CUDA)
need to add interp
2、at function Estimate ,should add the following respect
inTensor = torch.cat((tensorPreprocessedFirst.unsqueeze(0),tensorPreprocessedSecond.unsqueeze(0)), 1)
tensorFlow = torch.nn.functional.interpolate(
input=net(inTensor),
size=(intHeight, intWidth), mode='bilinear', align_corners=False)

and i test some pics ,especially at the edge ,the artifact is obvious ,this flow based method is not well enough

About the evaluation results

Since the results on video denoising of pytoflow is very different from original results of toflow, so could you put how you evaluate your models? on matlab or using skimage of python?@Coldog2333

Issue in SSIM implementation

Hey, you have amazing work. I am facing an issue with SSIM score you have calculated. it's like reshaping the image and passing it from SSIM function is not consistent with the Original Implementation of authors of SSIM. See the code for reproducing please.

% LR image available here 'https://raw.githubusercontent.com/mugheesahmad/Fun_testing/master/LR0000001.jpg' 
% HR image available here 'https://raw.githubusercontent.com/mugheesahmad/Fun_testing/master/HR0000001.jpg' 
lr = imread('LR0000001.jpg');
hr = imread('HR0000001.jpg');
ssim(hr, lr) %colored image
% ans = 0.8433
ssim(rgb2gray(hr), rgb2gray(lr)) %builtin MATLAB function
% ans =    0.7570
original_ssim(rgb2gray(hr), rgb2gray(lr)) %author implementation available here https://ece.uwaterloo.ca/~z70wang/research/ssim/
% original implementation doesnot accept the RGB image
% ans =    0.7574 
lru = reshape(lr, [380*672,3]);  %your way of doing
hru = reshape(hr, [380*672,3]);
ssim(lru, hru)
%ans = 86.70

As per the docs of Matlab SSIM, only gray images can be passed. Your way of using it does not consistent with the original and also with the SSIM implementation with skimage and pytorch version. see this and this colab file.

the mask network

Many thanks for your work. It seems that the mask network isn't implemented in this verson and there is a mask network as discribed in the paper, right?

TypeError: __init__() missing 1 required positional argument: 'task'

Facing below error while attempting to use 'run.py'.
command-
python run.py --f1 example/im1.png --f2 example/im3.png --o example/out.png --gpuID 0

Error-
Loading TOFlow Net... Traceback (most recent call last):
File "run.py", line 112, in
net = TOFlow(intPreprocessedHeight, intPreprocessedWidth, cuda_flag=CUDA)
TypeError: init() missing 1 required positional argument: 'task'

Any help. Thanks!!

2x model

Hi @Coldog2333

Thank you for the great code! I noticed that the code is for 4x super-resolution. Is it possible to train a 2x super-resolution model? Thanks.

Best,
Yongcheng

run.py forward() takes 2 positional arguments but 3 were given

I'm attempting to use run.py - but getting the below error. Any ideas?

Loading TOFlow Net... Done.
Processing...
Traceback (most recent call last):
  File "run.py", line 131, in <module>
    predict = Estimate(net, Firstfilename=frameFirstName, Secondfilename=frameSecondName, cuda_flag=CUDA)
  File "run.py", line 88, in Estimate
    input=net(tensorPreprocessedFirst, tensorPreprocessedSecond),
  File "C:\Users\pete\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
TypeError: forward() takes 2 positional arguments but 3 were given

Why SR results is one output image?

Hi, thank you for your great reimplementation work. As we know, toflow can achieve video SR tasks. I want to know how to generate consecutive HR video frames instead of one frame from 7 consecutive LR video frames.

some error

Hi @Coldog2333

Thank you for the great code! I want to ask some questions when reproduce the sr/super-resolutionexperimental results. Something went wrong when I run the "train.py".
" framex = np.transpose(frames[0:N, :, :, :], (0, 3, 1, 2))
framey = np.transpose(frames[-1, :, :, :], (2, 0, 1))
IndexError:too many indices for array
"
Have you ever had this problem? How to deal with it?
1

information about trained models

Thank you for porting this work to pytorch. Could you provide more information about the trained models given in the folder toflow_models?

In particular, for the video denoising model (denoise.pkl):

  1. In the original work there are 3 types of noise considered (Gaussian 15, Gaussian 25 and mixed noise). Your denoise.pkl, on which type of noise was it trained?
  2. Is it the one trained by the original authors or the one you retrained?
  3. If it is the one you retrained, which trainset did you use, and for how many epochs.

License?

I've found the Pytoflow's temporal frame interpolation useful. Could you please add a license to the repository? Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.