Skip to content

Commit

Permalink
Update README, add poisson(remain questions) and fixes, tbd: temporal…
Browse files Browse the repository at this point in the history
… filter, static mode.
  • Loading branch information
ai4sciencelab committed Nov 25, 2019
1 parent 93abcd2 commit 831defd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# motion_magnification_learning-based
An unofficial implementation of "Learning-based Video Motion Magnification" in Pytorch.
An unofficial implementation of "[Learning-based Video Motion Magnification](https://arxiv.org/abs/1804.02684)" in Pytorch.
Refer to the official tensorflow version [code](https://github.com/12dmodel/deep_motion_mag).

# Data preparation
1. coco100000: please refer to the clarification in the official respository.
2. frames of validation video: TBD.

# Run
`bash run_G.sh` to train and test
> feel free to _ctrl+c_ to stop train, it will automatically do testing on several well-prepared validation video frames.
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __init__(self, lambda_G_new=None, skip=None, videos_train=None):
self.GPUs = '0'
self.batch_size = 4 * len(self.GPUs.split(','))
self.use_energy = False
self.date = '2019-11-24'
self.date = '2019-11-26'
prefix = '..'
self.dir_train = os.path.join(prefix, 'datasets/motion_mag_data/train')
self.dir_test = os.path.join(prefix, 'datasets/motion_mag_data/test')
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(self, lambda_G_new=None, skip=None, videos_train=None):
self.skip = 0 if not isinstance(skip, int) else skip
self.batch_size_test = 1
self.video_num = len(self.videos_train)
self.preproc = ['resize']
self.preproc = ['resize', 'poisson']

self.lr = 1e-4
self.betas_G = (0.9, 0.999)
Expand Down
19 changes: 16 additions & 3 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
ImageFile.LOAD_TRUNCATED_IMAGES = True
Tensor = torch.cuda.FloatTensor


def gen_poisson_noise(unit):
n = np.random.randn(*unit.shape)

# Strange here, unit has been in range of (-1, 1),
# but currently same as the official codes.
n_str = np.sqrt(unit + 1.0) / np.sqrt(127.5)
poisson_noise = np.multiply(n, n_str)
return poisson_noise


def load_unit(path, preproc):
# Load
file_suffix = path.split('.')[-1].lower()
Expand All @@ -34,6 +45,8 @@ def load_unit(path, preproc):
unit = cv2.cvtColor(unit, cv2.COLOR_BGR2RGB)
try:
unit = unit.astype(np.float32) / 127.5 - 1.0
if 'poisson' in preproc:
unit = unit + gen_poisson_noise(unit) * np.random.uniform(0, 0.3)
except Exception as e:
print('EX:', e, unit.shape, unit.dtype)

Expand All @@ -50,7 +63,7 @@ def unit_postprocessing(unit, residual=None, vid_size=None):
unit = torch.clamp(unit - residual, -1.0, 1.0)
unit = unit.cpu().detach().numpy()
unit = np.round((np.transpose(unit, (1, 2, 0)) + 1.0) * 127.5).astype(np.uint8)
if unit.shape[:2][::-1] != vid_size:
if unit.shape[:2][::-1] != vid_size and vid_size is not None:
unit = cv2.resize(unit, vid_size, interpolation=cv2.INTER_CUBIC)
return unit

Expand Down Expand Up @@ -147,8 +160,8 @@ def gen_test(self, anchor=None):
anchor = self.anchor

for _ in range(self.batch_size):
unit_A = load_unit(self.paths[anchor], preproc=self.preproc)
unit_C = load_unit(self.paths[anchor].replace('frameA', 'frameC'), preproc=self.preproc)
unit_A = load_unit(self.paths[anchor], preproc=['resize'])
unit_C = load_unit(self.paths[anchor].replace('frameA', 'frameC'), preproc=['resize'])
batch_A.append(unit_A)
batch_C.append(unit_C)

Expand Down
Binary file removed network.jpg
Binary file not shown.

0 comments on commit 831defd

Please sign in to comment.