Skip to content

Instantly share code, notes, and snippets.

View syaffers's full-sized avatar

Syafiq Kamarul Azman syaffers

View GitHub Profile
@syaffers
syaffers / colors.json
Last active March 4, 2017 09:57
d3 categorical colors in HEX format
{
"category10": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#d62728",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
@syaffers
syaffers / get_keras_version_from_model.py
Created May 15, 2018 17:41
Get the version of Keras from a trained h5 file
import h5py
f = h5py.File('Model.h5', 'r')
print(f.attrs.get('keras_version'))
@syaffers
syaffers / headless-aiy-vision.md
Last active May 1, 2019 20:26
Headless AIY Vision Kit Setup from Raspbian Lite

Headless AIY Vision Kit Setup from Raspbian Lite

I faced some errors when trying to setup the AIY Vision kit using the Google AIY hacking docs. Here is my quick documentation of to allow for a smoother setup process from a blank Raspbian Lite image.

Pre-setup

If you have not already have an SD card with the Raspbian Lite image, do that now. Balena's Etcher is a good way to do this on most OSes. Now with the image burned, enable SSH headlessly by making an empty file called ssh in the boot directory on the SD card. If your Raspberry Pi has Wi-Fi capabilities, you may also want to create a wpa_supplicant.conf to enable wireless networking when the Raspberry Pi boots up for the first time.

Once you gain access to the Raspberry Pi via SSH, you may want to configure the Raspberry Pi by running sudo raspi-config to set a new password, correct time/date, keyboard layout, and minimize memory use on the GPU since we are not

@syaffers
syaffers / numbers-dataset-1.py
Last active May 15, 2019 07:13
The first iteration of the numbers dataset
from torch.utils.data import Dataset
class NumbersDataset(Dataset):
def __init__(self):
self.samples = list(range(1, 1001))
def __len__(self):
return len(self.samples)
def __getitem__(self, idx):
@syaffers
syaffers / numbers-dataset-2.py
Last active May 15, 2019 07:12
The second iteration of the numbers dataset with user-defined range
from torch.utils.data import Dataset
class NumbersDataset(Dataset):
def __init__(self, low, high):
self.samples = list(range(low, high))
def __len__(self):
return len(self.samples)
def __getitem__(self, idx):
@syaffers
syaffers / tes-names-dataset-1.py
Created May 15, 2019 07:02
The first iteration of the TES names dataset
import os
from torch.utils.data import Dataset
class TESNamesDataset(Dataset):
def __init__(self, data_root):
self.samples = []
for race in os.listdir(data_root):
race_folder = os.path.join(data_root, race)
@syaffers
syaffers / numbers-dataset-3.py
Last active August 4, 2020 03:38
The third iteration of the numbers dataset now with multiple data output types
from torch.utils.data import Dataset
import torch
class NumbersDataset(Dataset):
def __init__(self, low, high):
self.samples = list(range(low, high))
def __len__(self):
return len(self.samples)
@syaffers
syaffers / tes-names-dataset-2.py
Created May 15, 2019 07:19
The second iteration of the TES names dataset with major additions and updates
import os
from sklearn.preprocessing import LabelEncoder
from torch.utils.data import Dataset
import torch
class TESNamesDataset(Dataset):
def __init__(self, data_root, charset):
self.data_root = data_root
self.charset = charset
self.samples = []
@syaffers
syaffers / splitting-datasets.py
Created May 15, 2019 11:52
Create validation sets by splitting your custom PyTorch datasets easily
import string
from torch.utils.data import DataLoader, random_split
from datasets import TESNamesDataset
data_root = '/home/syafiq/Data/tes-names/'
charset = string.ascii_letters + "-' "
length = 30
dataset = TESNamesDataset(data_root, charset, length)
trainset, valset = random_split(dataset, [15593, 3898])
@syaffers
syaffers / AIYModelTrainer.ipynb
Last active May 21, 2019 08:00
Training a simple model in Keras for the AIY kit
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.