1
votes

I'm beginner in deep learning (CNN). I used this code :(http://learnandshare645.blogspot.com/2016/06/feeding-your-own-data-set-into-cnn.html) to learn more about Convolutional Neural Network. This python code just split data to two parts "train" and "test", there is not validation part in the code. So, how can I add validation folder to the code which contains different images such as normal and abnormal? My aim is: giving an abnormal image(which this image is totally different from train and test images that machine has been trained before) to the code in order to see the different result.

1

1 Answers

1
votes

According to the code, the "test" set is used as validation. You know this because the model "fits" on the test set, i.e. you have:

model.fit(...validation_data=(X_test, Y_test)

This is just nomenclature, but can be confusing. A true test set is never seen by the model during training. You need to "hold out" an additional dataset from the training and name the arrays properly. Let's say you want a test set as 10% of your training data, simply:

# Split your data into train/validation
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=4)

# Split into train/test
X_train, X_test, y_train, y_test = train_test_split(X_train, y_train, test_size=0.1, random_state=4)

...more code

# Train you model
model.fit(...validation_data=(X_val, Y_val)

...more code

# Now evaluate on the test data
score = model.evaluate(X_test, Y_test, show_accuracy=True)