{"id":21693538,"url":"https://github.com/kleinyuan/tf-blocks","last_synced_at":"2025-04-12T10:40:27.543Z","repository":{"id":87912039,"uuid":"103770742","full_name":"KleinYuan/tf-blocks","owner":"KleinYuan","description":"Building blocks of tensorflow architectures","archived":false,"fork":false,"pushed_at":"2019-10-14T00:51:53.000Z","size":49,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T05:33:10.223Z","etag":null,"topics":["cnn","tensorflow","training"],"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/KleinYuan.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-16T17:28:34.000Z","updated_at":"2019-03-06T02:18:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"7655d638-c005-46ef-963d-f38db67bc446","html_url":"https://github.com/KleinYuan/tf-blocks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KleinYuan%2Ftf-blocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KleinYuan%2Ftf-blocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KleinYuan%2Ftf-blocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KleinYuan%2Ftf-blocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KleinYuan","download_url":"https://codeload.github.com/KleinYuan/tf-blocks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248556568,"owners_count":21124141,"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","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":["cnn","tensorflow","training"],"created_at":"2024-11-25T18:20:40.490Z","updated_at":"2025-04-12T10:40:27.534Z","avatar_url":"https://github.com/KleinYuan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Announcement\n\nTo further increase the scope of this repo, the original `KleinYuan/cnn` repo has been deprecated and\nsaved in this [branch](https://github.com/KleinYuan/tf-blocks/tree/master-deprecated).\n\nThe scope of this branch has been extended to `tf-blocks` since Jul., 2018.\n\n# 1. TF-Blocks\n\nThe scope of this repo is to provide a modularized architecture of tensorflow project so that\nyou can put more focus on each individual part more independently.\n\n\n### 2.1 Motivation\n\nSince tensorflow is a Symbolic Programming framework, quite different than Pytorch or Caffe2,\nthe computation, neural network architecture and training are totally four independent things!\n\nTherefore I separate them into following four parts and also provide template module for each of them, \nas well as different other implementations such as CNN, RNN, ... etc. so that you can refer to to develop\nyour own ones. That's why I cal this repo `tf-blocks`.\n\nI used this repo as basis for my actual daily researches to speed up prototyping and try my best to put everything\nin a way of production ready quality.\n\n**If you like it, please star it!**\n\n**If you wanna contribute, feel free to submit Pull Request to make it better!**\n\n\n# 2. Components\n\n### 2.1 Graph Computation\n \nI separate the computation part and placeholder the actual network architecture  so that when you need to investigate/develop\nthis part, you don't need to mix the improvements on graph computation with the network.\n\n\n### 2.2 Network\n\nNetwork is all about architecture and you may need to follow some constraints so that the graph module can be compatible\nwith this module. However, it's constructed in a way that you truly can just focus on the architecture.\n\n### 2.3 Training\n\nWhile you have network/graph computation done, all left is how you wanna train it, including:\n\n* Which device you wanna run it? (CPU/GPU/Multi-Towers)\n\n* How you wanna manage the data feed in/batch?\n\n* How to config the tensorboard summary display?\n\n\n### 2.4 DataGenerator\n\nThis part is all about data:\n\n* How to load data from file path?\n\n* How to pre-process the data?\n\n* How to set the ratio of data?\n\n\n# 3. Run Example App\n\nThe scope of this repo is to make it way easier to build a customized training app which you can focus\non separate part.\n\nFor demo cases, I made a CNN base neural network pipeline with MNIST dataset API (cuz it's just free).\n\nThe demo app is composed of:\n\n```\n/apps/cnn_training_app.py\n/config/cnn_config.py\n/models/cnn_net.py\n```\n\nBasically, you can run it with:\n\n```\n# Navigate to /tf-blocks/\n\npython apps/cnn_training_app.py\n\n```\n\n# 4. How to develop your own training app?\n\n0. If I am lazy\n\nJust look at how those two scripts do and mimic them:\n\n```\n/apps/base_training_app.py\n/models/base_net.py\n```\n\n1. Create a Model\n\n```\ntouch /models/${fancy_name}_net.py\n```\n\nThen create a class inherent from `core.base_net.BaseNet`, finish the network architecture wrapped up in\n`define_net` function.\n\nNotes:\n\n* You need to update `x_pl/y_pl/is_training` three tf placeholders.\n\n2. Create a training app\n\n```\ntouch /apps/${fancy_name}_training_app.py\n```\n\nThen create a class inherent from `core.base_data_generator.BaseDataGenerator`, finish the data loader with your own setup wrapped up in\n`load_data` function.\n\nLast, add the code below:\n\n```\n\ndef main():\n\t# Config logger\n\ttf.logging.set_verbosity(tf.logging.INFO)\n\tlogger = tf.logging\n\t# Initialize Four Modules: Data, Trainer, Net, Graph\n\tdata_generator = ${fancy_name}DataGenerator()\n\tnet = Net(config=config, logger=logger)\n\tgraph_model = BaseGraph(net=net, config=config, logger=logger)\n\ttrainer = BaseTrainer(graph_model=graph_model, config=config, logger=logger)\n\t# Run Training\n\ttrainer.train(data_generator=data_generator)\n\n\nif __name__ == \"__main__\":\n\tmain()\n```\n\nNotes:\n\n* You need to update `train_data/val_data/test_data`, each of which is a dictionary with `x` (data) and `y` (label)\n\n* Create a config file if you need under `/config/${fancy_name}_config.py`\n\n3. Run Training!\n\n```\npython apps/${fancy_name}_training_app.py\n```\n\n# 5. Examples\n\n**Architecture**             |  **Graph**\n:-------------------------:|:-------------------------:\nCNN| ![CNN](https://user-images.githubusercontent.com/8921629/42332548-1c64c040-802d-11e8-8ab3-14ea4758099c.png)\nRNN | ![RNN](https://user-images.githubusercontent.com/8921629/42332535-145d11d6-802d-11e8-880b-891cabbd63a5.png)\nGAN | TBA\n\n# 6. Todo Items\n\n- [X] Adding RNN example\n\n- [ ] Adding GAN example\n\n- [ ] Adding a generic inference app","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkleinyuan%2Ftf-blocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkleinyuan%2Ftf-blocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkleinyuan%2Ftf-blocks/lists"}