Train without Validation set


(Jay Rodge) #1

How to train a neural network without a validation set, because most of the dataset I have been seeing, most of them dont have the validation split. I want to implement hot dog classifier and tried to pass the directory, it returns an error “no /valid directory”. I know validation is neccessary, but since I’m beginner I want to train a model and try different datasets.

Thanks!


(Kerem Turgutlu) #2

I think learning the importance of how to validate models is the most crucial part any of any application. Here is a great blog post emphasizing that http://www.fast.ai/2017/11/13/validation-sets/.

Still after this if you want to continue without validation you may create a dummy validation folder and put a single image in it to run any model.


(Jay Rodge) #3

Thanks for the help!


(Rengarajan Bashyam) #4

If you find it difficult to create a validation folder and move some random samples, pl use this script to move 20% of training set to validation set. (of course, you can modify the % of validation
set)


(Jay Rodge) #5

Thanks @Renga this was needed!


(Kerem Turgutlu) #6

Another good source https://www.coursera.org/learn/machine-learning-projects/lecture/78P8f/train-dev-test-distributions


(Karthikeyan Natarajan) #7
tfms = tfms_from_model(arch, sz)
data =  ImageClassifierData.from_paths(PATH, bs, tfms=tfms, val_name='train', test_name='test')
y=data.trn_y
from sklearn.model_selection import train_test_split
, val_idxs=train_test_split(range(len(y)),test_size=0.2, stratify=y)
data=ImageClassifierData.from_names_and_array(PATH, data.trn_ds.fnames, y, data.classes, 
                                         val_idxs=val_idxs, test_name='test',
                                         tfms=tfms, bs=bs)
len(data.trn_y), len(data.val_y)

this code could be of help.


(Jay Rodge) #8

Thanks @lxkarthi!