This file contains 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
# winpty fix | |
alias python='winpty python.exe' | |
alias pip='winpty pip' | |
# custom aliases | |
alias rt='reset' | |
alias ll='ls -la' | |
alias l='ls -1' | |
alias la='ls -a' |
This file contains 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
async function getImages(numbers) { | |
// fetch all at once, return fetch promises | |
const allResult = await Promise.all( | |
numbers.map((num) => fetch("url/to/img" + num)) | |
); | |
// iterate and return array of json promises | |
return Promise.all( | |
allResult.map((result) => { | |
if (result.ok) { |
This file contains 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 accuracy(input, target, thresh=0.4, na_idx=0): | |
valm, argm = input.max(-1) | |
# results below threshold are considered as "na" category | |
argm[valm < thresh] = na_idx | |
return (argm==target).float().mean() |
This file contains 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
# apply sigmoid and one-hot | |
input = input.sigmoid() | |
target = F.one_hot(target, input.shape[1]).float() | |
# change all target category “na” (placed at 0 index) to zero | |
target[:, 0] = 0 | |
# finally count bce loss | |
loss = F.binary_cross_entropy(input, target) |
This file contains 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
# borrowed from https://github.com/clcarwin/focal_loss_pytorch/blob/master/focalloss.py | |
# added "reduction" param for fastai | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
class FocalLoss(nn.Module): | |
def __init__(self, gamma=0.0, alpha=None, reduction='mean'): | |
super(FocalLoss, self).__init__() |
This file contains 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
import numpy as np | |
import pandas as pd | |
import cv2 | |
import os | |
import uuid | |
import argparse | |
from pathlib import Path | |
from google_images_download.google_images_download import googleimagesdownload |