158 - Convolutional filters + Random Forest for image classification.

Sdílet
Vložit
  • čas přidán 13. 09. 2020
  • Deep learning is far superior to traditional machine learning with loads of training data. But, for limited training data traditional machine learning (e.g. Random Forest or SVM) may outperform deep learning. For image processing applications features need to be extracted / engineered for improved accuracy. Alternatively, features can be extracted from convolutional filters that are part of convolutional neural networks.
    This video goes through the process of extracting features using convolutional filters and using them as inputs to a traditional Random Forest classifier to develop an image classification solution. This approach is specifically designed for image classification of custom datasets.
    Code generated in the video can be downloaded from here:
    github.com/bnsreenu/python_fo...
  • Věda a technologie

Komentáře • 111

  • @iamtherealankitroy
    @iamtherealankitroy Před 3 lety +25

    These videos have been an extremely valuable resource for me. Thanks for constantly providing high value content!

  • @Fransphoenix
    @Fransphoenix Před 4 měsíci +2

    Amazing content. Underrated channel. Though I suspect all of us here are the ones truly embracing ML and AI, haha!

  • @ssshukla26
    @ssshukla26 Před 2 lety +4

    You never know who is watching the videos. Exactly the kind of attitude every professor should have when they start explaining stuff which gets really confusing because one doesn't know small things needed to know. Thank you sir for the video. Subscribed.

    • @DigitalSreeni
      @DigitalSreeni  Před 2 lety

      Like I tweeted a few days ago - A good teacher educates by meeting students at least 80% into their space of understanding.

    • @ssshukla26
      @ssshukla26 Před 2 lety

      @@DigitalSreeni what's your Tweeter handle? I will like to follow you.

    • @ssshukla26
      @ssshukla26 Před 2 lety +1

      @@DigitalSreeni ok it's by same name. Got it. Following.

  • @ghaliahmed
    @ghaliahmed Před 2 lety

    For the first time, i find a person who can realy make a good explanation for all the time !!!!!!

  • @adoniasandarge6008
    @adoniasandarge6008 Před 3 lety

    I am Adonias Andarge from Ethiopia. I am so impressed by your everything. I am working on mammography image classification. And I found your tutorial very useful... thankyou so much sir...

  • @swethanandyala
    @swethanandyala Před 3 měsíci

    Most amazing content for deep learning...am learning lot from u sir...thank you

  • @shalombentenzingnamchyo9384

    Wow thank you so much. I wish I found you sooner. You deserver to be on top of the search results for CNN tutorials.

  • @iguyblr
    @iguyblr Před 2 lety

    Wow Sreeni , Just bumped into your videos , its pretty impressive now need to catch up on others .. Thanks for sharing

  • @nikhilkethu5202
    @nikhilkethu5202 Před rokem

    These video sloved lot of doubhts which i had and got me distinction in my main masters project. Thank you keep going....

  • @madchemist199
    @madchemist199 Před 2 lety

    Thanks a ton for making the video extremely useful for me!

  • @user-vz8tq2by7v
    @user-vz8tq2by7v Před 3 lety

    really helpful video! clear explanation! thank you a lot and this Vedio helps me a lot as a student majoring in CS

  • @naveenfernando1852
    @naveenfernando1852 Před 3 lety

    Hi sir,
    I use this approach for one of my projects. Thanks to you i was able to achieve 98% of accuracy.
    once i created the model i save random forest model using the following code
    import dill
    save_model = dill.dump(RF_model, open(directory_name + ".obj","wb"))
    Once i completed the model i open a new notebook and load the CNN_RF_model using the following code
    load_model = dill.load(open(directory_name + ".obj","rb"))
    After load the RF_CNN_model i tried to predict some images using the following code
    input_img = np.expand_dims(image, axis=0) #Expand dims so the input is (num images, x, y, c)
    input_img_features=feature_extractor.predict(input_img)
    prediction_RF = RF_CNN_model.predict(input_img_features)[0]
    prediction_RF = le.inverse_transform([prediction_RF])
    Since now i am in a new notebook i dont have feature_extraction variable that i used to build the RF_CNN_model.
    so my problem is how can load the feature_extractor variable data for the RF prediction?
    What i had done was I rerun the feature_extraction part that we use to create the model again in my new notebook.
    Everytime my CNN+RF model gives different results. maybe the feature_extraction variable changes everytime. How can i fix this issue sir?
    In conclude, when using the random forest model which created with CNN features .. how can i get the feature_extracted part for the prediction.. is there a method to save the CNN features
    Thanks and best regards.

  • @shitshow_1
    @shitshow_1 Před 2 lety

    Thank you, such an amazing video. Really Helpful 👍🏼

  • @qsxzae12
    @qsxzae12 Před 2 lety

    Extremely helpful. Thanks for sharing.

  • @MrMikael1337
    @MrMikael1337 Před 3 lety

    Hi Sreeni, thank you for this amazing video.
    I have a question on how to interpret what the random forest is doing. In another video you posted, the decision trees were using nodes based on histogram values and texture . There it was very clear what nodes the tree can be built upon. But when we have like in this case, just a very long flattened column vector, how can the nodes be represented from this vector?

  • @saivarun7298
    @saivarun7298 Před 2 lety

    Thanks sir, my mini project is done just because of you.

  • @AlgoTribes
    @AlgoTribes Před 3 lety

    that was really insightful..thanks for the content ..it really made me content..

  • @AIdAssist
    @AIdAssist Před 7 měsíci

    Thank you so so much! These videos are so helpful!!!!!!

  • @Hoxle-87
    @Hoxle-87 Před 3 lety +1

    Great tutorial. For few samples you should use bootstrapping

  • @fatizulfiqar
    @fatizulfiqar Před 3 lety

    Thank you for detailed and very informative tutorial. However I have one question that is you have extracted features from convolutional base, flatten it and passed into the random forest. My query is can I also add a few dense layers on top of features from convolutional base and use that feature descriptor to be fed into the svc or any other sklearn model?. I hope my query is clear

  • @TheMishupo
    @TheMishupo Před 2 lety

    Great video, thank you!

  • @refreshyourlife3099
    @refreshyourlife3099 Před 2 lety

    great course, thank you sir

  • @RadomName3457
    @RadomName3457 Před 2 lety

    Thanks for your ammazing video sir. But i have a question, how can i save the weights and architecture of the feature extractor (not the whole model) built from convolutional layers for later use?

  • @samarafroz9644
    @samarafroz9644 Před 3 lety

    Awesome tutorial like always sir.

  • @NehadHirmiz
    @NehadHirmiz Před 3 lety

    Excellent Tutorial. Thank you very much

  • @RAZZKIRAN
    @RAZZKIRAN Před 2 lety

    super, excellent , thank u sir

  • @kuipan5968
    @kuipan5968 Před 3 lety +1

    Great content! One quick question: since you trained feature_extractor first during fitting CNN model, that basically means the Random forest model's performance is dependent on the CNN model training process. I am wondering how did you decide how many layers to be used for the feature_extractor?

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety +2

      Please watch the follow up video 158b which may answer your questions.

  • @abhukk
    @abhukk Před 3 lety

    this is amazing

  • @shilashm5691
    @shilashm5691 Před 2 lety

    You can also work with labelencoding in deep learning by setting loss function as sparse_categorical_crossentropy

  • @talhaabbasjalvi9572
    @talhaabbasjalvi9572 Před 3 lety

    His sir amazing video by the way I have question which software or IDE you are usingb here

  • @ismailaslan287
    @ismailaslan287 Před 2 lety

    Is it similar to getting node embeddings with Convolutional filters and then passing the node embeddings to the random forest? Thanks for the great video.

  • @danielyoo5897
    @danielyoo5897 Před rokem

    Hi! Your video is so helpful! I would like to ask you one question about the code. On line 58 where you make X_for_RF, why does it have to be feature_extractor.predict(x_train) instead of feature_extractor.output like NN?
    Also, can you make a video to demonstrate how to add additional features like tabular data to your model please? For example, feature_extractor to extract features, then add tabular features (age, sex, etc..), then perform random forest for final!

  • @michaelmanuel1676
    @michaelmanuel1676 Před 3 lety

    Thank you!!

  • @joaosacadura6097
    @joaosacadura6097 Před 3 lety

    Thanks so much for your videos! So i'm currently using U-net for multi class classification on o
    orthophotos, and i see that u used other methods like this one with the add of random forest. From your
    experience in the subject what is best model for multi class?
    Keep up with the videos!

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety +1

      If you have enough labeled images please use one of the pre-trained models (e.g. VGG16) and attach your own dense layers to customize the prediction for your images. Continue training on your images. I think this works best for multiclass problems.

  • @abderrahmaneherbadji5478

    Hello Sreeni,
    Plesae how can we determine Accuracy Top-5 of the RF classifer

  • @MohamedAbomokh
    @MohamedAbomokh Před 3 lety

    Hey Sreeni ,
    I really enjoy watching your videos and love the effort you put into each video and they are helpful ,
    Also I wanted to ask if you did a video about how to use the watershed algorithm or something similar for edge detection in cells or fractography in order to creat masks for a CNN model ? If yes which one cause I can find it , if not would you kindly recommend something?

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety +1

      I did videos on Grain and cell segmentation where I used traditional watershed to separate connected components. Please watch videos 33, 34, and 35.

    • @MohamedAbomokh
      @MohamedAbomokh Před 3 lety

      @@DigitalSreeni thank you :)

  • @abderrahmaneherbadji5478

    Hi Sreeni,
    Many thanks for your efforts.
    Please can you record a video about fine-tuning procedure of pretrained models.

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety

      Fine tuning to do what? Do you mean transfer learning where you want t use pre-trained models?

  • @pechaaloler
    @pechaaloler Před 3 lety

    Hey, I really like your video!
    Do you know some papers about deep image feature extraction by any chance?
    I searched for an eternity but did not find interesting papers or an overview on this topic.
    I would really appreciate it if you could name a few papers or blogs on this topic!

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety

      Sorry No. I am not sure if the topic is worth publishing a paper so I am not surprised you haven't found any papers. I am also not aware of any blogs. If you haven't found anything doing a Google search then it must not exist :)

  • @umairsabir6686
    @umairsabir6686 Před 3 lety

    Hi Sreeni, great presentation of the topic. In real world scenarios most problems are novelty detection related. Where we only have data for normal case but not abnormal case. Is there any possibility of extracting features from convolutional filters and then use one class svm, isolation forest of LOC for novelty detection ? I want to know about tuning of those parameters in one class segmentation problems to get novelties. Thanks

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety

      For data sets where you only have normal case images you need to look for algorithms that detect anomalies. This is where you train it on normal and anything not normal is anomaly. Autoencoders can be good architectures for this application.

    • @umairsabir6686
      @umairsabir6686 Před 3 lety

      @@DigitalSreeni I tried autoencoders. But the problem with autoencoders is that they are also reconstructing the defected part of the images which they should not construct. They learned normal data but they also learned to construct abnormal part as well. This is where Variational autocnecoders comes in. Is it possible to tweat parameters in autoencoders or variational autoencoders to have control on the model so that it learns limited features ?

  • @mohammadareeb4826
    @mohammadareeb4826 Před 3 lety

    Sir can we not do one hot encoding and use sparse_categorical_crossentropy as the loss function?

  • @iraqfree9509
    @iraqfree9509 Před 2 lety

    thank you,how can i find the class labels for these features?

  • @holthuizenoemoet591
    @holthuizenoemoet591 Před 2 lety

    How do you apply the one hot encoding for pixel segmentation? An how can you flatten the convolutional layers, so they match the flattened input image?

    • @DigitalSreeni
      @DigitalSreeni  Před 2 lety

      I did that in many of my videos. Just search for multiclass segmentation videos on my channel. Here is the link to one such tutorial: czcams.com/video/XyX5HNuv-xE/video.html

  • @dr.aravindacvnmamit3770
    @dr.aravindacvnmamit3770 Před 3 lety +2

    Dear sir I cleared the error. I should use accuracy instead of acc😉😉😉

  • @htissolutions7960
    @htissolutions7960 Před 2 lety

    I found this video very interesting. Good job. But I have small issue that i want you to help me with. I have 790 train images, but when CNN trained, it reduced to 25 from the Epoch.
    And yours remain 320 images even during the training.
    kindly help me out

  • @rayhanuthama-5917
    @rayhanuthama-5917 Před rokem

    so i try this and set dense 2, activation = sigmoid (2 class) and why my confussion matrix append 4x4 table?

  • @lakshyavaibhavdatta9098

    @DigitalSreeni There's a huge problem with this code. Even directly copying it into google colab, and creating the directory structure with a train and validation folder produces a seemingly irresolvable error in the line "X_for_RF = feature_extractor.predict(train_images)" :
    WARNING:tensorflow:Model was constructed with shape (None, 100, 100, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, 100, 100, 3), dtype=tf.float32, name='conv2d_37_input'), name='conv2d_37_input', description="created by layer 'conv2d_37_input'"), but it was called on an input with incompatible shape (32,)
    Is there any way around this? Because otherwise the logic of merging the predict function will never work even in our own implementations. Thank you :)

    • @DigitalSreeni
      @DigitalSreeni  Před 2 lety

      You need to keep track of array dimensions as they go through various layers. The dimensions depend on your input images so you have to customize that part.

  • @minhaoling3056
    @minhaoling3056 Před rokem

    Hi Sir , do you know a feature extractor in computer vision called Krawtchouk moment ? Do you think it will be helpful if I convert the image into Krawtchuok moment image before putting them into the CNN feature extractor?

    • @DigitalSreeni
      @DigitalSreeni  Před rokem

      No need to preprocess images for deep learning based approach. Usually they should learn from raw data.

  • @saivarun7298
    @saivarun7298 Před 2 lety

    Sir, in this video the accuracy you got for cnn is for entire cnn model right?

    • @DigitalSreeni
      @DigitalSreeni  Před 2 lety

      Accuracy is for the trained model in classifying test data.

  • @htissolutions7960
    @htissolutions7960 Před 2 lety

    Also my cnn model does not show number trainning samples and validation samples

  • @abhisheksrivastava3700

    Hi
    What is your tensorflow and keras library version , because to_categorical() function giving error.
    Thank in advance .

    • @DigitalSreeni
      @DigitalSreeni  Před 2 lety

      If you are working with tensorflow2.x, do not import keras or its libraries directly. I do that mistake all the time. Please import keras from tensorflow.
      For example: from tensorflow.keras.utils import to_categorical

  • @mohamedtouati9663
    @mohamedtouati9663 Před 3 lety

    I need help Sir !!! :O how can i use this model to classifier diabetic retinopathy images?

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety

      This will work for diabetic retinopathy images but I recommend using fully deep learning for better accuracy. You may find this paper useful: arxiv.org/pdf/2003.02261.pdf

  • @dr.aravindacvnmamit3770

    Dear Sir I have taken 5 folders of images each folder consists of 1214 samples. But am getting this error?"ValueError: zero-size array to reduction operation maximum which has no identity"

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety +1

      Zero size array mean it is not reading your files and has an empty array. Please do these one step at a time so you can troubleshoot easily. Please make sure the path is correct from the location where you are executing the python file.

  • @QGISTutorial
    @QGISTutorial Před 2 lety

    Please tell me how to get the image data.

  • @mohit6847
    @mohit6847 Před 3 lety

    Sir is it possible if we use 3 pretrained models(ResNet, DensNet, Inception) with random forest for image classification if yes then how to do that.
    (newbie to ML)

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety +1

      Yes it is possible. You need to perform classification individually and then combine the predictions. Please watch my video 213 to find out how to ensemble. I used deep learning approach for classification but the ensembling part should be the same. czcams.com/video/-ix_Mjzu8BU/video.html

    • @mohit6847
      @mohit6847 Před 3 lety

      @@DigitalSreeni Sir with weighted average I got u and tried. But main problem where I confused to merge all 3 models using Random Forest like in this video u had fitted a single model, like that I want to merge all 3 models

  • @meriemketfi4923
    @meriemketfi4923 Před 2 lety

    thank you for this veideo. please can you help me why my RF_accuracy =00

  • @thomasjefferson6225
    @thomasjefferson6225 Před rokem

    Can i use this with deepsurv on a random survival forest?

  • @bhargavireddy604
    @bhargavireddy604 Před 3 lety

    Sir how to slove this error " return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
    " y_train_one_hot = to_categorical(y_train)
    ValueError: zero-size array to reduction operation maximum which has no identity

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety

      It says zero-size array. Please make sure you have information your arrays, may be the files are not being read into python correctly.

  • @rv0_0
    @rv0_0 Před rokem

    If you get the error "cannot import name 'BatchNormalization' from 'keras.layers.normalization' (C:\Users\RAVI\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\layers
    ormalization\__init__.py)"
    then use from tensorflow.keras.layers import BatchNormalization
    then use "from tensorflow.keras.layers import BatchNormalization" instead

  • @ravimehta714
    @ravimehta714 Před 2 lety

    by Compiling
    history = cnn_model.fit(x_train, y_train_one_hot, epochs=50, validation_data = (x_test, y_test_one_hot))
    I am getting error....Please suggest

  • @saivarun7298
    @saivarun7298 Před 2 lety

    At x= dense i am not able to use dropout. its showing keyword error. any solution

  • @Antonio-lu2vo
    @Antonio-lu2vo Před 3 lety

    the code crash after read only the first two for? why?

  • @dr.aravindacvnmamit3770

    Dear Sir I have solved my previous error thank you. But am facing this Error-acc = history.history['acc'] ??? Can you tell me Why.
    I saw the cnn_model.compile(optimizer='rmsprop',loss = 'categorical_crossentropy', metrics = ['accuracy'])

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety +1

      Looks like you solved this error but in general if you define metrics as 'acc' then it is stored as 'acc' in history. In the new version of keras you cannot mix 'acc' and 'accuracy'.

  • @ebrahimahmedal-rahawe3161

    Great effort sir,thanks a lot..
    My question is: can we plot ROC for such multiclasses? If so, how? Otherwise, what is the metrics applicable rather than acc?!
    Thanks a lot sir..

  • @pareedhijain5295
    @pareedhijain5295 Před 4 měsíci

    can we use CNN for numerical datasets

    • @DigitalSreeni
      @DigitalSreeni  Před 3 měsíci

      Yes, but I wouldn't recommend it. There are much better approaches for structured data.

  • @kannanv9304
    @kannanv9304 Před 3 lety +1

    @4.06......Why not live on the edge?........My take away......

  • @anirudhank6337
    @anirudhank6337 Před 3 lety

    "I think Random Forests did a better job than a Human in classification " LOL..XD 25:37

    • @DigitalSreeni
      @DigitalSreeni  Před 3 lety +1

      Machines are always better than humans at boring jobs. We tend to get bored after a while and get sloppy at our job.

    • @anirudhank6337
      @anirudhank6337 Před 3 lety

      @@DigitalSreeni agreed .. 👍

  • @rv0_0
    @rv0_0 Před rokem

    Title should be "DigitalSreeni trying to built build a crappy neural network model but failed"

  • @centralprocessingunit7431

    the title is quite misleading.
    this is convolutional neural network and random forest,
    not convolution and random forest as suggested by the title.

    • @DigitalSreeni
      @DigitalSreeni  Před rokem

      Can you please let me know what exactly is misleading so i can correct it? I do not see the confusion so trying to understand how others can misinterpret my intentions. Also, the title screen should help summarize the topic, hopefully.

    • @centralprocessingunit7431
      @centralprocessingunit7431 Před rokem

      @@DigitalSreeni
      the title is misleading as convolution is an independent topic to neural networks.
      so i got the sense that the only machine learning model going to be used in the video is random forest,
      but adding the neural network just makes it completely different.
      from the video title, one could expect the structure to be
      convolution + random forest --> random forest
      instead of
      convolution + neural network --> random forest

  • @yoyomcg
    @yoyomcg Před 3 lety

    my nigga sreeni makes good ass shit