{"id":18001913,"url":"https://github.com/dgurkaynak/tensorflow-cnn-finetune","last_synced_at":"2025-08-01T18:08:07.098Z","repository":{"id":79251242,"uuid":"94993936","full_name":"dgurkaynak/tensorflow-cnn-finetune","owner":"dgurkaynak","description":"Finetuning AlexNet, VGGNet and ResNet with TensorFlow","archived":false,"fork":false,"pushed_at":"2021-04-11T18:39:36.000Z","size":6704,"stargazers_count":198,"open_issues_count":1,"forks_count":93,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-08T21:01:52.443Z","etag":null,"topics":["alexnet","convolutional-neural-networks","finetune","resnet","tensorflow","vggnet"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dgurkaynak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-06-21T10:47:33.000Z","updated_at":"2025-04-15T02:19:37.000Z","dependencies_parsed_at":"2023-03-14T05:00:19.909Z","dependency_job_id":null,"html_url":"https://github.com/dgurkaynak/tensorflow-cnn-finetune","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dgurkaynak/tensorflow-cnn-finetune","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgurkaynak%2Ftensorflow-cnn-finetune","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgurkaynak%2Ftensorflow-cnn-finetune/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgurkaynak%2Ftensorflow-cnn-finetune/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgurkaynak%2Ftensorflow-cnn-finetune/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgurkaynak","download_url":"https://codeload.github.com/dgurkaynak/tensorflow-cnn-finetune/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgurkaynak%2Ftensorflow-cnn-finetune/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268272734,"owners_count":24223785,"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-08-01T02:00:08.611Z","response_time":67,"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":["alexnet","convolutional-neural-networks","finetune","resnet","tensorflow","vggnet"],"created_at":"2024-10-29T23:19:16.352Z","updated_at":"2025-08-01T18:08:07.064Z","avatar_url":"https://github.com/dgurkaynak.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tensorflow-cnn-finetune\n\nThis repo is about finetuning some famous convolutional neural nets using TensorFlow.\n\nConvNets:\n\n- [AlexNet](https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf)\n- [VGGNet](https://arxiv.org/pdf/1409.1556.pdf)\n- [ResNet](https://arxiv.org/pdf/1512.03385.pdf)\n\n\nRequirements:\n- Python 2.7 or 3.x\n- Tensorflow 1.x (tested with 1.15.1)\n- OpenCV2 (for data augmentation)\n\n\n## Dataset file\n\nYou need to setup two dataset files for training and validation. The format must be like following:\n\n```\n/absolute/path/to/image1.jpg class_index\n/absolute/path/to/image2.jpg class_index\n...\n```\n\n`class_index` must start from `0`.\n\nSample dataset files can be found at [data/train.txt](data/train.txt) and [data/val.txt](data/val.txt).\n\n\u003e Do not forget to pass `--num_classes` flag when running `finetune.py` script.\n\n## AlexNet\n\nGo into `alexnet` folder\n\n```bash\ncd alexnet\n```\n\n### Finetuning\n\nDownload the weights if you hadn't before.\n\n```bash\n./download_weights.sh\n````\n\nRun the `finetune.py` script with your options.\n\n```bash\npython finetune.py \\\n    --training_file=../data/train.txt \\\n    --val_file=../data/val.txt \\\n    --num_classes 26\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--training_file` | ../data/train.txt | Training dataset file |\n| `--val_file` | ../data/val.txt | Validation dataset file |\n| `--num_classes` | 26 | Number of classes |\n| `--train_layers` | fc8,fc7 | Layers to be finetuned, seperated by commas. Avaliable layers: `fc8`, `fc7`, `fc6`, `conv5`, `conv4`, `conv3`, `conv2`, `conv1` |\n| `--num_epochs` | 10 | How many epochs to run training |\n| `--learning_rate` | 0.0001 | Learning rate for ADAM optimizer |\n| `--dropout_keep_prob` | 0.5 | Dropout keep probability |\n| `--batch_size` | 128 | Batch size |\n| `--multi_scale` |  | As a preprocessing step, it scalse the image randomly between 2 numbers and crop randomly at network's input size. For example if you set it `228,256`: - Select a random number between 228 and 256 -- S - Scale input image to `S x S` pixels - Crop it 227x227 randomly |\n| `--tensorboard_root_dir` | ../training | Root directory to put the training logs and weights |\n| `--log_step` | 10 | Logging period in terms of a batch run |\n\n\nYou can observe finetuning with the tensorboard.\n\n```bash\ntensorboard --logdir ../training\n```\n\n### Testing a dataset file\n\nAt the end of each epoch while finetuning, the current state of the weights are saved into `../training` folder (or any folder you specified with `--tensorboard_root_dir` option). Go to that folder and locate the model and epoch you want to test.\n\nYou must have your test dataset file as mentinoned before.\n\n```bash\npython test.py \\\n    --ckpt ../training/alexnet_XXXXX_XXXX/checkpoint/model_epoch1.ckpt \\\n    --num_classes 26 \\\n    --test_file ../data/test.txt\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--ckpt` |  | Checkpoint path; it must end with \".ckpt\" |\n| `--num_classes` | 26 | Number of classes |\n| `--test_file` | ../data/val.txt | Test dataset file |\n| `--batch_size` | 128 | Batch size |\n\n### Predicting a single image\n\n```bash\npython predict.py \\\n    --ckpt ../training/alexnet_XXXXX_XXXX/checkpoint/model_epoch1.ckpt \\\n    --input_image=/some/path/to/image.jpg\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--ckpt` |  | Checkpoint path; it must end with \".ckpt\" |\n| `--num_classes` | 26 | Number of classes |\n| `--input_image` |  | The path of input image |\n\n## VGGNet\n\nGo into `vggnet` folder\n\n```bash\ncd vggnet\n```\n\n### Finetuning\n\nDownload the weights if you hadn't before.\n\n```bash\n./download_weights.sh\n````\n\nRun the `finetune.py` script with your options.\n\n```bash\npython finetune.py \\\n    --training_file=../data/train.txt \\\n    --val_file=../data/val.txt \\\n    --num_classes 26\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--training_file` | ../data/train.txt | Training dataset file |\n| `--val_file` | ../data/val.txt | Validation dataset file |\n| `--num_classes` | 26 | Number of classes |\n| `--train_layers` | fc8,fc7 | Layers to be finetuned, seperated by commas. Avaliable layers: `fc8`, `fc7`, `fc6`, `conv5_1`, `conv5_2`, `conv5_3`, `conv4_1`, `conv4_2`, `conv4_3`, `conv3_1`, `conv3_2`, `conv3_3`, `conv2_1`, `conv2_2`, `conv1_1`, `conv1_2` |\n| `--num_epochs` | 10 | How many epochs to run training |\n| `--learning_rate` | 0.0001 | Learning rate for ADAM optimizer |\n| `--dropout_keep_prob` | 0.5 | Dropout keep probability |\n| `--batch_size` | 128 | Batch size |\n| `--multi_scale` |  | As a preprocessing step, it scalse the image randomly between 2 numbers and crop randomly at network's input size. For example if you set it `228,256`: - Select a random number between 228 and 256 -- S - Scale input image to `S x S` pixels - Crop it 224x224 randomly |\n| `--tensorboard_root_dir` | ../training | Root directory to put the training logs and weights |\n| `--log_step` | 10 | Logging period in terms of a batch run |\n\n\nYou can observe finetuning with the tensorboard.\n\n```bash\ntensorboard --logdir ../training\n```\n\n### Testing a dataset file\n\nAt the end of each epoch while finetuning, the current state of the weights are saved into `../training` folder (or any folder you specified with `--tensorboard_root_dir` option). Go to that folder and locate the model and epoch you want to test.\n\nYou must have your test dataset file as mentinoned before.\n\n```bash\npython test.py \\\n    --ckpt ../training/vggnet_XXXXX_XXXX/checkpoint/model_epoch1.ckpt \\\n    --num_classes 26 \\\n    --test_file ../data/test.txt\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--ckpt` |  | Checkpoint path; it must end with \".ckpt\" |\n| `--num_classes` | 26 | Number of classes |\n| `--test_file` | ../data/val.txt | Test dataset file |\n| `--batch_size` | 128 | Batch size |\n\n### Predicting a single image\n\n```bash\npython predict.py \\\n    --ckpt ../training/vggnet_XXXXX_XXXX/checkpoint/model_epoch1.ckpt \\\n    --input_image=/some/path/to/image.jpg\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--ckpt` |  | Checkpoint path; it must end with \".ckpt\" |\n| `--num_classes` | 26 | Number of classes |\n| `--input_image` |  | The path of input image |\n\n## ResNet\n\nGo into `resnet` folder\n\n```bash\ncd resnet\n```\n\n### Finetuning\n\nDownload the weights if you hadn't before.\n\n```bash\n./download_weights.sh\n````\n\nRun the `finetune.py` script with your options.\n\n```bash\npython finetune.py \\\n    --training_file=../data/train.txt \\\n    --val_file=../data/val.txt \\\n    --num_classes 26\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--resnet_depth` | 50 | ResNet architecture to be used: 50, 101 or 152\n| `--training_file` | ../data/train.txt | Training dataset file |\n| `--val_file` | ../data/val.txt | Validation dataset file |\n| `--num_classes` | 26 | Number of classes |\n| `--train_layers` | fc | Layers to be finetuned, seperated by commas. Fully-connected last layer: `fc`, tho whole 5th layer: `scale5`, or some blocks of a layer: `scale4/block6,scale4/block5` |\n| `--num_epochs` | 10 | How many epochs to run training |\n| `--learning_rate` | 0.0001 | Learning rate for ADAM optimizer |\n| `--dropout_keep_prob` | 0.5 | Dropout keep probability |\n| `--batch_size` | 128 | Batch size |\n| `--multi_scale` |  | As a preprocessing step, it scalse the image randomly between 2 numbers and crop randomly at network's input size. For example if you set it `228,256`: - Select a random number between 228 and 256 -- S - Scale input image to `S x S` pixels - Crop it 224x224 randomly |\n| `--tensorboard_root_dir` | ../training | Root directory to put the training logs and weights |\n| `--log_step` | 10 | Logging period in terms of a batch run |\n\n\nYou can observe finetuning with the tensorboard.\n\n```bash\ntensorboard --logdir ../training\n```\n\n### Testing a dataset file\n\nAt the end of each epoch while finetuning, the current state of the weights are saved into `../training` folder (or any folder you specified with `--tensorboard_root_dir` option). Go to that folder and locate the model and epoch you want to test.\n\nYou must have your test dataset file as mentinoned before.\n\n```bash\npython test.py \\\n    --ckpt ../training/resnet_XXXXX_XXXX/checkpoint/model_epoch1.ckpt \\\n    --num_classes 26 \\\n    --test_file ../data/test.txt\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--ckpt` |  | Checkpoint path; it must end with \".ckpt\" |\n| `--resnet_depth` | 50 | ResNet architecture to be used: 50, 101 or 152\n| `--num_classes` | 26 | Number of classes |\n| `--test_file` | ../data/val.txt | Test dataset file |\n| `--batch_size` | 128 | Batch size |\n\n### Predicting a single image\n\n```bash\npython predict.py \\\n    --ckpt ../training/resnet_XXXXX_XXXX/checkpoint/model_epoch1.ckpt \\\n    --input_image=/some/path/to/image.jpg\n```\n\n| Option | Default | Description |\n|-|-|-|\n| `--ckpt` |  | Checkpoint path; it must end with \".ckpt\" |\n| `--resnet_depth` | 50 | ResNet architecture to be used: 50, 101 or 152\n| `--num_classes` | 26 | Number of classes |\n| `--input_image` |  | The path of input image |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgurkaynak%2Ftensorflow-cnn-finetune","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgurkaynak%2Ftensorflow-cnn-finetune","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgurkaynak%2Ftensorflow-cnn-finetune/lists"}