-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathTask_5.py
More file actions
52 lines (37 loc) · 1.33 KB
/
Task_5.py
File metadata and controls
52 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#Task 5
#Run these codes in colab
#--------------------------------------------------------------------------------
import os
os.chdir('/content/drive/My Drive/Colab Notebooks')
print(os.getcwd())
#--------------------------------------------------------------------------------
#upload an image in the following directory in your google drive
path = "/content/drive/My Drive/Colab Notebooks/photo.jpg"
#--------------------------------------------------------------------------------
import torch
from PIL import Image
from torchvision import transforms
import torchvision.transforms.functional as F
transform = transforms.Compose([
transforms.Resize(300),
transforms.CenterCrop(200),
transforms.ColorJitter(brightness=0.5, contrast=0.5, saturation=0.5, hue=0.5),
transforms.RandomRotation((-60,60), resample=False, expand=False, center=None, fill=None),
transforms.RandomHorizontalFlip(),
transforms.RandomVerticalFlip(),
transforms.ToTensor(),
transforms.Normalize(
(0.5, 0.5, 0.5),
(0.5, 0.5, 0.5)
),
])
img=Image.open(path)
img = transform(img)
a = F.to_pil_image(img)
b = F.to_grayscale(a, num_output_channels=1)
#--------------------------------------------------------------------------------
#a.show()
a
#--------------------------------------------------------------------------------
#b.show()
b