microsoft/MMdnn

[GAN support] how to convert from tensorflow to keras

Open

#69 opened on 2018年2月6日

GitHub で見る
 (1 comment) (0 reactions) (0 assignees)Python (5,767 stars) (982 forks)batch import
enhancementhelp wanted

説明

Thank you for a great covert tool! I want to convert tensorflow model to keras model. However, the following error occurred.

Platform:ubuntu 16.04 Python version:2.7.12 Source framework with version :Tensorflow 1.3.0 with GPU Destination framework with version :keras with 2.1.3 Pre-trained model path :https://drive.google.com/open?id=1KNOH5OtPLHQyod02A3L9_xJVWE5pdmcf code : https://github.com/xhujoy/CycleGAN-tensorflow

Running scripts:

$python -m mmdnn.conversion._script.convertToIR -f tensorflow -d isCycle -n cyclegan.model-213002.meta --dstNodeName generatorA2B/g_pred_c/Conv/weights -w cyclegan.model-213002.index

Parse file [cyclegan.model-213002.meta] with binary format successfully.
Tensorflow model file [cyclegan.model-213002.meta] loaded successfully.
Tensorflow checkpoint file [cyclegan.model-213002.index] loaded successfully. [0] variables loaded.
IR network structure is saved as [isCycle.json].
IR network structure is saved as [isCycle.pb].
IR weights are saved as [isCycle.npy].

$python -m mmdnn.conversion._script.IRToCode -f keras --IRModelPath isCycle.pb --dstModelPath convertedCycle.py --IRWeightPath isCycle.npy

Parse file [isCycle.pb] with binary format successfully.
Target network code snippet is saved as [convertedCycle.py].

$python -m mmdnn.conversion.examples.keras.imagenet_test -n convertedCycle.py -w isCycle.npy --dump cyclegan.h5

/usr/local/lib/python2.7/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/mmdnn/conversion/examples/keras/imagenet_test.py", line 58, in <module>
    tester.dump()
  File "/usr/local/lib/python2.7/dist-packages/mmdnn/conversion/examples/keras/imagenet_test.py", line 50, in dump
    self.model.save(path)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2573, in save
    save_model(self, filepath, overwrite, include_optimizer)
  File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 115, in save_model
    if legacy_models.needs_legacy_support(model):
  File "/usr/local/lib/python2.7/dist-packages/keras/legacy/models.py", line 9, in needs_legacy_support
    return isinstance(model.layers[0], Merge)
IndexError: list index out of range

コントリビューターガイド