You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically my training and validation resulted in 88-90% accuracy but the testing is very low.. only about 25%. I'm guessing it's overfitting but I'm not sure how to fix this. Also here is my code:
import os
import numpy as np
import matplotlib.pyplot as plt
import cv2
from tensorflow.keras import layers
from google.colab import drive
import tensorflow as tf
Basically my training and validation resulted in 88-90% accuracy but the testing is very low.. only about 25%. I'm guessing it's overfitting but I'm not sure how to fix this. Also here is my code:
import os
import numpy as np
import matplotlib.pyplot as plt
import cv2
from tensorflow.keras import layers
from google.colab import drive
import tensorflow as tf
drive.mount('/content/drive')
img_height = 256
img_width = 256
class_names = ['rice_blast', 'brown_spot', 'leaf_blight', 'healthy']
gdrive_path="drive/My Drive/rice_disease"
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
gdrive_path,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
)
validation_ds = tf.keras.preprocessing.image_dataset_from_directory(
gdrive_path,
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
)
gdrive_path="drive/My Drive/rice_disease_test"
test_ds = tf.keras.preprocessing.image_dataset_from_directory(
gdrive_path,
seed=123,
image_size=(img_height, img_width),
)
def preprocessing_fn(inputs):
"""Preprocess input columns into transformed columns."""
x = inputs['x']
y = inputs['y']
s = inputs['s']
x_centered = x - tft.mean(x)
y_normalized = tft.scale_to_0_1(y)
s_integerized = tft.compute_and_apply_vocabulary(s)
x_centered_times_y_normalized = (x_centered * y_normalized)
return {
'x_centered': x_centered,
'y_normalized': y_normalized,
's_integerized': s_integerized,
'x_centered_times_y_normalized': x_centered_times_y_normalized,
}
model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(img_height, img_width, 3)),
tf.keras.layers.Dense(32, activation='relu'),
tf.keras.layers.Dense(10),
tf.keras.layers.Dropout(0.2),
])
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
history = model.fit(train_ds, epochs=10)
image_results = model.evaluate(validation_ds)
print('\nValidation accuracy:', image_results)
test_results = model.evaluate(test_ds)
print('/nTest accuracy:', test_results)
The text was updated successfully, but these errors were encountered: