Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing much worse than training? #401

Open
aquiraa opened this issue Dec 22, 2020 · 0 comments
Open

testing much worse than training? #401

aquiraa opened this issue Dec 22, 2020 · 0 comments

Comments

@aquiraa
Copy link

aquiraa commented Dec 22, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant