64 lines
2.2 KiB
Python
Executable File
64 lines
2.2 KiB
Python
Executable File
#!/usr/bin/python3
|
|
#
|
|
# XXX This does not work yet XXX
|
|
#
|
|
# wut-ml-save
|
|
#
|
|
# Vet a SatNOGS image using machine learning (guessing).
|
|
# It will vet the image located at test/unvetted/waterfall.png.
|
|
#
|
|
# Note, there is an issue to fix where it will vet everything
|
|
# under the data/test directory, so fix that. For now, just delete
|
|
# everything else. :)
|
|
#
|
|
# Usage:
|
|
# wut-ml-save
|
|
# Example:
|
|
# wut-ml-save
|
|
|
|
import os
|
|
import numpy as np
|
|
import tensorflow.python.keras
|
|
from tensorflow.python.keras import Sequential
|
|
from tensorflow.python.keras.layers import Activation, Dropout, Flatten, Dense
|
|
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
|
|
from tensorflow.python.keras.layers import Convolution2D, MaxPooling2D, ZeroPadding2D
|
|
from tensorflow.python.keras import optimizers
|
|
from tensorflow.python.keras.preprocessing import image
|
|
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
|
|
|
|
datagen = ImageDataGenerator()
|
|
train_it = datagen.flow_from_directory('/srv/satnogs/data/train/', class_mode='binary')
|
|
val_it = datagen.flow_from_directory('/srv/satnogs/data/val/', class_mode='binary')
|
|
test_it = datagen.flow_from_directory('/srv/satnogs/data/test/', class_mode='binary')
|
|
batchX, batchy = train_it.next()
|
|
print('Batch shape=%s, min=%.3f, max=%.3f' % (batchX.shape, batchX.min(), batchX.max()))
|
|
img_width=256
|
|
img_height=256
|
|
model = Sequential()
|
|
model.add(Convolution2D(32, 3, 3, input_shape=(img_width, img_height,3)))
|
|
model.add(Activation('relu'))
|
|
model.add(MaxPooling2D(pool_size=(2, 2)))
|
|
model.add(Convolution2D(32, 3, 3))
|
|
model.add(Activation('relu'))
|
|
model.add(MaxPooling2D(pool_size=(2, 2)))
|
|
model.add(Convolution2D(64, 3, 3))
|
|
model.add(Activation('relu'))
|
|
model.add(MaxPooling2D(pool_size=(2, 2)))
|
|
model.add(Flatten())
|
|
model.add(Dense(64))
|
|
model.add(Activation('relu'))
|
|
model.add(Dropout(0.5))
|
|
model.add(Dense(1))
|
|
model.add(Activation('sigmoid'))
|
|
model.compile(loss='binary_crossentropy',
|
|
optimizer='rmsprop',
|
|
metrics=['accuracy'])
|
|
|
|
model.fit(x=train_it, validation_data=val_it, epochs=1, verbose=2, workers=16, use_multiprocessing=True)
|
|
|
|
model.save('wut.h5')
|
|
|