<jupyter_start><jupyter_text>To speed the execution procces, Colaboraty has an option to use GPU. This option is selected by default.  MultiLabel classification In this notebook, we illustrate how FrImCla can be employed for multi-label classification. We have to train the framework to make these classifications. This is a simple example to show how to use FrImCla. We train the models with a fragment of the [cloths dataset](https://www.pyimagesearch.com/2018/05/07/multi-label-classification-with-keras/).With this notebook we want to show and explain non-expert users the methods they have to use to run FrImCla.<jupyter_code>!wget "https://www.dropbox.com/s/6s3a2ezgwf22615/cloths.zip?dl=0" -O cloths.zip
!unzip cloths.zip<jupyter_output><empty_output><jupyter_text>In case that FrImCla is not installed in your system, the first task consist in installing using pip.<jupyter_code>!pip install frimcla<jupyter_output><empty_output><jupyter_text>We need some libraries to execute this framework and obtain the results.<jupyter_code>%tensorflow_version 1.x
from frimcla.index_features import generateFeatures
from frimcla.StatisticalComparison import statisticalComparison
from frimcla.train import train
from frimcla.prediction import prediction<jupyter_output><empty_output><jupyter_text>Configuring the variables of the program First of all, we have to indicate the variables that the program need such as the path of the dataset, the models you want to use,...<jupyter_code>datasetPath = "./cloths"
outputPath = "./output"<jupyter_output><empty_output><jupyter_text>Advanced parametersYou can use the following parameters by default.<jupyter_code>batchSize = 32 
verbose = False
trainingSize = 1
nSteps=10
measure = 'accuracy' #@param ["accuracy", "f1", "auroc", "precision", "recall"]<jupyter_output><empty_output><jupyter_text>In the next section we have to select the feature extractors that we want to use (It is mandatory to **select at least one option**)<jupyter_code>VGG16 = True #@param {type:"boolean"}
VGG19 = True #@param {type:"boolean"}
ResNet = True #@param {type:"boolean"}
Inception = True #@param {type:"boolean"}
GoogleNet = True #@param {type:"boolean"}
Overfeat = True #@param {type:"boolean"}
Xception = True #@param {type:"boolean"}
Densenet = True #@param {type:"boolean"}
LAB888 = True #@param {type:"boolean"}
LAB444 = True #@param {type:"boolean"}
HSV888 = True #@param {type:"boolean"}
HSV444 = True #@param {type:"boolean"}
Haralick = True #@param {type:"boolean"}
Hog = True #@param {type:"boolean"}
Haarhog = True #@param {type:"boolean"}

featureExtractors = []

if VGG19 :
  featureExtractors.append(["vgg19","False"])
if VGG16 :
  featureExtractors.append(["vgg16","False"])
if ResNet :
  featureExtractors.append(["resnet","False"])
if Inception :
  featureExtractors.append(["inception","False"])
if GoogleNet :
  featureExtractors.append(["googlenet"])
if Overfeat :
  featureExtractors.append(["overfeat","[-3]"])
if Xception :
  featureExtractors.append(["xception","False"])
if Densenet :
  featureExtractors.append(["densenet"])
if LAB888 :
  featureExtractors.append(["lab888"])
if LAB444 :
  featureExtractors.append(["lab444","4,4,4"])
if HSV888 :
  featureExtractors.append(["hsv888"])
if HSV444 :
  featureExtractors.append(["hsv444","4,4,4"])
if Haralick :
  featureExtractors.append(["haralick"])
if Hog :
  featureExtractors.append(["hog"])
if Haarhog :
  featureExtractors.append(["haarhog"])<jupyter_output><empty_output><jupyter_text>Now we have to indicate the classifier models that we want to use (It is mandatory to **select at least one option**)<jupyter_code>BinaryRelevance_MLP = True #@param {type:"boolean"}
BinaryRelevance_SVM = True #@param {type:"boolean"}
BinaryRelevance_KNN = True #@param {type:"boolean"}
BinaryRelevance_LogisticRegression = True #@param {type:"boolean"}
BinaryRelevance_GradientBoost = True #@param {type:"boolean"}
BinaryRelevance_RandomForest = True #@param {type:"boolean"}
ClassifierChain_MLP = True #@param {type:"boolean"}
ClassifierChain_SVM = True #@param {type:"boolean"}
ClassifierChain_KNN = True #@param {type:"boolean"}
ClassifierChain_LogisticRegression = True #@param {type:"boolean"}
ClassifierChain_GradientBoost = True #@param {type:"boolean"}
ClassifierChain_RandomForest = True #@param {type:"boolean"}
LabelPowerset_MLP = True #@param {type:"boolean"}
LabelPowerset_SVM = True #@param {type:"boolean"}
LabelPowerset_KNN = True #@param {type:"boolean"}
LabelPowerset_LogisticRegression = True #@param {type:"boolean"}
LabelPowerset_GradientBoost = True #@param {type:"boolean"}
LabelPowerset_RandomForest = True #@param {type:"boolean"}
MLkNN = True #@param {type:"boolean"}
MLTSVM= True #@param {type:"boolean"}
modelClassifiers = []


if BinaryRelevance_MLP :
  modelClassifiers.append("MLP")
if BinaryRelevance_SVM :
  modelClassifiers.append("SVM")
if BinaryRelevance_KNN :
  modelClassifiers.append("KNN")
if BinaryRelevance_LogisticRegression :
  modelClassifiers.append("LogisticRegression")
if BinaryRelevance_GradientBoost :
  modelClassifiers.append("GradientBoost")
if BinaryRelevance_RandomForest :
  modelClassifiers.append("RandomForest")

if ClassifierChain_MLP :
  modelClassifiers.append("ccMLP")
if ClassifierChain_SVM :
  modelClassifiers.append("ccSVM")
if ClassifierChain_KNN :
  modelClassifiers.append("ccKNN")
if ClassifierChain_LogisticRegression :
  modelClassifiers.append("ccLogisticRegression")
if ClassifierChain_GradientBoost :
  modelClassifiers.append("ccGradientBoost")
if ClassifierChain_RandomForest :
  modelClassifiers.append("ccRandomForest")

if LabelPowerset_MLP :
  modelClassifiers.append("lpMLP")
if LabelPowerset_SVM :
  modelClassifiers.append("lpSVM")
if LabelPowerset_KNN :
  modelClassifiers.append("lpKNN")
if LabelPowerset_LogisticRegression :
  modelClassifiers.append("lpLogisticRegression")
if LabelPowerset_GradientBoost :
  modelClassifiers.append("lpGradientBoost")
if LabelPowerset_RandomForest :
  modelClassifiers.append("lpRandomForest")

if MLTSVM :
  modelClassifiers.append("MLTSVM")
if MLkNN :
  modelClassifiers.append("MLkNN")<jupyter_output><empty_output><jupyter_text>Generating the features At this step we stored the features of each image of the dataset. These features depend on the model used at this moment because each model stores different features of the image.<jupyter_code>generateFeatures(outputPath, batchSize, datasetPath, featureExtractors, verbose,multiclass=True)<jupyter_output><empty_output><jupyter_text>Statistical analysis Now with the features of all the images of each model we can perform a statistical analysis to know which of this models has the best performace.<jupyter_code>statisticalComparison(outputPath, datasetPath, featureExtractors, modelClassifiers, measure, nSteps, verbose,multiclass=True)<jupyter_output><empty_output><jupyter_text>Train the model The study gives us as result the best model and indicates if there are significant differences between this and the rest of the models. With this information, we can train the best model and return as a result of the framework to the user.<jupyter_code>train(outputPath, datasetPath, trainingSize,multiclass=True)<jupyter_output><empty_output><jupyter_text>Predict the class of the images Finally, we have the best model and we can use it to predict the class of our images. To do this we have to use the following command and we have to define the feature extractor and the classifier. The prediction will store in the predictionResults file.<jupyter_code>image = "./cloths/black_jeans/00000000.jpg"
featExt = ["inception", "False"]
classi = "MLP"
prediction(featExt, classi, image, outputPath, datasetPath,multiclass=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10599197618739485, 'fraction_numerical': 0.011259220913679306, 'mean_word_length': 7.372697724810401, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '570740', 'license': 'MIT', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2372, 'n_words': 665, 'path': 'examples/multiClassNotebook.ipynb', 'repo_name': 'ManuGar/ObjectClassificationByTransferLearning', 'size': '7727'}