fdlksajflkds fafja jklfdasjflkds jfklajfds
really??
## 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 |
response = { | |
while(1){ | |
let response = await $.ajax({ | |
url: `${server_url}/data`, | |
contentType: 'application/json', | |
type: 'GET' | |
}); | |
yield Promises.delay(6000, response); | |
} | |
} |
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 |
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)) | |
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), |
# 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) |
# 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 |
""" | |
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 |