This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torchvision.transforms as transforms | |
from torch.utils.data import Dataset, DataLoader | |
#data augmentation | |
train_transforms = transforms.Compose([ | |
#transforms.ToPILImage(), | |
transforms.RandomHorizontalFlip(), | |
transforms.RandomRotation(10), | |
transforms.RandomResizedCrop(224), | |
transforms.ToTensor(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image = Image.open('/content/gdrive/MyDrive/ComputerVisionEngineer/images/deadstar.jpg') | |
cropped = image.crop((200,200,400,400)) | |
cropped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image = Image.open('/content/gdrive/MyDrive/ComputerVisionEngineer/images/deadstar.jpg') | |
#plot original image | |
f = pyplot.figure(figsize=(30,30)) | |
f.add_subplot(131) | |
pyplot.imshow(image) | |
#45 degrees rotation | |
f.add_subplot(132) | |
pyplot.imshow(image.rotate(45)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image = Image.open('/content/gdrive/MyDrive/ComputerVisionEngineer/images/deadstar.jpg') | |
#horizontal flip | |
hor_flip = image.transpose(Image.FLIP_LEFT_RIGHT) | |
#vertical flip | |
ver_flip = image.transpose(Image.FLIP_TOP_BOTTOM) | |
#plot all three using matplotlib | |
f = pyplot.figure(figsize=(30,30)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image = Image.open('/content/gdrive/MyDrive/ComputerVisionEngineer/images/deadstar.jpg') | |
print(image.size) | |
#resize image and ignore original aspect ratio | |
img_resized = image.resize((400,400)) | |
print(img_resized.size) | |
img_resized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create thumbnail of an image | |
image = Image.open('/content/gdrive/MyDrive/ComputerVisionEngineer/images/deadstar.jpg') | |
#report size | |
print(image.size) | |
#create thumbnail and preserve aspect ratio | |
image.thumbnail((400,400)) | |
#print size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
from matplotlib import pyplot | |
#load image | |
image = Image.open('/content/gdrive/MyDrive/ComputerVisionEngineer/images/deadstar.jpg') | |
#summarize some details about the image | |
print(image.format) | |
print(image.mode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#splitting the dataset.csv file into train , test splits and saving them as csv files | |
from sklearn.model_selection import train_test_split | |
dataset_df = pd.read_csv(r'/content/gdrive/My Drive/Malaria/dataset.csv') | |
train,test = train_test_split(dataset_df, test_size=0.1) | |
train.to_csv(r'gdrive/My Drive/Malaria/train.csv', index=False) | |
test.to_csv(r'gdrive/My Drive/Malaria/test.csv', index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for param in model.parameters(): | |
param.requires_grad = False | |
from collections import OrderedDict | |
classifier = nn.Sequential(OrderedDict([ | |
('fc1', nn.Linear(25088, 4096)), | |
('relu1', nn.ReLU()), | |
('drop1', nn.Dropout(p=0.5)), | |
('fc2', nn.Linear(4096, 4096)), | |
('relu2', nn.ReLU()), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#data augmentation | |
train_transforms = transforms.Compose([ | |
#transforms.ToPILImage(), | |
transforms.RandomHorizontalFlip(), | |
transforms.RandomRotation(10), | |
transforms.RandomResizedCrop(224), | |
transforms.ToTensor(), | |
transforms.Normalize([0.485, 0.456, 0.406], | |
[0.229, 0.224, 0.225])]) |
NewerOlder