Skip to content

Commit 5a23b6a

Browse files
authored
Merge pull request #6 from bachsh/master
Thank you very much to the two of you ! Yes, opencv-python is sometimes tricky to install, however works most of the times, I will therefore merge this first and then add it to the requirements. :)
2 parents 53ce35d + fc9daed commit 5a23b6a

12 files changed

+41
-20
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ The idea was to produce the equivalent of [torchvision transforms](https://githu
1010

1111
The basic paradigm is that dataloading should produce videoclips as a **list of PIL Images or numpy.ndarrays** (in format as read by opencv).
1212

13-
Several transforms are then provided in [video_transforms](videotransforms/video_transforms.py).
13+
Several transforms are then provided in [video_transforms](torchvideotransforms/video_transforms.py).
1414

1515
Each transform iterates on all the images in the list and applies the wanted augmentation.
1616

1717

1818
We then have to convert those inputs to torch tensors.
19-
This can be produced by the [volume_transform](videotransforms/volume_transforms.py).**ClipToTensor** class, which produces a video volume in format (n_channels, n_images, height, width) where n_channels = 3 in case of images.
19+
This can be produced by the [volume_transform](torchvideotransforms/volume_transforms.py).**ClipToTensor** class, which produces a video volume in format (n_channels, n_images, height, width) where n_channels = 3 in case of images.
2020

2121
When randomness is involved, the same random parameters (crop size, scale size, rotation angle,...) are applied to all the frames.
2222

@@ -28,7 +28,7 @@ This should produce something like the top image (this is a dummy clip for now,
2828

2929
# Advancement
3030

31-
[video_transforms.py](videotransforms/video_transforms.py)
31+
[video_transforms.py](torchvideotransforms/video_transforms.py)
3232
- [x] Compose
3333
- [x] Resize
3434
- [x] CenterCrop
@@ -39,7 +39,7 @@ This should produce something like the top image (this is a dummy clip for now,
3939
- [x] ColorJitter (acts on brightness, saturation, contrast and hue, only on PIL Images for now)
4040
- [ ] RandomResizedCrop
4141

42-
[volume_transforms.py](videotransforms/volume_transforms.py)
42+
[volume_transforms.py](torchvideotransforms/volume_transforms.py)
4343
- [x] ClipToTensor
4444

4545

@@ -56,7 +56,7 @@ export PYTHONPATH=$PYTHONPATH:path/to/torch_videovision
5656

5757
## In your python script
5858
```python
59-
from videotransforms import video_transforms, volume_transforms
59+
from torchvideotransforms import video_transforms, volume_transforms
6060

6161
video_transform_list = [video_transforms.RandomRotation(30),
6262
video_transforms.RandomCrop((200, 200))

setup.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import setuptools
2+
3+
with open("README.md", "r") as fh:
4+
long_description = fh.read()
5+
6+
setuptools.setup(
7+
name="torchvideotransforms",
8+
version="0.1.2",
9+
author="Yana Hasson",
10+
# author_email="author@example.com",
11+
description="A small example package",
12+
long_description=long_description,
13+
long_description_content_type="text/markdown",
14+
url="https://github.com/hassony2/torch_videovision",
15+
packages=setuptools.find_packages(),
16+
classifiers=[
17+
"Programming Language :: Python :: 3",
18+
"License :: OSI Approved :: MIT License",
19+
"Operating System :: OS Independent",
20+
"Development Status :: 2 - Pre-Alpha",
21+
],
22+
install_requires=[
23+
'torch',
24+
'torchvision',
25+
'scikit-image',
26+
],
27+
python_requires='>=3.6',
28+
)

testransforms.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import argparse
2-
import os
32

43
from matplotlib import pyplot as plt
5-
import numpy as np
64
from PIL import Image
75

8-
from videotransforms.video_transforms import Compose, Resize, RandomCrop, RandomRotation, ColorJitter, Normalize
9-
from videotransforms.volume_transforms import ClipToTensor
6+
from torchvideotransforms.video_transforms import Compose, Resize, RandomCrop, RandomRotation, ColorJitter, Normalize
7+
from torchvideotransforms.volume_transforms import ClipToTensor
108

119
img_path = 'data/cat/cat1.jpeg'
1210

@@ -44,7 +42,7 @@
4442
RandomCrop(crop_size),
4543
ColorJitter(args.brightness, args.contrast, args.saturation, args.hue),
4644
ClipToTensor(channel_nb=channel_nb),
47-
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
45+
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
4846
]
4947
video_transform = Compose(video_transform_list)
5048

torchvideotransforms/__init__.py

Whitespace-only changes.

videotransforms/functional.py torchvideotransforms/functional.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import cv2
44
import numpy as np
55
import PIL
6-
from skimage.transform import resize
6+
77

88
def _is_tensor_clip(clip):
99
return torch.is_tensor(clip) and clip.ndimension() == 4
1010

1111

12-
1312
def crop_clip(clip, min_h, min_w, h, w):
1413
if isinstance(clip[0], np.ndarray):
1514
cropped = [img[min_h:min_h + h, min_w:min_w + w, :] for img in clip]
@@ -65,7 +64,6 @@ def resize_clip(clip, size, interpolation='bilinear'):
6564
return scaled
6665

6766

68-
6967
def get_resize_sizes(im_h, im_w, size):
7068
if im_w < im_h:
7169
ow = size
@@ -75,6 +73,7 @@ def get_resize_sizes(im_h, im_w, size):
7573
ow = int(size * im_w / im_h)
7674
return oh, ow
7775

76+
7877
def normalize(clip, mean, std, inplace=False):
7978
if not _is_tensor_clip(clip):
8079
raise TypeError('tensor is not a torch clip.')

videotransforms/stack_transforms.py torchvideotransforms/stack_transforms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import PIL
33
import torch
44

5-
from videotransforms.utils import images as imageutils
5+
from .utils import images as imageutils
66

77

88
class ToStackedTensor(object):

videotransforms/tensor_transforms.py torchvideotransforms/tensor_transforms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import random
22

3-
from videotransforms.utils import functional as F
3+
from .utils import functional as F
44

55

66
class Normalize(object):

torchvideotransforms/utils/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

videotransforms/video_transforms.py torchvideotransforms/video_transforms.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import numbers
22
import random
3-
4-
import cv2
5-
from matplotlib import pyplot as plt
63
import numpy as np
74
import PIL
85
import skimage
9-
import torch
106
import torchvision
117

128
from . import functional as F

videotransforms/volume_transforms.py torchvideotransforms/volume_transforms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from PIL import Image
33
import torch
44

5-
from videotransforms.utils import images as imageutils
5+
from .utils import images as imageutils
66

77

88
class ClipToTensor(object):

0 commit comments

Comments
 (0)