Contrastive Learning for Image Classification | DataHour by Ashok Srinivas Darsi

Analytics Vidhya · Beginner ·👁️ Computer Vision ·3y ago

Key Takeaways

The video demonstrates the use of contrastive learning for image classification, introducing the concept of contrastive loss and its application in self-supervised and supervised learning scenarios, using tools such as ResNet, MLP, and TensorFlow.

Full Transcript

yeah we do have some pre-trained techniques familiar assign there is a free Trend model in hugging phase API you can explore that as well I can share to those links uh maybe after the session lalit is asking about uh the collab notebooks for contrast to learning yes you can use collab notebooks uh again but there is a limitation in collab notebooks I guess if the limited if you cross the if you cross that limitation I guess you won't be using GPU but I prefer you to use scaggle numbers because that will be super easy to try the model some GPU I personally use Capital notebooks if in case I wanted to train my model on GPU then collab but if you are comfortable with collab please go ahead with that thank you what have some limitations that uh depends upon you like which is more suitable for you uh so George is asking about um uh what okay so George this is not a demo Workshop basically I'll I'll try to uh I'll try to cover all the aspects of contrast to learning I'll also walk you through the code because I have some kind of uh sir can you sorry uh sorry to interrupt sir can you try once again yeah sure definitely yeah I'm able to share my screen now thanks yeah sorry for the problem actually this is the first time I am hosting the meeting so that's no problem I think no issues no issues no yeah not a problem at all so yeah just a minute I just uh share my screen let me know if in case you're able to view my screen or not can somebody because I couldn't see the chat uh please unmute yourself and let me know if in case you are not able to see my screen can you confirm uh can you hear me yes we can thank you thank you foreign so I'll just start from the beginning sorry for the issues so thank you everybody thanks for joining this session uh in this session I am going to talk about contrast to learning uh for image classification uh in this session we're going to see how the contrast to learning helps us to improve the model performance in image classification so before jumping into the topic sorry if I cough in between uh I'm having a sore throat uh so before jumping into the topic my name is Ashok I'm a senior data scientist at PayPal I have around eight years of experience in machine learning and data science and I'm actually deal with predictive analysis recommendation natural language processing and computer vision and I'm currently pursuing my masters from IIT jodhpur so coming to the table content here in this session we are going to see a brief about contrast to learning concept and we will see uh the training procedure involved in that and also I'll introduce you a new loss call contrast to loss because so far we have seen a cross entry field of classification but in this session I'll introduce a new loss called cross cross tool was followed by a Code walkthrough and in the end of the session we can have a q a as well so uh coming to the contrast to learning so contrast to learning is a representation of a data in a such a way where the similar data points will have a similar representations and the dissimilar ones will have a different representations in the embedding space for example when you take the image classification where you have two different classes uh class one is cat and Class 2 is talk now if you apply contrast to learning on top of the data we have and come up with certain representations and if you want to compare these representations of data points under class CAD then you will see a certain similarity between these two representations but when you try to compare the representation stuff of cat with the representations of a dog you will see there is a huge difference between these two representations so ultimately contrast to learning is trying to pull the data points together those who are having similar representations and also it will push the data points far from each other whose representations are totally different so by doing that it will be easy for us to Cluster the data points or classify the data points because we are having a totally different representations based on different clusters or different classes so now we understood that using these representations it will be easy for us to perform some Downstream tasks like classification or clustering or image detection or segmentation but the question raises like how exactly we can create these representations now let's take an image into consideration let's take a cat image and call it as an anchor and I'd also assume that this image has been taken from a certain cluster now we will transform this particular image into two different images by applying a transformation called T and p dash so when I say A transformation you can assume it as a kind of augmentation so you can apply any kind of augmentation like a flip rotation or blur so you can apply any kind of augmentation but our ultimate goal is to create two different images from a single anchor which we have so basically this is the anchor and these two are the augmented images so once you have the augmented images then we pass those augmented images to a certain function called f so when you pass this augmented image to the function the function f will give us an output called H sub I and H sub J so H sub I and H sub J are the representations of these two images so now once you have the representations we pass those representations to the another function called Z and also Z will also give us a output let's say Z sub I and Z subject so now once you have these representations and now our ultimate goal is to improve the similarity between these two representations sorry so when you try to improve the similarity between these two final representations then our representations will be so similar for those images which are drawn from a single particular cluster or single particular class since these two images are drawn from a single anchor when we try to improve the similarity between these two particular images uh when when we try to increase similarity between these two representations then the representations of these two particular images will be so similar so coming to the function the function f is nothing but resnet so I guess most of you guys might uh know about this so uh this resnet actually will be used to train our classification models um uh it gives certain embeddings for us or a kind of features so function f is a resnet and function Z is a MLP which is a multi-layer perceptron so now what happens when we pass the images with the resonator let's not gives certain representation based on the pre-trained information it has and these information will be passed to the multi-layer perceptron and multi-layer perceptron will give us another set of representation and finally we try to increase the similarity between these two in such cases during that process our weights of multi-layer perceptron and resnet will be adjusted in a such a way where the representations will be so similar for those images who are having who are uh who uh who who like uh these who those emitters who were drawn from this similar cluster so now um as you can see uh these particular images are drawn from this particular uh image anchor and now when you try to increase the similarity the representation representations will be so similar and the weights of resonate and MLP will be Ester we will learn more about this particular process uh when I talk about the training processor uh so before going to the training process we'll look at the page selections so page selections uh is very important for us because using the page selection we'll be creating our training data so as you can see here there are two types of page selections one is self-supervised contrast tool learning approach under one is supervised contracts to learning approach so self-supervised contrastful learning approach is used when there is a no uh targets when there is an options of targets and supervised contrastful learning will be used when uh when you know the targets so now let's go to self supervised contrast to learning where initially we will take a particular image and we'll consider that as an anchor and now we augment this anchor and create a new uh image called post to sample since we are drawing this or we are deriving this positive sample from this anchor it is wise to assume these two coming from these two messages coming from a single cluster and we consider them as a positive samples so since we already have a positive samples now we need to create the negative sample set and uh we don't have the label information so what we will be doing we will be randomly selecting the images from the batch we have and we will consider them as a negative samples once the positive samples and negative samples are generated then we will apply this we will perform the same result that we have seen we'll pass those uh paired informations to the resnet and MLP and finally try to create uh the similarity between them we will try to increase similarity between the similar images during that process we will end up creating a representation for each and every image we have in a batch and this process will be done for each and every batch we have so but there is one limited self-supervised contrast to learning which is when you randomly draw the image samples for the negative samples then we may end up having a positive sample in the necklace samples which will create a lot of confusion in the representations this adds an error in the representations but this is the limitation we have but when we try to pass this representations to the downstream task like the classification or clustering or image segmentation or image detection then these error will be reduced using using those Downstream tasks in neural networks now coming to supervised contrast school learning unless unless unlike a self-supervised contractual learning we we will be having labels over here so we won't be having any limitations that we have faced in self-supervised contextual learning so we can easily uh able to create pairs with the label information and we can easily able to uh generate the negative samples as well using label information pairs are generated then we will again use the same processor that we have discussed over here and we will generate the representations since there won't be any limitation since our page are drawn based on the known information which are labels then our representations will be so pure and we can easily be able to use them for the constant so now coming to the pay Selections in supervised contrast to loss uh we can only create one positive sample because of lack of labors and can create a mini Network samples where randomly selecting it but in supervised contrast to loss we can have many positives and many detectives because we we know the target since we know the target we can easily go ahead and pick as many number of positives and as many number of negatives based on the path size we have now coming to the training processor here we have three different types of trainings one is a supervised learning which everybody knows I guess most of you also know and under one is self-supervised contrast to learn another one is supervised contrast to learning so supervised learning is naturally used uh in our real time words uh real-time world and it's a traditional way of classifying the images where you pass a certain image and uh to encoder and you classify them using a cross entropy loss so since it's a very traditional way of classifying the image I'll not focus more about this particular thing because our major topic is contrastful learning so I'll focus more on these two training processors so in contrast to learning there are three major steps one is data augmentation encoder Network and production Network so in sales supervised contrast to learning we need to do data augmentation because we don't know what is the label so in those cases like I mentioned in the previous slide to create the pairs we need to have an anchor and we need to create a positive sample so for that we need to create an augmentation we need to augment the anchor and create a positive sample so for self-supervised contrast to learning we have to create a documentation but in supervised contrast to learning we don't need to do any kind of augmentation even though you want to you can and but uh mentally we won't be needing any uh data augmentation to create this patch because we are already know the labels we can draw positive samples from the same Target and also we can run into samples based on the label information now once the pairs are generated we will be passing these pairs to the encoder Network Network and this represent this gives us certain representations encoder network is nothing but a kind of rest net which we discussed before uh the function f and this resnet will give us certain representations based on the uh previously learned weights and that representations will be passed again to the production Network so now this production network is nothing but the MLP multi-layer perceptron and the representations of encoder will be passed to the production Network which is MLP and production Network again gives a certain another set of representations of images now these representations will be used for contrast to loss like we we pass these representations to the contrast to loss because when I mentioned contrast to loss it is purely depends upon the contrast to learning approach so I'll talk about this contrast to loss but I'll tell you like what exactly this contrast will last us so when you pass this representation with the representation of the contrast to loss it tries to increase the similarity between the images similar images and it tries to decrease the similarity between the two different images So based on that concept we will be training our model we will find our encoder model we will adjust our encoder model basically because in this case we are using resnet so resnet already has certain pre-trained debates but that is not purely trained on our use case on our labels so what we do we use contrast to learning and will create certain representations which is suitable to our use case so contrast to learning does that so in supervised contrast to learning we know the labels so we accordingly increase the similarity for those images which are taken from a single class and will decrease the similarity for those images which are taken from a different class so once the timing is done once uh the training is done then we will have a representations according to the labels we have then we will pass those different representations for the downstream task in our cases in our case it is a image classification so we use representations that we have and we'll pass to some dense layers and finally we use cross entropia on top of it and we'll classify the image so in supervised contrast to loss here we are using contrast to loss initially to create the representations and at the end we will be using cross entropy to classify the image so one more thing to highlight over here is it is not only used for image classification you can use the representations for any kind of problems we have we can use for image detection we can use for image captioning you can use for image segmentation which so it can be used in any use case like it can be used to solve any kind of problem so finally we will apply cross entropy and we will um we will classify that image so these are all about the training processor now we will see what exactly a contrast to losses because we are we were discussing a lot on increasing the similarity and decreasing the similarity based on the um uh images that we have drawn from a single cluster and also on all the all of those things right so we'll just uh see like what exactly these loss is all about and how we will increase the similarity and how we will decrease the similarity so we have two different losses over here one is a sorry one is a supervised contrast to loss and a self-supervised contrast to loss another one is a supervised contrast to loss so if you look at these two losses um both the formulas are little similar both the equations are a little similar but supervised contrast two loss is the extended version of self-supervised contrast to loss so I'll talk about these two and also tell you like what is the major difference between these two in a while uh but first of all we'll try to understand what exactly this losses uh about so now as you can see here uh we have in numerator we have Z sub I and Z sub j z sub I is nothing but the anchor representation and Z subject is nothing worthy positive sample representation so since we have self supervised contrast slow since we are talking about self-supervised contrast to loss we only have one positive sample like we discussed before which is uh one anchor and one positive sample so we'll try to understand the similarity between anchor and positive sample and we'll try to increase that similarity and the denominator is rest of the things so we'll try to check the similarity between anchor and the rest of the negative samples and we'll try to reduce the similarity so the numerator is supposed to be higher and the denominator is supposed to be lower and we have a negative symbol which can be used for loss the higher the numerator uh the lesser the loss will be so now in this way we'll be able to uh increase the similarity of a similar image and decrease similarity of two different images and exponential energy are the normalization normalization constant T is nothing but the temperature in implementation we'll pass some value to this so that we can normalize the values and exponential is another normalization constant we will just normalize the value we will be getting from the dot product of these two and coming to supervised contrast to loss here uh the only difference is this particular part when I mentioned supervised contrast to loss that means we know the label information so when you know the label information like we discussed before there can be many positives and many negatives so when we have a many positives and many negatives we have to adjust the loss functions according to that so for that reason what we are doing we are introducing this particular condition which says the label of P equal to label of I so when you look look at this numerator it says any representations whose label is whose level is equal with the T then we'll increase that if you take this Z sub by if in case the Z sub by label is equal to the Z sub P level then we will try to increase that particular plasma Latin if not we will write this so whatever like if all the if the label is similar then the numerator will try to increase the similarity if it is not similar then the denominator will be uh will try to decrease the similarity similarly we will have a higher numerator and lower will have a low denominator and uh remaining everything is constant so the only difference between these two is here in this supervised contrast to us we are passing some label information it's a kind of prayer knowledge to the loss function so this is how we create the contrast to loss uh equation and we'll be using this particular loss in our training position so I'll quickly walk you through the code let me just share my screen another I'll just stop my screen share I'll share the another window um uh just you're able to view my screen right yes we are able to see yeah yeah so here I have two different experiments the first experiment is a traditional way of classifying the images where we use our resonant and we will create a classification layer on top of it and another one is using contrast to learning so first we will see the traditional way of approach and we will observe the test accuracy and also we will see the contrast to learning approach and we'll absorb the test accuracy now um the first cell I am just putting all the libraries that I need and in a second cell I'm just loading the data here the data I am considering is c for 10 with a 10 classified with 10 classes um and the input shape is 32 cross 32 across three three dimensional array we have and sorry and we are spilling the data into two different parts one is for training and there is one another one is for testing uh training data contains around 50 000 images and the testing data contains around 10 000 images so once the split is done then we are augmenting our data and before the augmentation and normalizing the data because it is important in deep learning for us to normalize that data to converge the things faster and uh after that I'm using some random augmentations uh so that we can add some error and we can avoid the overfitting so I'm just adding a layer kit augmentation layer after that I'm creating an encoder what I'll do I'll just quickly open the training process so that you can easily able to correlate so initially we have this encoder Network so I'm just trying to create this encoder network over here so in encoder I'm using resnet so here you don't need to only stick to restaurant you can use any kind of free Trend words if in case you want to go for some Advanced pre-trained models like efficient or something you can use it not a problem at all so here I'm just using investment 50 and resnet 50 will give us certain embeddings based on the previous uh previous uh based on the previous learnings and we pass the input to the data augmentation initially so if if you can see here and create an input layer and I'm passing those inputs to the data augmentation that you may that gives me your augmented images and those augmented images are passing to the rest net which gives me certain output now that output I'll be passed as an uh you know features so as you can see here let's go to the summary of the model I'm passing the image uh having a shape of that 2 cross the 2 cross 3 and the rest not gives me uh 2040 at different dimensions and I'll be using these dimensions for my classification and also coming to some of the hyper parameters I'm using I'm using learning rate batch size hidden units number of epochs and dropouts so learning rate is 0.001 and the number of epoxy is equal to 15 and the hidden units are 5 12 and the bad this is 32 and now uh coming to the classification layer I mean I'm just creating a function for classification model uh this is a traditional way of handling the image classification as you can see here first I'll create an encoder and I'll add a classification model on top of it that is what I am doing here because it's a traditional way of classifying the images so in this classifier what I am doing I'm just keeping the layers for training because we need to adjust the layer weights according to the Cross entropy loss we have according the targets we have so I'm just keeping the trainable equal to true and like I mentioned I'm just taking the features from encoder which is around 2048 different dimensions and then and I will be passing those features to the dropouts and some dense layers and the uh for densely I'm using a activation layer as a relu activation equal to value for this dense layer and at the end I'll be having another dense layer with activation softmax since it is a multi-class uh problem we need to use softmax and at the end I'm using Optimizer as atom and the loss is fast categorical cross entropy and the Matrix is past cultural accuracy so we have we have created the classification model now what we do we just need to train the model as you can see here I am just initializing the encoder and then coder values will be passed to the classifier and the classifier model has been created and if you see the summary of the classifier model initially we are passing the input and that input will be passed to the encoder which gives us 2048 different dimensions and those only 48 dimensional will be passed to the classification layers and the tens layers we have and finally we'll be having 10 different outputs uh one probability for each class now we'll be training this data uh for 50 epochs and as you can see here Infinity I'm passing external white train and uh the training has been started and actually I just um I I executed all these things before because it takes a lot of time for us uh I execute this on GPU so it took some time for me and at the end of 50 epochs we have the test accuracy as 80.5 percent now this is a traditional way of solving the images which most of you might know about this now we will look at the implementation of contrast to learning and I will see how we can Implement and how that can affect the results so initially I'll just install the tensorflow add-ons because uh to build the supervised contrast tool loss function and with the tensorflow add-ons because that has certain libraries that we need and I'm importing the libraries that I need and I as we did uh earlier uh I'm loading the c510 data here what I'm trying to do for comparison I need to make sure everything is same in both uh both the experiments so I'm just taking the same data over here as well and the number of class equal to 10 and the input shape is same as before and the training data contains 50 000 and testing data contains 10 000 different data points and again I am doing the data documentation adding an optimization layer in uh an organization layer before and having some augmentation layers after that and once that is done now we need to build a loss function which is a supervised contrast tool loss so this is the loss function that we'll be using I'll just quickly help you understand what exactly happening inside this so like let me show you the equation uh parallely so like I have mentioned uh there is one major difference between these two which is passing the labels and also we have something called dot product of representations so for this particular equation we need two different parameters one is representations another one is label and also temperature constant so now as you can see here we are passing One Way parameter which is temperature and also two different uh the parameters one is labels another one is feature yes so these feature lookups are nothing but the representations and now we'll perform some math multiplications and pass the Logics to the end pair loss so n pair loss is nothing but the loss of self-supervised contrast to learning so in self super uh so like I mentioned uh here the major difference is uh passing the labels so I'm just passing the labels to it and along with the logins we have so here uh what happens this particular loss function will take at about the similarity it will just increase the similarity for those images which are more similar and it will decrease the similarity for those image which are totally different from each other so this loss function will help us with that and now we'll create an encoder uh let me open the architecture again so we will create an encoder uh here as you can see again I'm using resnet 50 and I'm passing the inputs to the data documentation part and that gives me some augmented images and those images I can pass to the resonant that gives me an output now there are few more parameters in this apart from the uh hyper parameters that we have used earlier in the experiment one which are production units which is 128 and the band size is changed because uh here um from the paper uh um I learned that higher the batch size the higher the Improvement because if you increase the Basset then there will be many positive Pairs and many negative pairs to create so it is good to increase a bad says previously we used batches equal to 32 and here we are having a batches equal to 65 though it consumes certain memory with respect to CP and GPU but it is uh always good to use a higher batch size and you can play with this hyper parameter so I'm actually taking the very basic hyper parameters I haven't do any kind of hyper parameter tuning uh just for the experimentation purpose I have to I have randomly taken certain hyper parameters but if in case if you want to learn more about this particular contrast to learning and want to see the capacity of this particular thing then you can play with this hyper parameters as well you are welcome with that you can do certain Web projects with that too coming to the uh some uh summary of the model uh we have we are passing the input and we are having a 20 48 different dimensions from the resident and now we will be creating another Network called production Network like I mentioned uh in this particular slide we have three different parts one is data documentation encoder and production and network so these two are already done now we need to create a production Network so that we can train this particular model using contrast loss so I'll be creating a production head over here so here we are passing the encoder input uh we're passing the input to the input and the encoder input will be taken as a features and now we will just concatenate both encoder and production head so that we can train our model so as you can see here I am initializing the encoder part and the encoded information is passed to the prescription head but the major thing that you need to notice over here is the loss is changing over here the loss is supervised contrast to loss uh Optimizer is atom as always but the loss is changing uh now I want to take you to the loss again because uh here um in the summary as you can see we are passing the input and the input is passed into the encoder which is giving 20 48 dimensions and uh when you pass those encoder outputs to the production Network it gives you 128 different dimensions so these create metrics 128 array will be passed to the supervised contrast to loss so the feature vectors which I mentioned over here as the representations those are coming from the production head so as I mentioned earlier in the training processor the representations of production network will be passed to the contrast to loss so the same way here also in the implementation the feature vectors are coming from the production Network as you can see here these 128 Dimensions will be passed to the supervised contrast to loss so now uh once the model is initialized then we'll start the model and I have chose 50 epochs for this and we are passing the features I mean image arrays and also the labels uh the reason I'm passing the label because the supervised contrast to loss needs the label information so I need to pass the labels as well so now we will initiate initialize the training procedure and the training has been started and if you can see the loss got reduced to 3.74 so this tells us that um we are able to learn certain representations based on the targets we have so what happens during this process the resnet will be adjusted since um we are concatenating the encoder and the production head the resnet weights will be adjusted in a such a way so that it gives us the representations according to the labels we have so now we have the representations that we need and we will pass those representations to the classification model this is the same classification architecture that I have used in the previous experiment like I mentioned before I am using the encoder layers and I'm keeping them as trainable because we you could adjust them again based on the cross entropy laws we already adjusted them using contrast tool loss but we want to adjust them even more using the uh cross entropy plus so I just kept them trainable equal to true and um we are passing the input to the encoder like I mentioned before now the adjacent representations will be taken into consideration in the previous experiment we were just using the same representations that encoder generally gives us but here in this case we are using the representations which were adjusted using contrast to loss so those representations will be used to here and now we'll be passing them to the dense layer with the railway activation and the final dense layer with the soft Max and this gives us the probability where the optimizer will be atom again and the loss function is Parts category across entropy and the Matrix is uh sparse categorical accuracy and we will start the training and the back says will be 256 and the number of epochs will be 50 and everything is similar uh we have done everything uh just like the way that we need to do it's a normal traditional way of on trending the model so as you can see after 50th Epoch and the number of epochs are 15 in in this particular case as you can see at the end of the test tax across is 81.52 so previously in the experiment one our test accuracy is 80.5 percent uh but using contrast to learning with 50 epochs uh our accuracy input from 80.5 to 80.81.52 so we can see a significant Improvement in this uh experiments uh with using some basic hyper parameters if you can tune more and if you can add more layers if you can add more documentation techniques if you can regularly regularize them better then you may end up even creating a more robust model than what I have right now so the ultimate conclusion over here is uh the supervised contrast tool learning outperforms the traditional way of classifying the images and also it can be used any in any kind of Downstream task like classification uh image detection image segmentation also it is widely used in natural language processing as well so it is good to learn the representations over here and it will adjust according to the use case we have done having a generic embeddance so that has been said now we have gone through the code as well now I'll uh I'll take few questions if you have any I'll just stop sharing my screen if you have any questions please feel feel free to ask I would like to tell hello sorry I would like to tell the attendees the attendees that there is a feedback code I have put in the whole section if you can give it it will be good good to all the attending yeah thanks Ron yeah definitely I have shared with the sample code with the team maybe the team can share those Snippets with you and also I will share the um research papers that I have considered to put together this concept maybe people can share that as well if I'm not wrong you can share with them right if I'm not wrong I guess I have involved everything in that Tech I have shared with you okay the main right yeah male male okay I can share here but um yeah let me let me try sharing the Snippets that I have yeah I can share it here right yeah in the third section maybe yeah yeah I shared the code Snippets with you and I'll also try to share the research papers sorry I might have missed it can you please uh post your question again if you don't mind oh okay there is a separate session cool what are the data augmentation I'll just go from one uh I guess that I didn't check this Q under path I'll just go one by one what are the data augmentation techniques for similar kind images in different classes uh you can try there are a lot of augmentation techniques we have uh it's not like you can just follow one certain other documentation every time depends upon the type of data you have and the domain you have so you can try multiple techniques like uh blur blurring the images or already in the image it really depends upon how the quality of images you have what kind of quality FMS you have and coming to the other question what are the data augmentation techniques first similarly seems like the same question similarity between H and HDI also maximized okay let me let me go to slide four um and I'll try sharing my screen again so I guess you're talking about hi and HJ right yes so when you try to improve the similarity between these two uh and these two will also be adjusted once if you like it's a kind of um back propagation here also uh like function f and g will also be adjusted if those are if those are adjusted then h i and H will also be adjusted and let's go to uh the question no it's just it's not a high Dropout basically 0.5 is normal according to my knowledge maybe you can try with different reports as well maybe you can go for 0.2 or 0.02 I already shared the notebook and I'll share the PPT as well in a while you can do sentiment analysis as well uh ultimately whatever the use case it might be you need certain representations based on your target so you can go ahead with sentiment analysis for images I'm not sure what kind of problems you're talking under telecommunication uh but if it is purely related to machine learning yes you can you can use it uh Dinesh Singh uh coming to contrast to loss um like I mentioned before classification when can be one uh use case clustering can be another use case image uh image segmentation image detection can be another use case like um uh somebody mentioned rikesh has mentioned sentiment analysis for images you can do that also these are some of the uh best examples that I can give right now but uh according to your problem I'm sure you can use those contrast to Lost anybody even for a structured data for everyone else so if you have highly imbalanced data that can also work over there for fraud detection or recommendations no matter what kind of problem it is embeddings are always needed so you can use contrast to loss over there as well I guess you asked multiple questions uh can this found in the problems in Hardware authentication so Sonia that can you just give more information about that what about this what kind of data you will be considering and whether it's a classification or something can you just give more information about this I'll just wait for your question again uh somebody asked on cheggle probably 20 21 there was a competition to find similar images from the webshop put it a valid approach to use compassion yeah yeah definitely you can definitely use uh you can try contrast to loss and you can find out the similar images as well foreign sorry for coughing a lot I shared the PPT thanks Kishore I'll just wait for a couple of minutes maybe if anybody has any other questions maybe you guys can post it over here okay just do I need to type the answer over here so because I could see an option to type the answer do I need to type the answer but I told it vocally that's okay right that's fine okay cool that the guys are said Thank you and all right yeah makes sense makes sense I will uh quickly share the research links as well research paper links with these people [Music] so this is one of the research paper that you can find on supervisor attach tools Ashok sir you are all mute I think yeah sorry I was talking sorry about that okay so yeah I did somebody said that PPT is and core are codes are not visible um I'll just check once definitely the link that you sent right now right those are research paper links but I already shared the files with them let me cross verify from my own I could see I could see them uh do I need to share them again do that also if we can't see maybe you can see right now yeah John if you're not able to see her let me share them again please acknowledge if you're able to do them thanks for confirming John can you confirm as well thank you um it just seems like uh nobody has any questions maybe I guess uh we can then drop off I guess okay then I'll thanks a lot Ashok uh yeah on the behalf of analytics with the I would like to thank you for delivering such a wonderful session uh I'm sure that everybody is insightful and hopeful that uh so that we can conduct some more sessions with you in the future uh the LinkedIn ID of Ashok is present in the chat window if uh everybody can see it right there I hope you and I hope that you have filled up the feedback for and if you are not build it uh please uh feel it because it helps us to conduct more such sessions uh if you if you wish to conduct a webinar or uh or uh or are facing difficulty in registering it connect us with that data at the rate analytics with the.com uh the recording of the session is available in two days on our YouTube channel the link is in the chat section and uh we will be back for with another session on 11th of March another data session the link is present in your side chat sections till then bye bye and keep learning thanks everyone for joining us thank you thank you very much thank you very much thanks everybody yeah bye

Original Description

In this DataHour, Ashok will explain how Contrastive Learning is used for performing image classification, For more amazing datahour session, visit: https://datahack.analyticsvidhya.com/contest/all/ Download Reference Material here: https://drive.google.com/drive/folders/142ny1-X1_7_UHq2xZ4pWiix3QI1d5WRc?usp=sharing Stay on top of your industry by interacting with us on our social channels: Follow us on Instagram: https://www.instagram.com/analytics_vidhya/ Like us on Facebook: https://www.facebook.com/AnalyticsVidhya/ Follow us on Twitter: https://twitter.com/AnalyticsVidhya Follow us on LinkedIn:https://www.linkedin.com/company/analytics-vidhya
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Analytics Vidhya · Analytics Vidhya · 0 of 60

← Previous Next →
1 The DataHour: Data Science in Retail
The DataHour: Data Science in Retail
Analytics Vidhya
2 The DataHour: Anomaly detection using NLP and Predictive Modeling
The DataHour: Anomaly detection using NLP and Predictive Modeling
Analytics Vidhya
3 The DataHour: Energy Data Science Project from Scratch
The DataHour: Energy Data Science Project from Scratch
Analytics Vidhya
4 The DataHour: Explainable AI Need and Implementation
The DataHour: Explainable AI Need and Implementation
Analytics Vidhya
5 The DataHour: Google Cloud AI/ML
The DataHour: Google Cloud AI/ML
Analytics Vidhya
6 Prediction to Production in Machine Learning #machinelearning #prediction
Prediction to Production in Machine Learning #machinelearning #prediction
Analytics Vidhya
7 Practical Applications of Data science in Ecommerce
Practical Applications of Data science in Ecommerce
Analytics Vidhya
8 How to tackle Overfitting?#machinelearning #overfitting
How to tackle Overfitting?#machinelearning #overfitting
Analytics Vidhya
9 Building Data Pipelines on GCP #googlecloud #datapipelines #data
Building Data Pipelines on GCP #googlecloud #datapipelines #data
Analytics Vidhya
10 Hands-on with A/B Testing #abtesting #datascience
Hands-on with A/B Testing #abtesting #datascience
Analytics Vidhya
11 Efficient Implementations of Transformers #transformers #cnn  #machinelearning
Efficient Implementations of Transformers #transformers #cnn #machinelearning
Analytics Vidhya
12 Modern Deep Learning Architecture #deeplearning  #architecture #deeplearningtutorial
Modern Deep Learning Architecture #deeplearning #architecture #deeplearningtutorial
Analytics Vidhya
13 Key steps for Designing Artificial Neural Network (ANN) for Image classification #machinelearning
Key steps for Designing Artificial Neural Network (ANN) for Image classification #machinelearning
Analytics Vidhya
14 5 things you should know about Azure SQL #azure #sql #datahour #datascience
5 things you should know about Azure SQL #azure #sql #datahour #datascience
Analytics Vidhya
15 AI & ML in the Automotive Industry #machinelearning #ai
AI & ML in the Automotive Industry #machinelearning #ai
Analytics Vidhya
16 Building Machine Learning Models in BigQuery
Building Machine Learning Models in BigQuery
Analytics Vidhya
17 NLP aspects in Telecommunication Industry
NLP aspects in Telecommunication Industry
Analytics Vidhya
18 Practical Time Series Analysis
Practical Time Series Analysis
Analytics Vidhya
19 Fundamentals of Quantum Computing
Fundamentals of Quantum Computing
Analytics Vidhya
20 A DAY IN THE LIFE of a Data Scientist (From waking up to working on algorithms)
A DAY IN THE LIFE of a Data Scientist (From waking up to working on algorithms)
Analytics Vidhya
21 Classification Machine Learning Model from Scratch
Classification Machine Learning Model from Scratch
Analytics Vidhya
22 Knowledge Graph Solutions using Neo4j
Knowledge Graph Solutions using Neo4j
Analytics Vidhya
23 Model Guesstimation (MLOps)
Model Guesstimation (MLOps)
Analytics Vidhya
24 ETL Pipelines in Google Cloud Platform
ETL Pipelines in Google Cloud Platform
Analytics Vidhya
25 Key steps for Designing Convolutional Neural Network(CNN) for Image Classification
Key steps for Designing Convolutional Neural Network(CNN) for Image Classification
Analytics Vidhya
26 Getting Started with AWS EC2 #amazon #aws
Getting Started with AWS EC2 #amazon #aws
Analytics Vidhya
27 How to Use Azure NLP and Graph Databases for Intelligent Knowledge Mining
How to Use Azure NLP and Graph Databases for Intelligent Knowledge Mining
Analytics Vidhya
28 Certified AI & ML BlackBelt Plus Program #shorts
Certified AI & ML BlackBelt Plus Program #shorts
Analytics Vidhya
29 Visualizing Data using Python #machinelearning #visualization #python
Visualizing Data using Python #machinelearning #visualization #python
Analytics Vidhya
30 DCNN for Machine RUL Prediction using Time-series Data #timeseries #machinelearning #datascience
DCNN for Machine RUL Prediction using Time-series Data #timeseries #machinelearning #datascience
Analytics Vidhya
31 M in ML stands for Math & Magic
M in ML stands for Math & Magic
Analytics Vidhya
32 An Unsupervised ML approach using Clustering
An Unsupervised ML approach using Clustering
Analytics Vidhya
33 Customizing Large Language Models GPT3 for Real-life Use Cases #gpt3 #datascience
Customizing Large Language Models GPT3 for Real-life Use Cases #gpt3 #datascience
Analytics Vidhya
34 Model Parameters vs Hyperparameters - Techniques in ML Engineering #machinelearning
Model Parameters vs Hyperparameters - Techniques in ML Engineering #machinelearning
Analytics Vidhya
35 Practical MLOps #mlops #datascience
Practical MLOps #mlops #datascience
Analytics Vidhya
36 Data Engineering with Databricks #dataengineering #databricks
Data Engineering with Databricks #dataengineering #databricks
Analytics Vidhya
37 Multi-Objective Optimisation
Multi-Objective Optimisation
Analytics Vidhya
38 When Airflow Meets Kubernetes
When Airflow Meets Kubernetes
Analytics Vidhya
39 AI in Banking
AI in Banking
Analytics Vidhya
40 Learn Convolutional Neural Network for Image Recognition
Learn Convolutional Neural Network for Image Recognition
Analytics Vidhya
41 Extracting Value from Data
Extracting Value from Data
Analytics Vidhya
42 How to measure Marketing Channel Effectiveness
How to measure Marketing Channel Effectiveness
Analytics Vidhya
43 Transforming Lives | Data Science Immersive Bootcamp
Transforming Lives | Data Science Immersive Bootcamp
Analytics Vidhya
44 Stock Market Analysis - AI driven approach
Stock Market Analysis - AI driven approach
Analytics Vidhya
45 Become a Data Engineering Professional in 2022 | Future Trends + Skills Required
Become a Data Engineering Professional in 2022 | Future Trends + Skills Required
Analytics Vidhya
46 Ensemble Techniques in Machine Learning #machinelearning #ensemble #datascience
Ensemble Techniques in Machine Learning #machinelearning #ensemble #datascience
Analytics Vidhya
47 The Power of Visualization | Tableau Full Course | Analytics Vidhya
The Power of Visualization | Tableau Full Course | Analytics Vidhya
Analytics Vidhya
48 Demand for Data Engineers is on the Rise | Data Engineer | Analytics Vidhya
Demand for Data Engineers is on the Rise | Data Engineer | Analytics Vidhya
Analytics Vidhya
49 Data Visualization in Data Science | DataHour | Analytics Vidhya
Data Visualization in Data Science | DataHour | Analytics Vidhya
Analytics Vidhya
50 Role of Optimization in Machine Learning & Deep Learning | DataHour | Analytics Vidhya
Role of Optimization in Machine Learning & Deep Learning | DataHour | Analytics Vidhya
Analytics Vidhya
51 Solving any Machine Learning Problem | Approach and Steps Involved
Solving any Machine Learning Problem | Approach and Steps Involved
Analytics Vidhya
52 Topic Modeling Explained with Implementation | Using LDA in Python | DataHour by Arpendu Ganguly
Topic Modeling Explained with Implementation | Using LDA in Python | DataHour by Arpendu Ganguly
Analytics Vidhya
53 Data Engineering in E-Commerce | The Best Case Study
Data Engineering in E-Commerce | The Best Case Study
Analytics Vidhya
54 Introduction to Classification using Azure Machine Learning | DataHour | Analytics Vidhya
Introduction to Classification using Azure Machine Learning | DataHour | Analytics Vidhya
Analytics Vidhya
55 Introduction to Federated Learning | DataHour | Analytics Vidhya
Introduction to Federated Learning | DataHour | Analytics Vidhya
Analytics Vidhya
56 Diffusion Models for Generative Arts | DataHour | Analytics Vidhya
Diffusion Models for Generative Arts | DataHour | Analytics Vidhya
Analytics Vidhya
57 Master Google Analytics in 1 Hour | DataHour | Analytics Vidhya
Master Google Analytics in 1 Hour | DataHour | Analytics Vidhya
Analytics Vidhya
58 Learn Hypothesis Testing | DataHour | Analytics Vidhya
Learn Hypothesis Testing | DataHour | Analytics Vidhya
Analytics Vidhya
59 A Practical Approach to Kaggle Competition | DataHour | Analytics Vidhya
A Practical Approach to Kaggle Competition | DataHour | Analytics Vidhya
Analytics Vidhya
60 Making AI work for Business | DataHour | Analytics Vidhya
Making AI work for Business | DataHour | Analytics Vidhya
Analytics Vidhya

This video teaches how to use contrastive learning for image classification, including the concept of contrastive loss and its application in self-supervised and supervised learning scenarios. The speaker provides a comprehensive overview of the technique and its implementation using popular deep learning tools.

Key Takeaways
  1. Create pairs of anchor and positive samples using data augmentation
  2. Pass pairs to the encoder network and production network
  3. Use contrastive loss to increase similarity between similar images and decrease similarity between different images
  4. Implement supervised contrastive loss for image classification
  5. Use ResNet as the encoder and adjust its weights to give representations according to labels
💡 Contrastive learning can be used to improve model performance in image classification tasks by increasing the similarity between similar images and decreasing the similarity between different images.

Related Reads

Up next
9-Phase Computer Vision Roadmap 2026 | AI & Deep Learning | #shorts
SCALER
Watch →