Skip to content

Instantly share code, notes, and snippets.

View CLozy's full-sized avatar
🦄
Focusing

Charleenlozi CLozy

🦄
Focusing
View GitHub Profile
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(),
@CLozy
CLozy / img_crop.py
Created July 12, 2022 09:04
cropping
image = Image.open('/content/gdrive/MyDrive/ComputerVisionEngineer/images/deadstar.jpg')
cropped = image.crop((200,200,400,400))
cropped
@CLozy
CLozy / img_rotate.py
Last active July 12, 2022 12:21
rotate image
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))
@CLozy
CLozy / img_flip.py
Last active July 12, 2022 12:12
flipping image
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))
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
@CLozy
CLozy / img_resize.py
Last active July 12, 2022 11:53
resizing image
#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
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)
@CLozy
CLozy / spilt.py
Created October 19, 2021 17:58
spilliting dataset to train and test set
#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)
@CLozy
CLozy / class.py
Created October 13, 2021 13:40
classifier
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()),
@CLozy
CLozy / data_aug.py
Created October 13, 2021 10:12
dataaugmentation
#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])])