notes, debug
parent
83fbb7d6d9
commit
6cef79c5ac
62
wut-ml
62
wut-ml
|
@ -26,7 +26,22 @@ from tensorflow.python.keras.models import load_model
|
|||
from tensorflow.python.keras.preprocessing.image import load_img
|
||||
from tensorflow.python.keras.preprocessing.image import img_to_array
|
||||
|
||||
# XXX
|
||||
from tensorflow.python.keras.models import Model
|
||||
from tensorflow.python.keras.layers import Input, concatenate
|
||||
#from tensorflow.python.keras.optimizers import Adam
|
||||
|
||||
|
||||
# XXX Plot
|
||||
from tensorflow.python.keras.utils import plot_model
|
||||
from tensorflow.python.keras.callbacks import ModelCheckpoint
|
||||
## for visualizing
|
||||
import matplotlib.pyplot as plt, numpy as np
|
||||
from sklearn.decomposition import PCA
|
||||
|
||||
# https://keras.io/preprocessing/image/
|
||||
# TODO:
|
||||
# * Pre-process image
|
||||
print("datagen")
|
||||
datagen = ImageDataGenerator(
|
||||
featurewise_center=False,
|
||||
|
@ -56,9 +71,19 @@ print("datagen.flow")
|
|||
train_it = datagen.flow_from_directory('data/train/', class_mode='binary')
|
||||
val_it = datagen.flow_from_directory('data/val/', class_mode='binary')
|
||||
test_it = datagen.flow_from_directory('data/test/', class_mode='binary')
|
||||
|
||||
print("train_it.next()")
|
||||
batchX, batchy = train_it.next()
|
||||
print('Batch shape=%s, min=%.3f, max=%.3f' % (batchX.shape, batchX.min(), batchX.max()))
|
||||
trainX, trainY = train_it.next()
|
||||
print('Batch shape=%s, min=%.3f, max=%.3f' % (trainX.shape, trainX.min(), trainX.max()))
|
||||
valX, valY = val_it.next()
|
||||
print('Batch shape=%s, min=%.3f, max=%.3f' % (valX.shape, valX.min(), valX.max()))
|
||||
testX, testY = test_it.next()
|
||||
print('Batch shape=%s, min=%.3f, max=%.3f' % (testX.shape, testX.min(), testX.max()))
|
||||
|
||||
print("input shape")
|
||||
input_shape=trainX.shape[1:]
|
||||
print(input_shape)
|
||||
|
||||
#img_width=823
|
||||
#img_height=1606
|
||||
img_width=256
|
||||
|
@ -71,26 +96,51 @@ print("Sequential")
|
|||
model = Sequential()
|
||||
|
||||
print("add")
|
||||
# Other data to consider adding:
|
||||
# * JSON metadata
|
||||
# * TLE
|
||||
# * Audio File (ogg)
|
||||
# * Decoded Data (HEX, ASCII, PNG)
|
||||
# Data from external sources to consider adding:
|
||||
# * Weather
|
||||
|
||||
print("convolution 2 deeeee")
|
||||
# https://keras.io/layers/convolutional/
|
||||
#model.add(Convolution2D(32, 3, 3, input_shape=trainX.shape[1:]))
|
||||
#model.add(Convolution2D(32, 3, 3, input_shape=(255,255,3)))
|
||||
model.add(Convolution2D(32, 3, 3, input_shape=(img_width, img_height,3)))
|
||||
# https://keras.io/activations/
|
||||
print("Activation relu")
|
||||
model.add(Activation('relu'))
|
||||
# https://keras.io/layers/pooling/
|
||||
print("Pooling")
|
||||
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||
print("Convolution2D")
|
||||
model.add(Convolution2D(32, 3, 3))
|
||||
print("Activation relu")
|
||||
model.add(Activation('relu'))
|
||||
print("Pooling")
|
||||
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||
print("Convolution2D")
|
||||
model.add(Convolution2D(64, 3, 3))
|
||||
print("Activation relu")
|
||||
model.add(Activation('relu'))
|
||||
print("Pooling")
|
||||
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||
# https://keras.io/layers/core/
|
||||
print("Flatten")
|
||||
model.add(Flatten())
|
||||
# https://keras.io/layers/core/
|
||||
print("Dense")
|
||||
model.add(Dense(64))
|
||||
print("Activation relu")
|
||||
model.add(Activation('relu'))
|
||||
# https://keras.io/layers/core/
|
||||
print("Dropout")
|
||||
model.add(Dropout(0.5))
|
||||
print("Dense")
|
||||
model.add(Dense(1))
|
||||
print("Activation softmax")
|
||||
model.add(Activation('softmax'))
|
||||
|
||||
# https://keras.io/models/sequential/
|
||||
|
@ -104,6 +154,8 @@ model.compile(
|
|||
optimizer='rmsprop',
|
||||
metrics=['accuracy'])
|
||||
|
||||
|
||||
|
||||
# https://keras.io/models/sequential/
|
||||
print("fit")
|
||||
model.fit(
|
||||
|
@ -129,6 +181,12 @@ model.fit(
|
|||
# https://keras.io/models/sequential/
|
||||
# evaluate(x=None, y=None, batch_size=None, verbose=1, sample_weight=None, steps=None, callbacks=None, max_queue_size=10, workers=1, use_multiprocessing=False)
|
||||
|
||||
# TODO:
|
||||
# * Generate output to visualize training/validating/testing.
|
||||
# Plot, fail
|
||||
#print("plot")
|
||||
#plot_model(test_it, to_file='data/wut-plot.png', show_shapes=True, show_layer_names=True)
|
||||
|
||||
# https://keras.io/models/sequential/
|
||||
print("predict")
|
||||
prediction = model.predict(
|
||||
|
|
Loading…
Reference in New Issue