-
Notifications
You must be signed in to change notification settings - Fork 0
/
NeuralNet.py
36 lines (26 loc) · 986 Bytes
/
NeuralNet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
import pickle
from keras.utils import to_categorical
X = pickle.load(open("X.pickle", "rb"))
y_int = pickle.load(open("y.pickle", "rb"))
y_binary = to_categorical(y_int)
X = X / 255.0
model = Sequential()
model.add(Conv2D(64, (3, 3), input_shape=X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3), input_shape=X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Dense(24))
model.add(Activation("sigmoid"))
model.compile(loss="categorical_crossentropy",
optimizer="adam",
metrics=['accuracy'])
model.fit(X, y_binary, batch_size=24, epochs=10, validation_split=0.1)
pickle.dump(model, open("food_classifier.pickle", "wb"))
# model.save('food_predict.model')