{"id":16840558,"url":"https://github.com/mitmul/tfchain","last_synced_at":"2025-04-11T05:41:51.449Z","repository":{"id":141385662,"uuid":"78500723","full_name":"mitmul/tfchain","owner":"mitmul","description":"Run a static part of the computational graph written in Chainer with Tensorflow","archived":false,"fork":false,"pushed_at":"2017-01-10T05:29:35.000Z","size":1630,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T03:41:38.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mitmul.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":"2017-01-10T05:27:15.000Z","updated_at":"2018-11-14T05:34:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"8daf1109-acd7-48c5-9c4a-ed0518e64ed5","html_url":"https://github.com/mitmul/tfchain","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/mitmul%2Ftfchain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitmul%2Ftfchain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitmul%2Ftfchain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitmul%2Ftfchain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitmul","download_url":"https://codeload.github.com/mitmul/tfchain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351314,"owners_count":21089268,"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":[],"created_at":"2024-10-13T12:37:07.976Z","updated_at":"2025-04-11T05:41:51.442Z","avatar_url":"https://github.com/mitmul.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tfchain\n\nAlternative Chain implementation with TensorFlow backend\n\n# Requirements\n\n- CUDA 8.0\n- cuDNN 5.1\n- Chainer 1.17.0+\n- TensorFlow 0.11.0rc2\n\n## Environmental Setup\n\n```\nexport TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0rc2-cp35-cp35m-linux_x86_64.whl\npip install --upgrade -I setuptools\npip install --upgrade $TF_BINARY_URL\npython setup.py install\n```\n\n# Run tests\n\n```bash\nnosetests -s tests\n```\n\n# Run a MNIST example\n\n```bash\npython examples/mnist.py\n```\n\n# Usage\n\nJust give a decorator `@totf` to the member function `__call__` of your model class that inherits from `chainer.Chain`. The following example is from `examples/mnist.py`, and it shows how to use TensorFlow for all computations performed inside the `__call__` function:\n\n```py\nclass LeNet5(chainer.Chain):\n\n    def __init__(self):\n        super(LeNet5, self).__init__(\n            conv1=L.Convolution2D(1, 6, 5),\n            conv2=L.Convolution2D(6, 16, 5),\n            fc3=L.Linear(None, 120),\n            fc4=L.Linear(120, 84),\n            fc5=L.Linear(84, 10)\n        )\n        self.train = True\n\n    @totf\n    def __call__(self, x):\n        h = F.max_pooling_2d(F.relu(self.conv1(x)), 2, 2)\n        h = F.max_pooling_2d(F.relu(self.conv2(h)), 2, 2)\n        h = F.relu(self.fc3(h))\n        h = F.relu(self.fc4(h))\n        h = self.fc5(h)\n        return h\n```\n\nDon't miss the `@totf` decorator right before the `__call__` method definition.\n\nThen, just give a `chainer.Variable` to the model object as usual, it runs on TensorFlow.\n\n```py\nx = ...  # Prepare the input variable as a numpy array\nmodel = LeNet5()\nx = chainer.Variable(x)\ny = model(x)  # It's performed with TensorFlow!\n```\n\nThe returned value `y` will be a numpy array.\n\n## Visualization\n\nTo visualize your Chainer model using tensorboard, just adding the below line following the model forward calculation part:\n\n```py\ntf.train.SummaryWriter('data', graph=model.session.graph)\n```\n\nAnd before running the script (e.g., `examples/mnist.py` or `examples/vgg16.py`), please launch the tensorboard first by:\n\n```bash\n$ tensorboard --logdir=$PWD\n```\n\nThen run an example script, it will create `data` dir. Open your browser and go to `http://localhost:6006` then click the `GRAPHS` tab, and enjoy the visualization result.\n\n### Chainer model visualization examples\n\nLeNet5               | VGG16\n-------------------- | -------------------\n![](data/LeNet5.png) | ![](data/VGG16.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitmul%2Ftfchain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitmul%2Ftfchain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitmul%2Ftfchain/lists"}