Skip to content

Instantly share code, notes, and snippets.

View sailfish009's full-sized avatar

sailfish009

  • freelancer
  • South Korea
View GitHub Profile
@sailfish009
sailfish009 / streamlit_download_button.py
Created February 23, 2021 06:48 — forked from chad-m/streamlit_download_button.py
A download function and examples app for Streamlit
import base64
import os
import json
import pickle
import uuid
import re
import streamlit as st
import pandas as pd
@sailfish009
sailfish009 / color-scale.js
Created February 2, 2021 14:33 — forked from mlocati/color-scale.js
Javascript color scale from 0% to 100%, rendering it from red to yellow to green
function perc2color(perc) {
var r, g, b = 0;
if(perc < 50) {
r = 255;
g = Math.round(5.1 * perc);
}
else {
g = 255;
r = Math.round(510 - 5.10 * perc);
}
@sailfish009
sailfish009 / installing_nvidia_driver_cuda_cudnn_linux.md
Created December 1, 2020 01:12 — forked from kmhofmann/installing_nvidia_driver_cuda_cudnn_linux.md
Installing the NVIDIA driver, CUDA and cuDNN on Linux

Installing the NVIDIA driver, CUDA and cuDNN on Linux (Ubuntu 20.04)

This is a companion piece to my instructions on building TensorFlow from source. In particular, the aim is to install the following pieces of software

on an Ubuntu Linux system, in particular Ubuntu 20.04.

@sailfish009
sailfish009 / stratified_sample.py
Created November 22, 2020 15:26 — forked from srikarplus/stratified_sample.py
Stratified Sampling in Pytorch
def make_weights_for_balanced_classes(images, nclasses):
count = [0] * nclasses
for item in images:
count[item[1]] += 1
weight_per_class = [0.] * nclasses
N = float(sum(count))
for i in range(nclasses):
weight_per_class[i] = N/float(count[i])
weight = [0] * len(images)
for idx, val in enumerate(images):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sailfish009
sailfish009 / ralamb.py
Created June 26, 2020 15:11 — forked from redknightlois/ralamb.py
Ralamb optimizer (RAdam + LARS trick)
class Ralamb(Optimizer):
def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=0):
defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay)
self.buffer = [[None, None, None] for ind in range(10)]
super(Ralamb, self).__init__(params, defaults)
def __setstate__(self, state):
super(Ralamb, self).__setstate__(state)
@sailfish009
sailfish009 / torch_percentile.py
Created June 1, 2020 12:27 — forked from spezold/torch_percentile.py
Calculate percentile of a PyTorch tensor's values, similar to numpy.percentile
from typing import Union
import torch
import numpy as np
def percentile(t: torch.tensor, q: float) -> Union[int, float]:
"""
Return the ``q``-th percentile of the flattened input tensor's data.
@sailfish009
sailfish009 / parse_drugbank_xml.py
Created May 31, 2020 08:48 — forked from ravila4/parse_drugbank_xml.py
Python script for parsing an xml database dump from DrugBank for extracting Log P values
import xmltodict
import pandas as pd
with open("full_database.xml") as db:
doc = xmltodict.parse(db.read())
values = []
for item in doc['drugbank']['drug']:
logp = None
try:
@sailfish009
sailfish009 / main.py
Created May 30, 2020 05:41
create backgroud process
import os, time, sys, subprocess
if len(sys.argv) == 2:
time.sleep(5)
print 'track end'
if sys.platform == 'darwin':
subprocess.Popen(['say', 'hello'])
else:
print 'main begin'
subprocess.Popen(['python', os.path.realpath(__file__), '0'], close_fds=True)
@sailfish009
sailfish009 / processify.py
Created May 27, 2020 03:57 — forked from schlamar/processify.py
processify
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
Be sure that every argument and the return value