Skip to content

Instantly share code, notes, and snippets.

View SkalskiP's full-sized avatar
👨‍💻
I open-source stuff

Piotr Skalski SkalskiP

👨‍💻
I open-source stuff
View GitHub Profile
# Auxiliary function creating graph of classification boundaries
def save_model_prediction_graph(epoch, logs):
prediction_probs = model.predict_proba(grid_2d, batch_size=32, verbose=0)
plt.figure(figsize=(10,10))
sns.set_style("whitegrid")
plt.title('Binary classification with KERAS - epoch: ' + makeIndexOfLength(epoch, 3), fontsize=20)
plt.xlabel('X', fontsize=15)
plt.ylabel('Y', fontsize=15)
plt.contourf(X, Y, prediction_probs.reshape(100, 100), alpha = 0.7, cmap=cm.Spectral)
plt.scatter(X_train[:, 0], X_train[:, 1], c=y_train.ravel(), s=50, cmap=plt.cm.Spectral, edgecolors='black')
@SkalskiP
SkalskiP / create_gif.sh
Created September 13, 2018 21:38
Creating gif from set of images
convert -delay 10 -loop 0 *.png keras_class_boundaries.gif
@SkalskiP
SkalskiP / lorenz_animation_save.py
Last active September 13, 2018 18:40
Saving animations
# Animation creation
anim = FuncAnimation(fig, update,
frames=np.arange(0, int(STEPS/STEPS_PER_FRAME)), interval=40)
# Saving animation
anim.save('lorenz_attractor.gif', dpi=80, writer='imagemagick')
@SkalskiP
SkalskiP / lorenz_animation_update.py
Last active February 23, 2019 11:30
Updating the chart
# Updating chart
def update(i):
frame_end = (i + 1) * STEPS_PER_FRAME
for plot, dot, data in zip(plots, dots, plots_data):
xs, ys, zs = data
# Updating the trajectory
plot.set_data(xs[:frame_end], ys[:frame_end])
plot.set_3d_properties(zs[:frame_end])
# Updating the position of dots
dot._offsets3d = ([xs[frame_end]], [ys[frame_end]], [zs[frame_end]])
@SkalskiP
SkalskiP / lorenz_animation_init.py
Created September 13, 2018 18:12
Animation initiation process
# Calculation of the points belonging to the three trajectories,
# based on the given starting conditions
plots_data = [build_lorenz_trajectory(DELTA_T, STEPS,
initial_values=initial_conditions[i]) for i in range(3)]
# Creation of an empty chart
fig, ax = create_blank_chart_with_styling(plots_data, PADDING, (8, 8))
# Setting up (for the time being empty) data sequences for each trajectory
plots = [ax.plot([],[],[], color=colors[i], label=str(initial_conditions[i]),
@SkalskiP
SkalskiP / lorenz_animation_imports.py
Last active September 13, 2018 18:36
Libraries that have to be imported to create 3D animation using matplotlib.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from matplotlib.animation import FuncAnimation
@SkalskiP
SkalskiP / create_frames.py
Created September 9, 2018 22:16
Function to create animation frames
def create_frames(dt, steps, padding, output_dir):
fig, ax = create_blank_chart_with_styling((6, 6))
# creation of data describing the trajectory
xs, ys, zs = build_lorenz_trajectory(dt, steps)
# setting the fixed range of axes
ax.set_xlim3d(xs.min() - padding, xs.max() + padding)
ax.set_ylim3d(ys.min() - padding, ys.max() + padding)
ax.set_zlim3d(zs.min() - padding, zs.max() + padding)
for i in range(steps-1):
@SkalskiP
SkalskiP / simple_nn.py
Created August 13, 2018 16:32
Simple KERAS neural network for binary classification
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(4, input_dim=2,activation='relu'))
model.add(Dense(6, activation='relu'))
model.add(Dense(6, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
@SkalskiP
SkalskiP / first_model_layer.py
Created May 16, 2018 17:30
parameters of the first layer in Keras Mnist model
model.add(Conv2D(
filters = 32,
kernel_size = (5,5),
padding = 'Same',
activation ='relu',
input_shape = (28,28,1)
))
@SkalskiP
SkalskiP / adding_tensorflow.html
Created May 16, 2018 16:33
adding tensorflow/tfjs to your project
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script>