Skip to content

Instantly share code, notes, and snippets.

View ramcandrews's full-sized avatar
🏠
Working from home

Ryan McAndrews ramcandrews

🏠
Working from home
View GitHub Profile
@ramcandrews
ramcandrews / Google colab load data from google drive
Created February 17, 2020 06:30
Use this code in the top cell of your colab notebook to read data from google drive. It if you are loading thousands of image files or thousands of small files it is slower than just a few larger files.
from google.colab import drive
drive.mount('/content/drive/')
data_dir = '/content/drive/My Drive/Colab Notebooks/<your assets>/'
@ramcandrews
ramcandrews / pytorch_image_folder_with_file_paths.py
Created November 17, 2019 09:22 — forked from andrewjong/pytorch_image_folder_with_file_paths.py
PyTorch Image File Paths With Dataset Dataloader
import torch
from torchvision import datasets
class ImageFolderWithPaths(datasets.ImageFolder):
"""Custom dataset that includes image file paths. Extends
torchvision.datasets.ImageFolder
"""
# override the __getitem__ method. this is the method that dataloader calls
def __getitem__(self, index):
@ramcandrews
ramcandrews / iterate and pop dict.py
Last active September 27, 2019 06:14
Normally you can't remove items from a dictionary while you are iterating over it. But if you convert it to a list first, there are no problems.
origDict = {
'First name': 'Ryan',
'Last name': 'M',
'Subject': 'AI',
'task': 'Cleaning Data'
}
removedItem = origDict.pop('Last name') # this is normal usage of pop()
print(origDict)
print('value = ' + removedItem)