Search code examples
machine-learningdeep-learningneural-networkconv-neural-networktransfer-learning

How do we provide the labels to our training set in transfer learning?


I am trying to use a pre trained model specifically training on logos . I am using MobileNet for training in logos . If we made our CNN model from scratch then we provide the labels in it . I don't know how to provide the labels in transfer learning . Either image data generator automatically provide the labels when we use flow_from_directory function . Little part of code is shown below . Elaborate !

training_set = train_datagen.flow_from_directory('Datasets/Train',
                                                 target_size = (224, 224),
                                                 batch_size = 32,
                                                 class_mode = 'categorical')
        r = model.fit_generator(training_set,validation_data=test_set,epochs=5,steps_per_epoch=len(training_set),
    validation_steps=len(test_set)
        )

Solution

  • I believe that the labels are inferred from the directory schema, so if your main directory looks like this for each of the train and test sets:

    main_directory/
    ...class_a/
    ......a_image_1.jpg
    ......a_image_2.jpg
    ...class_b/
    ......b_image_1.jpg
    ......b_image_2.jpg
    

    You should be fine. for more examples refer to this