Skip to content
Snippets Groups Projects
Commit 4e77088f authored by ivan.rigo's avatar ivan.rigo
Browse files

Model need Tweaking

parent 3cf400f7
Branches
No related tags found
No related merge requests found
Showing
with 65 additions and 2 deletions
......@@ -3,6 +3,11 @@ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from matplotlib import pyplot as plt
#It hide INFO/Warning and Error, as the usually one will be tensorflow reminding me of not having a cuba driver or the fact it has been installed correctly
#both doesnt stop the program completing
......@@ -13,13 +18,71 @@ batch_size = 10
train_ds, val_ds = tf.keras.utils.image_dataset_from_directory(
"ImageTest",
labels="inferred",
label_mode="categorical",
image_size=image_size,
batch_size=batch_size,
validation_split=0.1,
subset="both",
seed=1219
seed=1219,
color_mode="grayscale"
)
data_augmentation = keras.Sequential(
[
layers.RandomFlip("horizontal"),
layers.RandomRotation(0.1),
]
)
train_ds = train_ds.map(
lambda img, label: (data_augmentation(img), label),
num_parallel_calls=tf.data.AUTOTUNE,
)
# Prefetching samples in GPU memory helps maximize GPU utilization.
train_ds = train_ds.prefetch(tf.data.AUTOTUNE)
val_ds = val_ds.prefetch(tf.data.AUTOTUNE)
model = Sequential()
model.add(Dense(400, activation='relu'))
model.add(layers.Rescaling(1/255))
model.add(Dense(200, activation='relu'))
model.add(Dense(500, activation='relu'))
model.add(Dense(200, activation='relu'))
model.add(layers.Flatten())
model.add(Dense(10, activation='softmax'))
epochs = 40
model.compile(
optimizer=keras.optimizers.Adam(1e-3),
loss="binary_crossentropy",
metrics=["accuracy"],
)
model.fit(
train_ds,
epochs=epochs,
validation_data=val_ds,
)
img = keras.utils.load_img(
"Test2.jpg",
target_size=image_size,
color_mode="grayscale"
)
img_array = keras.utils.img_to_array(img)
img_array = tf.expand_dims(img_array, 0) # Create batch axis
predictions = model.predict(img_array)
for v in range(10):
print(str(v) + " possible à {0:.2f}".format(predictions[0][v] * 100))
#https://keras.io/examples/vision/image_classification_from_scratch/
#https://keras.io/examples/
#https://www.sitepoint.com/keras-digit-recognition-tutorial/
#https://www.tensorflow.org/api_docs/python/tf/keras/utils/image_dataset_from_directory
\ No newline at end of file
OCR/ImageTest/0/0_1.jpg

635 B

OCR/ImageTest/0/0_10.jpg

649 B

OCR/ImageTest/0/0_11.jpg

687 B

OCR/ImageTest/0/0_12.jpg

643 B

OCR/ImageTest/0/0_13.jpg

696 B

OCR/ImageTest/0/0_14.jpg

682 B

OCR/ImageTest/0/0_15.jpg

627 B

OCR/ImageTest/0/0_16.jpg

593 B

OCR/ImageTest/0/0_17.jpg

630 B

OCR/ImageTest/0/0_18.jpg

665 B

OCR/ImageTest/0/0_19.jpg

640 B

OCR/ImageTest/0/0_2.jpg

625 B

OCR/ImageTest/0/0_20.jpg

634 B

OCR/ImageTest/0/0_3.jpg

688 B

OCR/ImageTest/0/0_4.jpg

609 B

OCR/ImageTest/0/0_5.jpg

641 B

OCR/ImageTest/0/0_6.jpg

691 B

OCR/ImageTest/0/0_7.jpg

670 B

OCR/ImageTest/0/0_8.jpg

657 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment