#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tensorflow as tf
from tensorflow.keras import layers

print(tf.VERSION)
print(tf.keras.__version__)


model = tf.keras.Sequential()
# Adds a densely-connected layer with 64 units to the model:
model.add(layers.Conv2D(32, (3,3), activation='relu', input_shape=(32,32,1)))
model.add(layers.MaxPool2D())
model.add(layers.Conv2D(32, (3,3), activation='relu'))
model.add(layers.MaxPool2D())
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
# Add another:
model.add(layers.Dense(64, activation='relu'))
# Add a softmax layer with 10 output units:
model.add(layers.Dense(10, activation='softmax'))

model.compile(optimizer=tf.train.AdamOptimizer(0.001),
              loss='categorical_crossentropy',
              metrics=['accuracy'])

# Configure a model for mean-squared error regression.
model.compile(optimizer=tf.train.AdamOptimizer(0.01),
              loss='mse',       # mean squared error
              metrics=['mae'])  # mean absolute error

import numpy as np


# question how to get these in the same format as the 
data = np.random.random((1000, 32, 32, 1))
labels = np.random.random((1000, 10))

val_data = np.random.random((100, 32, 32, 1))
val_labels = np.random.random((100, 10))

model.fit(data, labels, epochs=10, batch_size=32,
          validation_data=(val_data, val_labels))


keras_file = "output/bare_image_model.h5"
tf.keras.models.save_model(model, keras_file)

# Convert to TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_keras_model_file(keras_file)
tflite_model = converter.convert()
open("output/bare_img_conv.tflite", "wb").write(tflite_model)

converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_model = converter.convert()
open("output/bare_img_conv_opt.tflite", "wb").write(tflite_model)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tensorflow as tf
from tensorflow.keras import layers

print(tf.VERSION)
print(tf.keras.__version__)


model = tf.keras.Sequential()
# Adds a densely-connected layer with 64 units to the model:
model.add(layers.Conv2D(32, (3,3), activation='relu', input_shape=(32,32,1)))
model.add(layers.MaxPool2D())
model.add(layers.Conv2D(32, (3,3), activation='relu'))
model.add(layers.MaxPool2D())
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
# Add another:
model.add(layers.Dense(64, activation='relu'))
# Add a softmax layer with 10 output units:
model.add(layers.Dense(10, activation='softmax'))

model.compile(optimizer=tf.train.AdamOptimizer(0.001),
              loss='categorical_crossentropy',
              metrics=['accuracy'])

# Configure a model for mean-squared error regression.
model.compile(optimizer=tf.train.AdamOptimizer(0.01),
              loss='mse',       # mean squared error
              metrics=['mae'])  # mean absolute error

import numpy as np


# question how to get these in the same format as the 
data = np.random.random((1000, 32, 32, 1))
labels = np.random.random((1000, 10))

val_data = np.random.random((100, 32, 32, 1))
val_labels = np.random.random((100, 10))

model.fit(data, labels, epochs=10, batch_size=32,
          validation_data=(val_data, val_labels))


keras_file = "output/bare_image_model.h5"
tf.keras.models.save_model(model, keras_file)

# Convert to TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_keras_model_file(keras_file)
tflite_model = converter.convert()
open("output/bare_img_conv.tflite", "wb").write(tflite_model)

converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_model = converter.convert()
open("output/bare_img_conv_opt.tflite", "wb").write(tflite_model)

#!/usr/bin/env python # -*- coding: utf-8 -*- # Adds a densely-connected layer with 64 units to the model: # Add another: # Add a softmax layer with 10 output units: # Configure a model for mean-squared error regression. # mean squared error # mean absolute error # question how to get these in the same format as the # Convert to TensorFlow Lite model.