Skip to content

Instantly share code, notes, and snippets.

View davidnvq's full-sized avatar
🎯
Focusing

Van-Quang Nguyen davidnvq

🎯
Focusing
View GitHub Profile
@davidnvq
davidnvq / one_hot_multi_label_encoding.py
Created April 24, 2018 01:27
Convert multi-labels of an instance to one-hot encoding.
import numpy as np
n_classes = 10
class_matrix = np.eye(n_classes)
"""
class_matrix should be obtained as below:
array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
@davidnvq
davidnvq / image_channel_order_cvt.py
Last active April 23, 2018 05:31
Converting RGB to BGR for image data
import numpy as np
"""
In this gist, I demonstrate the simple ways to
convert between 2 colorspace representation of images
mutually(RGB, BGR).
"""
CONVERSION_ORDER = [2, 1, 0]
def convert_channel(img):
@davidnvq
davidnvq / chunk_data_train.py
Created March 22, 2018 06:47
Training a Chunk of data
datagen = ImageDataGenerator(
featurewise_center=True, # set input mean to 0 over the dataset
samplewise_center=False, # set each sample mean to 0
featurewise_std_normalization=True, # divide inputs by std of the dataset
samplewise_std_normalization=False, # divide each input by its std
zca_whitening=False, # apply ZCA whitening
rotation_range=20, # randomly rotate images in the range (degrees, 0 to 180)
width_shift_range=0.2, # randomly shift images horizontally (fraction of total width)
height_shift_range=0.2, # randomly shift images vertically (fraction of total height)
horizontal_flip=True, # randomly flip images
from keras.preprocessing.image import ImageDataGenerator,standardize,random_transform
# input generator with standardization on
datagenX = ImageDataGenerator(
featurewise_center=True,
featurewise_std_normalization=True,
featurewise_standardize_axis=(0, 2, 3),
rotation_range=180,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
@davidnvq
davidnvq / image_generator.py
Created March 21, 2018 06:42
Image Generator in Keras
https://keras.io/preprocessing/image/
@davidnvq
davidnvq / libstdc++6.sh
Last active March 21, 2018 02:16
Error of not found libstdc++6 in virtual environment
#1. Install libstdc++6
sudo apt-get install libstdc++6
#2. Copy to envs/tensorflow/bin/../lib/
cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /home/username/anaconda/envs/tensorflow/bin/../lib/
@davidnvq
davidnvq / keras_hdf5.py
Created March 21, 2018 01:48
Example of Keras HDF5 matrix
from keras.models import Sequential
from keras.layers import Dense
from keras.utils.io_utils import HDF5Matrix
import numpy as np
def create_dataset():
import h5py
X = np.random.randn(200,10).astype('float32')
y = np.random.randint(0, 2, size=(200,1))
f = h5py.File('test.h5', 'w')
@davidnvq
davidnvq / matplotlib.pyplot.sh
Created March 20, 2018 11:04
Error warning: Duplicate key
Warning message: Duplicate key in file "/home/username/.matplotlib/matplotlibrc", line #2
>>> Solution:
Just go to the file "/home/username/.matplotlib/matplotlibrc" and
Remove the duplicate key
@davidnvq
davidnvq / ssh_key.sh
Last active March 9, 2018 06:56
Generate a SSH-key
ssh-keygen - t rsa
@davidnvq
davidnvq / conda_mac.sh
Created March 7, 2018 09:48
Install anaconda on MacOS
## Download file from the url
https://www.anaconda.com/download/#macos
## Run the graphical installer
## Install Tensorflow version 1.6
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.6.0-py3-none-any.whl
## Install Keras
pip install keras