Skip to content

Instantly share code, notes, and snippets.

View morawi's full-sized avatar
🎯
Focusing

Mohammed Al-Rawi morawi

🎯
Focusing
  • Trinity College Dublin
  • Dublin
View GitHub Profile
@morawi
morawi / test_sampler.py
Created February 18, 2021 13:49
Using/Tesgin PyTorch SubSetRandSampler
import torch
from torch.utils.data import SubsetRandomSampler as SubSetRandSampler
import torchvision.transforms as transforms
import torchvision.datasets as datasets
import matplotlib.pyplot as plt
my_sampler_size = 5000 # I'm going to randomly sample 5000 items from the dataset
# Why using this instead of shuffle? Because I want to get less samples than the whole dataset
# would using an if statement inside the validation function be good ... something like if i>my_sampler_size: break
@morawi
morawi / Multi-label pair-wise distance accepting ground truth labels as input
Created March 12, 2019 14:24
The purpose of this implemention is to find the correctly identified samples from predictions made with some AI/ML model. The incorrect labels can also be found. The function accepts three inputs; the predictions, the ground truth and their labels. It implements a pair-wise distance metric to find the proximity, based on the minimum distance, be…
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 27 18:36:33 2019
@author: malrawi
"""
import numpy as np
from collections import Counter
@morawi
morawi / Multilabel pair-wise distance accepting ground truth labels as input
Created March 12, 2019 14:21
The purpose of this implemention is to find the correctly identified samples from predictions made with some AI/ML model. The incorrect labels can also be found. The function accepts three inputs; the predictions, the ground truth and their labels. It implements a pair-wise distance metric to find the proximity, based on the minimum distance, be…
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 27 18:36:33 2019
@author: malrawi
"""
import numpy as np
from collections import Counter
@morawi
morawi / im_pil_power.txt
Created January 31, 2019 14:29
Arithmetic operations on PIL images
from PIL import Image
img = Image.open("bride.jpg")
img.show()
img = Image.eval(img, lambda px: (px**2) % 255) # f = f^2 % 255
img.show()
@morawi
morawi / Stich_images.py
Last active October 5, 2018 15:51
Stitching an arbitrary number of images into one with PIL/Pillow and PyTorch
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 5 11:29:33 2018
@author: malrawi
"""
import torchvision
from PIL import Image