This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflowjs as tfjs | |
# creating and training of model using Keras | |
# ... | |
tfjs.converters.save_keras_model(model, './ModelJS') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tensorflowjs_converter --input_format keras ./ModelPY/model.h5 ./../ModelJS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as tf from '@tensorflow/tfjs'; | |
// Definition of the component supporting the model | |
// ... | |
protected async loadModel() { | |
this.model = await tf.loadModel(AppSettings.mnistModelUrl); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected async predict(imageData: ImageData) { | |
const pred = await tf.tidy(() => { | |
let img:any = tf.fromPixels(imageData, 1); | |
img = img.reshape([1, 28, 28, 1]); | |
img = tf.cast(img, 'float32'); | |
const output = this.model.predict(img) as any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.add(Conv2D( | |
filters = 32, | |
kernel_size = (5,5), | |
padding = 'Same', | |
activation ='relu', | |
input_shape = (28,28,1) | |
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
import numpy as np | |
from matplotlib.animation import FuncAnimation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]), |
OlderNewer