35 lines
750 B
Python
35 lines
750 B
Python
import tensorflow as tf
|
|
import numpy as np
|
|
|
|
x = np.array([
|
|
[0, 0, 0],
|
|
[0, 0, 1],
|
|
[0, 1, 0],
|
|
[0, 1, 1],
|
|
[1, 0, 0],
|
|
[1, 0, 1],
|
|
[1, 1, 0],
|
|
[1, 1, 1],
|
|
])
|
|
|
|
y = np.array([sum(i) % 2 for i in x])
|
|
|
|
model = tf.keras.Sequential([
|
|
tf.keras.layers.Input(shape = (3,)),
|
|
tf.keras.layers.Dense(3, activation = "tanh"),
|
|
tf.keras.layers.Dense(1, activation = "sigmoid")
|
|
])
|
|
|
|
model.compile(
|
|
optimizer = tf.keras.optimizers.Adam(learning_rate = 0.05),
|
|
loss = "binary_crossentropy",
|
|
metrics = ["accuracy"]
|
|
)
|
|
|
|
model.load_weights("mod1_final.weights.h5")
|
|
|
|
prediction = model.predict(x)
|
|
|
|
for i, o, t in zip(x, prediction, y):
|
|
print(f"i = {i}, o = {round(o[0])}, t = {t} : {'Good' if t == round(o[0]) else 'Bad'}")
|