Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
PyTorch to Keras model convertor
| Date | Stars |
|---|---|
| 2026-07-24 | 862 |
| 2026-07-25 | 862 |
| 2026-07-28 | 862 |
| 2026-07-30 | 862 |
| 2026-08-06 | 862 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# pytorch2keras
[](https://travis-ci.com/gmalivenko/pytorch2keras)
[](https://opensource.org/licenses/MIT)
[](https://github.com/gmalivenko/pytorch2keras)
[](https://pepy.tech/project/pytorch2keras)

[](https://pytorch2keras.readthedocs.io/en/latest/)
PyTorch to Keras model converter.
## Installation
```
pip install pytorch2keras
```
## Important notice
To use the converter properly, please, make changes in your `~/.keras/keras.json`:
```json
...
"backend": "tensorflow",
"image_data_format": "channels_first",
...
```
## Tensorflow.js
For the proper conversion to a tensorflow.js format, please use the new flag `names='short'`.
Here is a short instruction how to get a tensorflow.js model:
1. First of all, you have to convert your model to Keras with this converter:
```python
k_model = pytorch_to_keras(model, input_var, [(10, 32, 32,)], verbose=True, names='short')
```
2. Now you have Keras model. You can save it as h5 file and then convert it with `tensorflowjs_converter` but it doesn't work sometimes. As alternative, you may get Tensorflow Graph and save it as a frozen model:
```python
# Function below copied from here:
# https://stackoverflow.com/questions/45466020/how-to-export-keras-h5-to-tensorflow-pb
def freeze_session(session, keep_var_names=None, output_names=None, clear_devices=True):
"""
Freezes the state of a session into a pruned computation graph.
Creates a new computation graph where variable nodes are replaced by
constants taking their current value in the session. The new graph will be
pruned so subgraphs that are not necessary to compute the requested
outputs are removed.
@param session The TensorFlow session to be frozen.
@param keep_var_names A list of variable names that should not be frozen,
or None to freeze all the variables in the graph.
@param output_names Names of the relevant graph outputs.
@param clear_devices Remove the device directives from the graph for better portability.
@return The frozen graph definition.
"""
from tensorflow.python.framework.graph_util import convert_variables_to_constants
graph = session.graph
with graph.as_default():
freeze_var_names = \
list(set(v.op.name for v in tf.global_variables()).difference(keep_var_names or []))
output_names = output_names or []
output_names += [v.op.name for v in tf.global_variables()]
input_graph_def = graph.as_graph_def()
if clear_devices:
for node in input_graph_def.node:
node.device = ""
frozen_graph = convert_variables_to_constants(session, input_graph_def,
output_names, freeze_var_names)
return frozen_graph
from keras import backend as K
import tensorflow as tf
frozen_graph = freeze_session(K.get_session(),
output_names=[out.op.name for out in k_model.outputs])
tf.train.write_graph(frozen_graph, ".", "my_model.pb", as_text=False)
print([i for i in k_model.outputs])
```
3. You will see the output layer name, so, now it's time to convert `my_model.pb` to tfjs model:
```bash
tensorflowjs_converter \
--input_format=tf_frozen_model \
--output_node_names='TANHTObs/Tanh' \
my_model.pb \
model_tfjs
```
4. Thats all!
```js
const MODEL_URL = `model_tfjs/tensorflowjs_model.pb`;
const WEIGHTS_URL = `model_tfjs/weights_manifest.json`;
const model = await tf.loadFrozenModel(MODEL_URL, WEIGHTS_URL);
```
## How to use
It's the converter of PyTorch graph toExcerpt of 6,697 characters
Read on GitHubGrigory Malivenko · Japan
255
5
4
4
3
2
2
1
1
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:dd780d07e39a49c1, topic:deep-learning, topic:pytorch, topic:tensorflow