Skip to content

Instantly share code, notes, and snippets.

@danyashorokh
danyashorokh / [Keras] Training visualization
Created November 13, 2019 09:02
[Keras] Training visualization
# Plot training & validation accuracy values
plt.plot(results.history['iou_coef'])
plt.plot(results.history['val_iou_coef'])
plt.title('Model accuracy')
plt.ylabel('IOU')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.show()
# Plot training & validation loss values
@danyashorokh
danyashorokh / [Python] OpenCV histogram matching 2
Created June 28, 2019 11:44
[Python] OpenCV histogram matching 2
from skimage.exposure import cumulative_distribution
import numpy as np
def cdf(im):
'''
computes the CDF of an image im as 2D numpy ndarray
'''
c, b = cumulative_distribution(im)
# pad the beginning and ending pixels and their CDF values
@danyashorokh
danyashorokh / [Python] OpenCV histogram matching 2
Created June 28, 2019 11:44
[Python] OpenCV histogram matching 2
from skimage.exposure import cumulative_distribution
import numpy as np
def cdf(im):
'''
computes the CDF of an image im as 2D numpy ndarray
'''
c, b = cumulative_distribution(im)
# pad the beginning and ending pixels and their CDF values
@danyashorokh
danyashorokh / [Python] OpenCV histogram matching
Created June 28, 2019 09:21
[Python] OpenCV histogram matching
import numpy as np
def hist_match(source, template):
"""
Adjust the pixel values of a grayscale image such that its histogram
matches that of a target image
Arguments:
-----------
source: np.ndarray
@danyashorokh
danyashorokh / [Python] TF Keras CNN example
Last active June 28, 2019 08:26
[Python] TF Keras CNN example
import tensorflow as tf
from keras.models import Sequential
from tensorflow.keras.layers import (
Conv2D, MaxPooling2D, Flatten,
Dense, Dropout, Input
)
image_input = Input(shape=(100, 100, 3), name='input_layer')
conv_1 = Conv2D(8,
kernel_size=(3, 3),
@danyashorokh
danyashorokh / [Python][CV] Color filtering
Created May 31, 2019 09:45
[Python][CV] Color filtering
import cv2 as cv
import numpy as np
def nothing(x):
pass
# Color trackbars
@danyashorokh
danyashorokh / [Python] Variables types
Created April 1, 2019 06:18
[Python] Variables types
df1 = df.copy()
var_types = pd.DataFrame(df1.dtypes.index, columns = ['Variable'])
lst = []
for col in df1.columns:
try:
df1[col] = df1[col].astype(float)
lst.append(False)
except:
try:
@danyashorokh
danyashorokh / [Python] Colorized correlation
Created March 27, 2019 06:21
[Python] Colorized correlation
import pandas as pd
variables = []
rlst = []
for i in range(0, len(variables)):
clst = []
for j in range(0, len(variables)):
if i != j:
clst.append( round(df[variables[i]].corr(df[variables[j]]), 3))
@danyashorokh
danyashorokh / [Python] Interpolate & extrapolate
Created February 5, 2019 08:44
[Python] Interpolate & extrapolate
from scipy.optimize import curve_fit
# interpolate
df_int[field] = df[field].interpolate(method='piecewise_polynomial')
'''
'linear’, ‘time’, ‘index’, ‘values’, ‘nearest’, ‘zero’,
‘slinear’, ‘quadratic’, ‘cubic’, ‘barycentric’, ‘krogh’, ‘polynomial’, ‘spline’ ‘piecewise_polynomial’, ‘pchip’}
'''
@danyashorokh
danyashorokh / [Python] Plot all features
Created October 9, 2018 10:03
[Python] Plot all features
# %matplotlib inline
from matplotlib import pyplot as plt
plt.rcParams['figure.figsize'] = (10, 8)
fig = plt.figure(figsize=(25, 15))
cols = 5
rows = np.ceil(float(data_train.shape[1]) / cols)
for i, column in enumerate(data_train.columns):
ax = fig.add_subplot(rows, cols, i + 1)