This file contains hidden or 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 typing import List | |
from uuid import UUID | |
from sqlalchemy import create_engine | |
from sqlalchemy.orm import Session, sessionmaker | |
from fastapi import FastAPI, Depends, HTTPException | |
from sqlalchemy.orm import Session | |
from pydantic import BaseModel | |
class User(BaseModel): | |
# This is a DB model - in SQLModel you can return the ORM model directly bc it's Pydantic under the hood |
This file contains hidden or 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
n_searches = 20 | |
n_epochs = 15 | |
n_val = 500 | |
for train_size in dataset_size: | |
print('Training with subset %1.4f, which is %d images'%(train_size, train_size*total_train)) | |
test_acc[train_size] = [] | |
test_loss[train_size] = [] | |
val_acc[train_size] = [] |
This file contains hidden or 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
def random_hyperparamters(): | |
""" Returns randomly drawn hyperparamters for our CNN" | |
hyperparam_dict = {} | |
hyperparam_dict['lr'] = 10 ** np.random.uniform(-6, -1) | |
hyperparam_dict['weight_decay'] = 10 ** np.random.uniform(-6, -3) | |
hyperparam_dict['momentum'] = 10 ** np.random.uniform(-1, 0) | |
hyperparam_dict['conv1_size'] = int(np.random.uniform(10,100)) |
This file contains hidden or 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
test_acc = {} | |
val_acc = {} | |
train_acc = {} | |
test_loss = {} | |
for train_size in dataset_size: | |
print('Training with subset %1.4f, which is %d images'%(train_size, train_size*total_train)) | |
net = Net() | |
# Train model with an early stopping criterion - terminates after 4 epochs of non-improving val loss | |
net, loss_list, val_list = train_model(net, trainset_loaders[train_size], valloader, 1000, n_epochs=10) |
This file contains hidden or 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
def get_dataset_size(start=0.5, end=100, base=2): | |
""" Returns exponentially distributed dataset size vector""" | |
dataset_size=[start] | |
while True: | |
dataset_size.append(dataset_size[-1]*base) | |
if dataset_size[-1] > end: | |
dataset_size[-1] = end | |
break | |
return dataset_size |
This file contains hidden or 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
class Net(nn.Module): | |
""" A simple 5 layer CNN, configurable by passing a hyperparameter dictionary at initialization. | |
Based upon the one outlined in the Pytorch intro tutorial | |
(http://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html#define-the-network) | |
""" | |
def __init__(self, hyperparam_dict=None): | |
super(Net, self).__init__() | |
if not hyperparam_dict : |