![]() ![]() I solved the problem following the advices in the comments of this discussion. Where "img" are all the imageas read with "imread_collection" of skimage.ioĮDIT1: the images resized with opencv have not been processed with the preprocessing function We can easily iterate over the iterator to yield the batches of data. This is done using the flow method which creates an iterator. In this blog, we will learn how we can generate batches of the augmented data. Supported image formats: jpeg, png, bmp, gif. Resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) In the previous blog, we have discussed how to apply different transformations to augment data using Keras ImageDataGenerator class. Then calling imagedatasetfromdirectory (maindirectory, labels'inferred') will return a tf.data.Dataset that yields batches of images from the subdirectories classa and classb, together with labels 0 and 1 (0 corresponding to classa and 1 corresponding to classb ). The code that I used to solve is the same but I read and resize images with the following code: width = 299 Where the columns represent the labels (1 to 29) and imNames are obtained with filenames attribute of test_generator.įinally I generated the csv with the labels with highest probabilities value and i compute the accuracy obtaining the value that I wrote before. Where 6104 is the number of images in test folder.Īfter this i've generated a csv with images name with relative categorical probabilities: import pandas as pdĬols =ĭf.to_csv('predictions_xception_all_data.csv', sep=',') The predictions are made with the following code: predictions = model_xcpetion.predict_generator(test_generator, 6104, verbose = 1 ) Where the preprocess function is exactly the same. Test_generator = test_datagen.flow_from_directory(Ĭlass_mode=None # non ce alcuna classe di riferimento Val_train_generator = train_val_datagen.flow_from_directory( # subset di validationįinal_train_generator = train_val_datagen.flow_from_directory( # set finale di allenamento con tutti i datiĪs you can see i used Xception as pretrained-net and I choose to resize my images to adapt them to the net.Īfter the training I created a new Iterator for test data as follow: test_datagen = ImageDataGenerator(preprocessing_function=preprocess_input) Train_val_generator = train_val_datagen.flow_from_directory( # subset di allenamento Train_val_datagen = ImageDataGenerator( validation_split=0.25, preprocessing_function=preprocess_input) Chapter-2: Writing a generator function to read your data that can be fed for training an image classifier in Keras. from import ImageDataGeneratorįrom import preprocess_input I solved the problem using opencv to read and resize image, but I'd like to understand why with keras methods I've this problem. The problem is that the accuracy on validation set is very high, around the 90%, but on test set the accuracy is very bad, less that 1%. I'm new with keras with tensorflow backend and I'm trying to do transfer learning with pretrained net. ![]()
0 Comments
Leave a Reply. |