{"id":18556641,"url":"https://github.com/ahmdtaha/tf_learning_to_count","last_synced_at":"2026-05-18T09:11:08.129Z","repository":{"id":91930516,"uuid":"316061185","full_name":"ahmdtaha/tf_learning_to_count","owner":"ahmdtaha","description":"(ICCV2017) Tensorflow implementation of Representation Learning by Learning to Count","archived":false,"fork":false,"pushed_at":"2021-02-20T20:30:51.000Z","size":270,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-15T13:51:24.123Z","etag":null,"topics":["computer-vision","deep-learning","deep-neural-networks","machine-learning","nvidia-dali","self-supervised-learning","tensorflow","tensorpack","unsupervised-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmdtaha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-25T21:50:39.000Z","updated_at":"2021-02-20T20:30:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"5ac5c4f8-00da-4d87-8be7-1f0e76d46814","html_url":"https://github.com/ahmdtaha/tf_learning_to_count","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahmdtaha/tf_learning_to_count","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Ftf_learning_to_count","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Ftf_learning_to_count/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Ftf_learning_to_count/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Ftf_learning_to_count/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmdtaha","download_url":"https://codeload.github.com/ahmdtaha/tf_learning_to_count/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Ftf_learning_to_count/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273658574,"owners_count":25145303,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","deep-learning","deep-neural-networks","machine-learning","nvidia-dali","self-supervised-learning","tensorflow","tensorpack","unsupervised-learning"],"created_at":"2024-11-06T21:32:33.267Z","updated_at":"2025-10-04T18:57:51.234Z","avatar_url":"https://github.com/ahmdtaha.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Learning to Count\nThis is an _Unofficial_ Tensorflow implementation of **Representation Learning by Learning to Count (Lrn-Cnt).** Lrn-Cnt is a self-supervised visual representation approach. Lrn-Cnt is published 2017; it no longer achieves SOTA results. However, it is simple approach that serves as a nice tutorial for self-supervised learning approaches. Lrn-Cnt is illustrated in this [blog](https://medium.com/p/787ba421611e).\n\n\n\n### TL;DR\nThe alexnet used is [here](https://github.com/ahmdtaha/tf_unsupervised_count/blob/main/nets/alexnet.py). This alexnet version is inspired by [Zhang _et al._ [2]](https://github.com/richzhang/colorization/blob/caffe/train_alexnet/train_val_nobn.prototxt). The self-supervised representation count loss is [here](https://github.com/ahmdtaha/tf_unsupervised_count/blob/4f9d4717047f50712e46cad15d9ed09de9351fdb/nets/model.py#L199). The supervised linear classifier loss is [here](https://github.com/ahmdtaha/tf_unsupervised_count/blob/4f9d4717047f50712e46cad15d9ed09de9351fdb/nets/model.py#L120)\n\n## Requirements\n\n* Python 3+ [Tested on 3.6.10]\n* Tensorflow 1.X [Tested on 1.14]\n* TensorPack [Tested on 0.10.1]\n* Nvidia-DALI [Tested on 0.20.0]\n* Nvidia-DALI-Plugin [Tested on 0.20.0]\n\nWe use cuda 10.0.130 and cudnn v7.6.5\n\nOur TensorFlow model and loss function are simple. However, to train it *efficiently*, we needed to use [TensorPack](https://tensorpack.readthedocs.io/) and [Nvidia-DALI](https://docs.nvidia.com/deeplearning/dali/user-guide/docs/) libraries. If linking these libraries is challenging, feel free to remove them from the code and use Tensorflow only (e.g., tf.data.dataset). The requirements.txt lists all our install packages and their versions.\n\n[//]: # \"## ImageNet Pretrained Models\"\n\n\n\n## Usage example\n\nTo run the unsupervised representation-count phase \n\n`python counter_trn.py --batch_size 256 --exp_name cnt_gpu4_bz256_adam_250 --net alexnet --learning_rate 0.0001 --gpu 0,1,2,3 --logits_dim 1000 --opt adam --epoch 250 --learning_rate_var_name lr_cnt`\n\nTo run the supervised linear-classifier phase\n\n`python classifier_trn.py --exp_name cls_gpu2_bz256_adam_250 --pretrained --cnt_exp_name cnt_gpu4_bz256_adam_250 --batch_size 256 --learning_rate 0.001 --opt adam --epoch 250 --net alexnet  --learning_rate_var_nam lr_cls --gpu 0,1`\n\nThe following table compares our implementation with the paper results.\n\n| ImageNet Performance          | conv1 | conv2 | conv3 | conv4 | conv5 |\n|-------------------------------|-------|-------|-------|-------|-------|\n| Mehdi et at. [1] \\(Table. 2\\) | 18.0  | 30.6  | 34.3  | 32.5  | 25.7  |\n| Ours                          | 18.6  | 30.3  | 33.6  | 30.1  | 24.9  |\n    \n![Our implementation performance](./imgs/cls_performance.jpg)    \n\n### TODO LIST\n* highlight the image resize issue\n* highlight the I/O performance issue\n* Document the discrepancy between the paper and our implementation\n\nContributor list\n----------------\n1. [Ahmed Taha](http://www.ahmed-taha.com)\n2. [Alex Hanson](https://github.com/j-alex-hanson)\n\n* We train the unsupervised representation-count phase for 250 epochs and the supervised linear-classifier phase for 250 epochs. This leads to a long training time. If someone has an to converge faster (e.g., a better learning rate scheduler), please share through a Github issue.  \n* It would be great if someone re-implement this in PyTorch. Let me know and I will add a link to your PyTorch implementation here\n\n\n### MISC Notes\n* Our implementation is inspired by [CLVR's implementation](https://github.com/clvrai/Representation-Learning-by-Learning-to-Count). However, the CLVR's implementation has a serious bug and performance issues that need to be fixed. These issues are discussed [here](https://github.com/ahmdtaha/tf_unsupervised_count/blob/main/docs/clvr_bug.md).\n* Our implementation diverges from the paper [1] technical details. We explain this discrepancy [here](https://github.com/ahmdtaha/tf_unsupervised_count/blob/main/docs/paper_discrepancy.md).\n\n## Release History\n* 1.0.0\n    * First commit on 25 Nov 2020\n    * First code commit on 2 Dec 2020\n\n\n## References\n[1] Representation Learning by Learning to Count\n[2] Colorful image colorization\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmdtaha%2Ftf_learning_to_count","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmdtaha%2Ftf_learning_to_count","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmdtaha%2Ftf_learning_to_count/lists"}