女人内火旺喝什么降火| 什么叫弱视| 家政是干什么的| 上海市市委书记是什么级别| 眉目比喻什么| 运交华盖是什么意思| 狮子女喜欢什么样的男生| 3月什么星座| 心里想的话用什么标点符号| 朋友妻不可欺是什么意思| 公检法是什么| 104岁属什么生肖| 黄精吃了有什么好处| 什么地摇动| 与虎谋皮是什么生肖| 尿频是什么原因造成的| 无创是什么检查| 兄弟左右来是什么生肖| 灵芝孢子粉有什么功效| 芒果什么时候吃最好| 梦见蔬菜是什么预兆| 9月20日是什么星座| hyper是什么意思| 看嗓子去医院挂什么科| 为什么哭了眼睛会肿| 为什么会得子宫肌瘤| 眼睛经常充血是什么原因引起的| 溶血性黄疸是什么原因引起的| 四肢抽搐口吐白沫是什么病| 松鼠喜欢吃什么食物| 丝状疣用什么药| 短发女人吸引什么男人| 缺钾吃什么补得最快| 支气管炎吃什么消炎药| 当逃兵会有什么后果| 中间人是什么意思| 白细胞低要吃什么| 舌苔开裂是什么原因呢| 嘴唇干是什么原因引起的| 宫颈管短有什么症状| 去香港买什么划算| champion什么意思| 给男生送什么礼物好| 右侧卵巢内囊性结构什么意思| 胆囊结石不宜吃什么| 什么牛什么毛| 宫腔内无回声区是什么意思| 什么叫养生| 梦见梳头发是什么意思| 被利用的信任是什么歌| 有什么国家| 胎停了有什么明显症状| 建档是什么意思| 高血糖吃什么菜好| 百香果什么味道| 内能是什么| 人为什么会长痣| 2013年五行属什么| 打蛔虫吃什么药| 什么的朝霞| 空心菜不能和什么一起吃| 没有子宫会有什么影响| 776是什么意思| 嗓子哑了吃什么药| 阴盛阳衰什么意思| 女性血常规都检查什么| 拆穿是什么意思| 胆囊息肉吃什么药| 梦见棉花是什么意思| cnv是什么意思| 宫内小囊是什么意思| 东华帝君的真身是什么| 插画师是做什么的| 焕字五行属什么| 神经衰弱吃什么中成药| 女人梦到蛇是什么意思| 仙女下凡是什么生肖| 大姨妈来了可以吃什么水果| 浅卡其色裤子配什么颜色上衣| 梦见和死去的亲人说话是什么意思| 可乐定是什么药| 头晕为什么做眼震检查| 小孩肺炎吃什么药| 人养玉三年玉养人一生是什么意思| 什么叫通勤| 眼睛一直眨是什么原因| 伪娘什么意思| 小螃蟹吃什么| 腰眼疼是什么原因引起的| 拔了牙吃什么消炎药| 骨皮质是什么| 脑梗前期有什么症状| 六月初二是什么星座| 毛主席女儿为什么姓李| 什么是肝癌| 什么的废墟| 虾子不能和什么一起吃| 什么功尽弃| 血液生化检查能看出什么病| 天蝎座是什么象星座| 四件套包括什么| 肠炎发烧吃什么药| 鼻子毛白了是什么原因| 声情并茂的意思是什么| 多汗症挂什么科| 蒲公英叶和根的功效有什么不同| 心脏房颤吃什么药最好| eft是什么意思| 什么手表品牌最好| 白细胞减少吃什么药| 手工diy是什么意思| 耳朵嗡嗡响是什么原因| 清热去火吃什么药| 舌苔黄腻厚是什么原因| boy是什么品牌| 什么是有机奶粉| 榴莲是什么季节的水果| 缓缓是什么意思| 红蓝光照射有什么作用| 手掌红什么原因| 芸字五行属什么| 富贵竹开花什么预兆| 卧轨什么意思| 孕期小腿抽筋什么原因| 牙龈萎缩是什么原因引起的| 什么竹子| 荷叶泡水喝有什么作用| 初心不改是什么意思| 冰心原名什么| 做什么来钱快| 品质是什么| 肛周脓肿什么症状| 西施姓什么| 勾践姓什么| 曾孙是什么意思| 大乌龙是什么意思| 不成功便成仁的仁是什么意思| 68岁属什么生肖| 农历8月是什么月| 流产有什么症状或感觉| 09年的牛是什么命| 静脉炎的症状是什么| 妲己是什么意思| 三点水加分念什么| 颈部疼痛挂什么科| 99年属什么| 茂盛的意思是什么| 肿瘤是什么| 石乐读什么| 农历十月十八是什么星座| dr和ct有什么区别| 腺肌瘤是什么病| 减少什么| 江苏有什么烟| 客家人是什么意思| 02属什么| 西南方向五行属什么| 什么是羊蝎子| 梦见蛇挡路是什么意思| 得过且过什么意思| 阴部毛变白是什么原因| 做梦梦见棺材和死人是什么意思| 污蔑是什么意思| 92年出生属什么生肖| 梦见儿子小时候是什么意思| 房颤吃什么药好| ns是什么单位| 小囊肿是什么病严重吗| 脚底干裂起硬皮是什么原因怎么治| 九月份是什么季节| 老人大小便失禁是什么原因造成的| hcg偏高是什么原因| 信阳毛尖属于什么茶| 女人吃鹅蛋有什么好处| 什么病不能吃狗肉| 窦缓是什么意思| 冰箱底部漏水是什么原因| 国安是什么单位| 重庆五行属什么| aemape是什么牌子| 僵尸是什么| 孕妇喝什么汤| 吃生姜对身体有什么好处和坏处| 乳头痛什么问题| 关节炎吃什么药好得快| 胃痛可以吃什么水果| 遇人不淑是什么意思| 五点是什么时辰| 什么是发票抬头| 嗜酸性粒细胞是什么| 叶酸每天什么时候吃最好| 什么是蛋白尿| 屈光检查是什么| 低血压是什么症状| 上山下金是什么字| 猪心炖什么好吃又营养| 梦见拔牙是什么预兆| 脾胃虚寒吃什么食物好| 手脚热吃什么药| 说梦话是什么原因| 小河边有什么| 隔三差五是什么意思| 脚气长什么样| 影子代表什么生肖| 天河水是什么意思| 万劫不复是什么意思| 唇炎涂什么药膏| 尿性什么意思| 三伏天是什么时候开始| 眼睛过敏用什么眼药水| 今年是什么生肖| 1901年属什么生肖| 土猪肉和普通猪肉有什么分别| 米黄配什么颜色好看| 今天什么时候出梅| 气胸是什么| 女人为什么要少吃鳝鱼| 肠炎可以吃什么水果| 杨柳是什么生肖| 皇协军是什么意思| 世界上最长的单词是什么| 鹦鹉鱼能和什么鱼混养| 痘痘挤出来的白色东西是什么| 敛是什么意思| 为什么有些| 心脏病是什么原因引起的| 阿托伐他汀钙片有什么副作用| 便是什么意思| 118什么意思| 宫腔积液和盆腔积液有什么区别| 气血不足吃什么中成药| 泮是什么意思| 尿微肌酐比值高是什么情况| 减肥要注意什么| 干净的什么| 中央党校校长是什么级别| 鼓风机是干什么用的| 看嗓子去医院挂什么科| 小猫来家里有什么预兆| 口腔苦味是什么原因| 顾虑是什么意思| 肠胃不好经常拉肚子吃什么药| 阴虱卵长什么样图片| 玮五行属什么| 什么水果榨汁好喝| 血糖高可以吃什么主食| 磕头虫吃什么| 小肚子发胀是什么原因女性| 胃痛是什么原因| 时辰宜忌是什么意思| 风湿病是什么原因造成的| 男生喜欢什么礼物| 加百列是什么天使| 梦见很多蜜蜂是什么意思| 颈动脉强回声斑块是什么意思| 猫眼石是什么| 1964年是什么年| 女性阴毛变白是什么原因| 城镇户口是什么意思| 水奶和奶粉什么区别| 尿道炎用什么药治疗最好| 君子兰什么时候开花| 化生是什么意思| 酉鬼念什么| 百度
Skip to content

Tensorflow-Keras implementation of SimCLR: Simple Framework for Contrastive Learning of Visual Representations by Chen et al. (2020)

License

Notifications You must be signed in to change notification settings

mwdhont/SimCLRv1-keras-tensorflow

Repository files navigation

SimCLR

A Tensorflow-Keras Implementation of SimCLRv1 which allows to improve the feature representation quality of your base_model by the means of the Simple Framework for Contrastive Learning of Visual Representations (SimCLR). The provided code should allow to apply the framework to any Keras model with only minor changes.

alt text
Fig.1 - SimCLR Illustration [1]

The given implementation allowed for an top-1 accuracy increase of 17% on the linear classifier trained, with 5% of the data. Furthermore, the t-SNE plot demonstrates a clear clustering of the features according to their class, after training with the SimCLR framework.

alt text alt text
Fig.2.1 - t-SNE of VGG16-features before SimCLR Fig.2.2 - t-SNE of VGG16-features after SimCLR

It is possible to reproduce this results via the following notebook: Open In Colab

References: Paper, GitHub, Blog

How to use?

SimCLR = SimCLR(base_model, input_shape, batch_size, feat_dim, feat_dims_ph, num_of_unfrozen_layers, save_path)

The method SimCLR.train can be used to train the SimCLR_model by passing the training and validation data of the type DataGeneratorSimCLR. The attribute SimCLR.base_model keeps track of the changing base_model. The feature representation quality can be evaluated in a number of ways, see below.

Implementation

A SimCLR-class has been defined which builds a Keras SimCLR_model around the base_model. It is the aim to improve the feature encoding quality of this base_model. The SimCLR_model has (2.batch_size) Inputs of the image size and 1 matrix-output with shape (batch_size x 4.batch_size).

  1. Each of the batch_size images are transformed twice by a random image distortion (see Fig.1), giving the 2.batch_size input images. See DataGeneratorSimCLR and SimCLR_data_util for the details.
  2. These input images are passed through the base model and a MLP projection head, resulting in a feature encoding.
  3. The SimCLR_model-output is obtained from a pairwise vector multiplication between all computed feature encodings. This vector multiplications correspond with the cosine similarity, after which the similarity is passed through a softmax. Since it is the aim to 'attract' feature representations of the same image, and 'repel' representations of different images, the SimCLR-output matrix should match to [I|O|I|O], with I = identity-matrix and O = zero-matrix. For this purpose, a custom Keras-layer is defined: SoftmaxCosineSim (see notebook for intuitive toy example).
  4. A simple Keras cross_entropy-loss can be used to evaluate the difference between the SimCLR-output and [I|O|I|O].
  5. As such, the SimCLR_model can be trained and simultaneously the feature encoding improves.

Difference with official implementation:

  • Swish activation instead of relu in projection head
  • As only 1 device is used, no global batch normalization
  • Only colour distortion used with reduced color_jitter strength of 0.5 instead of 1.0. Possible to activate other distortions in DataGeneratorSimCLR.
  • Adam optimizer instead of Lars, no warmup nor cosine decay on learning rate, reduction on plateau instead.

Experiments

SimCLR has been used as a self-supervised learning approach to improve the feature encoding quality of a pretrained VGG16-network. A SimCLR_model has been built around the base_model and consequently trained on the SimCLR-task. For this, a gradual defreeze of the base model was adopted. A clear improvement of the feature representations could be observed for the downstream classification task.

Data: Trashnet

The trashnet-dataset has been used. The original dataset has been reduced to 5 classes with the following number of instances:

  • Glass: 501
  • Paper: 594
  • Cardboard: 403
  • Plastic: 482
  • Metal: 410

The original images of (512x384) have been center-cropped and reduced to a size (80x80). Data has been split in train/val/test - 70/15/15.

Note that the similar results have been observed on a private dataset, see project context below.

Evaluation

The feature quality is evaluated by the means of

  • A linear classifier (logistic regression) trained on the extracted features of the encoder
  • A fine-tuned classifier. 5 attempts are performed, the best classifier is kept.
  • A t-SNE visualization is made.

These evaluations are done for 3 fractions of the training data: 100%, 20%, 5%.

Results

The table below lists the top-1 accuracy for all cases. It can be seen that SimCLR improves the classification performance for all fractions of the training set on both the linear and fine-tuned classifier.

One can consequently conclude that the feature encoding of the base_model clearly improves thanks to the SimCLR framework.

Fraction of training set Classifier VGG16 SimCLR
100% Linear 0.79 ± 0.00 0.82 ± 0.01
Fine-tuned 0.85 ± 0.01 0.87 ± 0.01
20% Linear 0.70 ± 0.00 0.81 ±0.02
Fine-tuned 0.83 ± 0.01 0.86 ± 0.01
5% Linear 0.63 ± 0.00 0.80 ± 0.02
Fine-tuned 0.80 ± 0.02 0.84 ± 0.03

Since the results change slightly because of the stochastic nature of the optimization procedure of both the SimCLR_model and the fine-tuned classifier, the average and standard deviation over 10 runs are presented in the table above.

Project Context

This repository is part of a joined research project of KU Leuven, Sagacify and BESIX on the topic of automatic monitoring of waste containers on construction sites. For this purpose, data has been collected during a period of 5 months. Similar results where achieved on this dataset. See below for an illustration of the type of data. If you would be interested in the details of this research, please feel free to reach out.

alt text alt text
Fig.3 - Illustration of ContAIner output

About

Tensorflow-Keras implementation of SimCLR: Simple Framework for Contrastive Learning of Visual Representations by Chen et al. (2020)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
空虚什么意思 孕晚期白细胞高是什么原因 周星驰为什么不结婚 眉茶属于什么茶 前列腺炎忌口什么食物
为什么尿会很黄 颈部淋巴结肿大挂什么科 孕妇可以喝什么茶 狗咬人后狗为什么会死 鹅和什么一起炖最好吃
为什么感冒会咳嗽 芥末是什么植物 发烧咳嗽吃什么药 小孩肠胃感冒吃什么药比较好 饺子是什么意思
草单斤是什么字 什么情况下需要打狂犬疫苗 疝气手术是什么 什么食物降胆固醇最好 枉然是什么意思
子宫位于腹部什么位置hcv9jop1ns5r.cn 宰相和丞相有什么区别hcv9jop5ns9r.cn 牙发黑是什么原因怎么办0297y7.com 梦到自己拉大便是什么预兆hcv8jop7ns3r.cn 好强的女人是什么性格hcv7jop9ns7r.cn
万圣节应该送什么礼物hcv8jop3ns9r.cn 97年的牛是什么命0735v.com 为什么会腰疼hcv9jop0ns9r.cn 富贵竹开花什么预兆hcv9jop0ns1r.cn 山东登州府现在叫什么adwl56.com
阴历六月十三是什么日子hcv9jop4ns0r.cn 做b超挂什么科imcecn.com 什么是省控线hcv8jop6ns8r.cn 肩周炎属于什么科室hcv9jop7ns9r.cn 梦见红枣树上结满红枣代表什么hcv8jop5ns4r.cn
夏天喝绿茶有什么好处hcv8jop0ns1r.cn 六允读什么zhiyanzhang.com 红玫瑰花语是什么意思hcv8jop9ns2r.cn magnesium是什么意思cl108k.com 头皮屑多用什么洗发水效果好hcv9jop1ns3r.cn
百度