Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

What would this look like

fdlksajflkds fafja jklfdasjflkds jfklajfds

Looks like we will find out

I Think it looks pretty good

really??

@burrussmp
burrussmp / GoogleColabServer.py
Created July 11, 2020 21:37
A python flask server that runs in the background and can be used in a Google Colab environment
## imports
import flask
from flask import Flask
from flask_cors import CORS
from flask_ngrok import run_with_ngrok
import threading
import trace
import sys
import time
@burrussmp
burrussmp / ObservableAjaxCall.js
Created July 11, 2020 03:16
Javascript Ajax Call to Get Data in Observable
response = {
while(1){
let response = await $.ajax({
url: `${server_url}/data`,
contentType: 'application/json',
type: 'GET'
});
yield Promises.delay(6000, response);
}
}
@burrussmp
burrussmp / GaussianMixtureModel.py
Created June 13, 2020 20:00
Example of EM Maximization using Gaussian Mixture Model for Unsupervised Segmentation of Image
import cv2
import numpy as np
from sklearn.mixture import GaussianMixture
def preprocess(x):
return (x - x.mean(axis=(0,1,2), keepdims=True)) / x.std(axis=(0,1,2), keepdims=True)
# EM hyper parameters
epsilon = 1e-4 # stopping criterion
R = 10 # number of re-runs
@burrussmp
burrussmp / testUNetSegmentation.py
Created May 5, 2020 20:49
Test segmentation model (U-Net) using the dice coefficient and return the average, median, and standard deviation dice scores. The close to 1 the average dice score, the better the model.
def dice_loss(input, target):
smooth = 1.
iflat = input.view(-1)
tflat = target.view(-1)
intersection = (iflat * tflat).sum()
return 1 - ((2. * intersection + smooth) /
(iflat.sum() + tflat.sum() + smooth))
@burrussmp
burrussmp / UNet.py
Created May 5, 2020 20:24
Define and load UNet into the GPU
class DoubleConv2D(nn.Module):
"""(convolution => [BN] => ReLU) * 2"""
def __init__(self, in_channels, out_channels):
super().__init__()
self.double_conv = nn.Sequential(
nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1),
nn.BatchNorm2d(out_channels),
nn.ReLU(inplace=True),
nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1),
@burrussmp
burrussmp / TrainMode.py
Created May 5, 2020 20:16
Train a model in Pytorch.
# hyper-parameters
batch_size = 32
learning_rate = 0.001
scheduler_step = 30
epochs = 190
gamma = 0.5
lr_scheduler_step_size = 12
adam_betas = (0.9,0.999)
use_cuda = torch.cuda.is_available()
torch.manual_seed(123456)
@burrussmp
burrussmp / train.py
Created May 5, 2020 19:55
Training and validation for annotation segmentation network
# used to penalize the model less when it predicts a 0 to account for
# slight frequency issues in the training space i.e. imbalances of label 0 and other labels
weights = np.ones(27)
weights[0] = 0.25
class_weights = torch.FloatTensor(weights).cuda()
"""
Function to train model for a single epoch
@params
model: PyTorch.nn.Module
@burrussmp
burrussmp / PytorchDataLoader.py
Last active May 5, 2020 19:08
An example of a PyTorch Data Loader that uses ListDataset and a load_data function.
"""
Helper function for the Pytorch data loader
@params
type: string
Specifies if training (train), validation (valid), or testing (test) list
should be generated
@return
mlist: A nested Python list
A list of number of input-output pairs where each element is a list of size 2
The first element is the path to the .npy input file and the second element is