Skip to content

Instantly share code, notes, and snippets.

View steven-mi's full-sized avatar
🍗
Eating

Steven steven-mi

🍗
Eating
View GitHub Profile
@steven-mi
steven-mi / wikidownloader.py
Created October 5, 2020 17:09
script for downloading wikipedia cropus as txt file
# from https://towardsdatascience.com/train-gpt-2-in-your-own-language-fc6ad4d60171
import tensorflow as tf
from gensim.corpora import WikiCorpus
import os
import argparse
def store(corpus, lang):
base_path = os.getcwd()
store_path = os.path.join(base_path, '{}_corpus'.format(lang))
@steven-mi
steven-mi / download-cityscapes.md
Created October 3, 2020 19:48
download cityscapes from terminal

How to download cityscapes dataset via terminal

To download the dataset the server check the authentication information of the cookie and confirm that the server is an authenticated user

Step 1. User authentication

Since it is authentication using cookie, it is necessary to acquire cookie first. This can also be done with wget! The command is as follows.

wget --keep-session-cookies --save-cookies=cookies.txt --post-data 'username=YOUR_EMAIL&password=YOUR_PASSWORD&submit=Login' https://www.cityscapes-dataset.com/login/; history -d $((HISTCMD-1))
@steven-mi
steven-mi / Inference.java
Created October 3, 2020 09:44
Running a SavedModel in Java
package org.example;
import org.tensorflow.SavedModelBundle;
import org.tensorflow.Tensor;
import org.tensorflow.ndarray.IntNdArray;
import org.tensorflow.ndarray.NdArrays;
import org.tensorflow.ndarray.Shape;
import org.tensorflow.proto.framework.SignatureDef;
import org.tensorflow.types.TInt32;
@steven-mi
steven-mi / format-python-scripts.sh
Created August 26, 2020 17:55
format all python scripts in a certain directory
#!/bin/bash
pip install autopep8
for filename in ./dags/*.py; do
echo $filename
autopep8 -i $filename
done
@steven-mi
steven-mi / gist:8bc4d685597a10b0b3e9809474d9c2c7
Created October 15, 2019 08:38
pyplot for loop without index
plt.figure(figsize=(20, 20))
num_classes = 10
for c in range(num_classes):
# Select samples_per_class random keys of the labels == current class
keys = np.random.choice(np.where(label == c)[0], examples_each_row)
images = data[keys]
labels = label[keys]
for i in range(examples_each_row):
f = plt.subplot(examples_each_row, num_classes, i * num_classes + c + 1)

How to install virtualenv:

Install pip first

sudo apt-get install python3-pip

Then install virtualenv using pip3

sudo pip3 install virtualenv 
@steven-mi
steven-mi / docker.md
Created April 23, 2019 13:00
docker cheatsheet

remove Docker container

docker rm tf

stop the container

docker stop tf
export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_9_HOME=$(/usr/libexec/java_home -v9)
alias java7='export JAVA_HOME=$JAVA_7_HOME'
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java9='export JAVA_HOME=$JAVA_9_HOME'
#default java8
export JAVA_HOME=$JAVA_8_HOME
@steven-mi
steven-mi / pyplot_loop.py
Created April 16, 2019 07:42
plotting a pyplot in a for loop
import matplotlib.pyplot as plt
# plot 0 plot 1 plot 2 plot 3
x=[[1,2,3,4],[1,4,3,4],[1,2,3,4],[9,8,7,4]]
y=[[3,2,3,4],[3,6,3,4],[6,7,8,9],[3,2,2,4]]
plots = zip(x,y)
figs={}
axs={}
for idx,plot in enumerate(plots):
figs[idx]=plt.figure()
@steven-mi
steven-mi / layers.py
Created April 13, 2019 18:03
tensorflow conv layer with activation function and bn
import tensorflow as tf
def get_weight(shape, name, trainable=True):
#initial = tf.random_uniform(shape, minval=-0.1, maxval = 0.1)
initial = tf.contrib.layers.xavier_initializer()(shape)
return tf.Variable(initial, trainable=trainable, name=name+'_W', dtype=tf.float32)
def get_bias(shape, name, trainable=True):
"""
filter_height, filter_width, in_channels, out_channels]