Last active
January 21, 2022 09:45
-
-
Save taznica/626952bbf6f67d5536039aa9214bdf04 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import tensorflow as tf | |
import numpy as np | |
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
def load_data(): | |
dataframe = pd.read_csv('data/z-pushed-210810.csv') | |
train_df, test_df = train_test_split(dataframe, test_size=0.2, shuffle=True) | |
y_train_df = train_df.pop('pushed') | |
y_test_df = test_df.pop('pushed') | |
x_train = train_df.values | |
y_train = y_train_df.values | |
x_test = test_df.values | |
y_test = y_test_df.values | |
return (x_train, y_train), (x_test, y_test) | |
(x_train, y_train), (x_test, y_test) = load_data() | |
print(x_train[0:5]) | |
print(y_train[0:5]) | |
model = tf.keras.models.Sequential() | |
model.add(tf.keras.layers.Dense(10, activation='relu', input_shape=[25])) | |
model.add(tf.keras.layers.Dense(20, activation='relu')) | |
model.add(tf.keras.layers.Dense(5, activation='relu')) | |
model.add(tf.keras.layers.Dense(1, activation='sigmoid')) | |
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=[tf.keras.metrics.BinaryAccuracy()]) | |
model.fit(x_train, y_train, epochs=100) | |
result = model.evaluate(x_test, y_test, return_dict=True) | |
print(result) | |
print(model.summary()) | |
converter = tf.lite.TFLiteConverter.from_keras_model(model) | |
converted_model = converter.convert() | |
with tf.io.gfile.GFile('model/ring_keras_model_210810.tflite', 'wb') as f: | |
f.write(converted_model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment