tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone
https://tensorflow.org
Apache License 2.0
185.74k stars 74.21k forks source link

Can't convert Albert to tflite by missing IdentityN support #35018

Closed hygkim95 closed 4 years ago

hygkim95 commented 4 years ago

System information

Provide the text output from tflite_convert

ConverterError: See console for info.
2019-12-11 07:22:00.278074: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: IdentityN
2019-12-11 07:22:00.421599: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 2198 operators, 3544 arrays (0 quantized)
2019-12-11 07:22:00.563590: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 2194 operators, 3535 arrays (0 quantized)
2019-12-11 07:22:00.753664: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 2194 operators, 3535 arrays (0 quantized)
2019-12-11 07:22:01.305107: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 1366 operators, 2266 arrays (0 quantized)
2019-12-11 07:22:02.013834: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 2: 1293 operators, 2193 arrays (0 quantized)
2019-12-11 07:22:02.126476: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 3: 1256 operators, 2125 arrays (0 quantized)
2019-12-11 07:22:02.230528: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 4: 1252 operators, 2120 arrays (0 quantized)
2019-12-11 07:22:02.347386: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 5: 1316 operators, 2260 arrays (0 quantized)
2019-12-11 07:22:02.459624: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 6: 1316 operators, 2260 arrays (0 quantized)
2019-12-11 07:22:02.583975: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 7: 1379 operators, 2410 arrays (0 quantized)
2019-12-11 07:22:02.710596: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 8: 1379 operators, 2410 arrays (0 quantized)
2019-12-11 07:22:02.837758: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 9: 1378 operators, 2420 arrays (0 quantized)
2019-12-11 07:22:02.964471: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 10: 1378 operators, 2420 arrays (0 quantized)
2019-12-11 07:22:03.097633: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 11: 1330 operators, 2335 arrays (0 quantized)
2019-12-11 07:22:03.219935: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 12: 1324 operators, 2329 arrays (0 quantized)
2019-12-11 07:22:03.341469: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 13: 1388 operators, 2469 arrays (0 quantized)
2019-12-11 07:22:03.473109: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 14: 1388 operators, 2469 arrays (0 quantized)
2019-12-11 07:22:03.608375: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 15: 1451 operators, 2619 arrays (0 quantized)
2019-12-11 07:22:03.746363: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 16: 1451 operators, 2619 arrays (0 quantized)
2019-12-11 07:22:03.888602: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 17: 1450 operators, 2629 arrays (0 quantized)
2019-12-11 07:22:04.021441: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 18: 1450 operators, 2629 arrays (0 quantized)
2019-12-11 07:22:04.166493: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 19: 1402 operators, 2544 arrays (0 quantized)
2019-12-11 07:22:04.296326: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 20: 1396 operators, 2538 arrays (0 quantized)
2019-12-11 07:22:04.435268: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 21: 1460 operators, 2678 arrays (0 quantized)
2019-12-11 07:22:04.576370: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 22: 1460 operators, 2678 arrays (0 quantized)
2019-12-11 07:22:04.727069: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 23: 1523 operators, 2828 arrays (0 quantized)
2019-12-11 07:22:04.884741: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 24: 1523 operators, 2828 arrays (0 quantized)
2019-12-11 07:22:05.035517: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 25: 1522 operators, 2838 arrays (0 quantized)
2019-12-11 07:22:05.185234: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 26: 1522 operators, 2838 arrays (0 quantized)
2019-12-11 07:22:05.345311: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 27: 1474 operators, 2753 arrays (0 quantized)
2019-12-11 07:22:05.490007: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 28: 1468 operators, 2747 arrays (0 quantized)
2019-12-11 07:22:05.664208: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 29: 1532 operators, 2887 arrays (0 quantized)
2019-12-11 07:22:05.816073: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 30: 1532 operators, 2887 arrays (0 quantized)
2019-12-11 07:22:05.979330: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 31: 1595 operators, 3037 arrays (0 quantized)
2019-12-11 07:22:06.146208: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 32: 1595 operators, 3037 arrays (0 quantized)
2019-12-11 07:22:06.311167: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 33: 1594 operators, 3047 arrays (0 quantized)
2019-12-11 07:22:06.469774: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 34: 1594 operators, 3047 arrays (0 quantized)
2019-12-11 07:22:06.641870: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 35: 1546 operators, 2962 arrays (0 quantized)
2019-12-11 07:22:06.794954: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 36: 1540 operators, 2956 arrays (0 quantized)
2019-12-11 07:22:06.961088: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 37: 1604 operators, 3096 arrays (0 quantized)
2019-12-11 07:22:07.126460: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 38: 1604 operators, 3096 arrays (0 quantized)
2019-12-11 07:22:07.298514: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 39: 1667 operators, 3246 arrays (0 quantized)
2019-12-11 07:22:07.480185: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 40: 1667 operators, 3246 arrays (0 quantized)
2019-12-11 07:22:07.682372: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 41: 1666 operators, 3256 arrays (0 quantized)
2019-12-11 07:22:07.867497: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 42: 1666 operators, 3256 arrays (0 quantized)
2019-12-11 07:22:08.062627: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 43: 1618 operators, 3171 arrays (0 quantized)
2019-12-11 07:22:08.239084: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 44: 1612 operators, 3165 arrays (0 quantized)
2019-12-11 07:22:08.428755: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 45: 1676 operators, 3305 arrays (0 quantized)
2019-12-11 07:22:08.615966: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 46: 1676 operators, 3305 arrays (0 quantized)
2019-12-11 07:22:08.811813: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 47: 1739 operators, 3455 arrays (0 quantized)
2019-12-11 07:22:09.014879: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 48: 1739 operators, 3455 arrays (0 quantized)
2019-12-11 07:22:09.220450: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 49: 1738 operators, 3465 arrays (0 quantized)
2019-12-11 07:22:09.423087: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 50: 1738 operators, 3465 arrays (0 quantized)
2019-12-11 07:22:09.634820: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 51: 1690 operators, 3380 arrays (0 quantized)
2019-12-11 07:22:09.829015: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 52: 1684 operators, 3374 arrays (0 quantized)
2019-12-11 07:22:10.034856: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 53: 1748 operators, 3514 arrays (0 quantized)
2019-12-11 07:22:10.242489: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 54: 1748 operators, 3514 arrays (0 quantized)
2019-12-11 07:22:10.449573: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 55: 1811 operators, 3664 arrays (0 quantized)
2019-12-11 07:22:10.656973: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 56: 1811 operators, 3664 arrays (0 quantized)
2019-12-11 07:22:10.887171: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 57: 1810 operators, 3674 arrays (0 quantized)
2019-12-11 07:22:11.106195: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 58: 1810 operators, 3674 arrays (0 quantized)
2019-12-11 07:22:11.342466: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 59: 1762 operators, 3589 arrays (0 quantized)
2019-12-11 07:22:11.555873: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 60: 1756 operators, 3583 arrays (0 quantized)
2019-12-11 07:22:11.779618: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 61: 1820 operators, 3723 arrays (0 quantized)
2019-12-11 07:22:12.002172: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 62: 1820 operators, 3723 arrays (0 quantized)
2019-12-11 07:22:12.230472: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 63: 1883 operators, 3873 arrays (0 quantized)
2019-12-11 07:22:12.475085: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 64: 1883 operators, 3873 arrays (0 quantized)
2019-12-11 07:22:12.715383: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 65: 1882 operators, 3883 arrays (0 quantized)
2019-12-11 07:22:12.956508: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 66: 1882 operators, 3883 arrays (0 quantized)
2019-12-11 07:22:13.200556: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 67: 1834 operators, 3798 arrays (0 quantized)
2019-12-11 07:22:13.431959: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 68: 1828 operators, 3792 arrays (0 quantized)
2019-12-11 07:22:13.676081: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 69: 1892 operators, 3932 arrays (0 quantized)
2019-12-11 07:22:13.936701: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 70: 1892 operators, 3932 arrays (0 quantized)
2019-12-11 07:22:14.198596: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 71: 1955 operators, 4082 arrays (0 quantized)
2019-12-11 07:22:14.455744: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 72: 1955 operators, 4082 arrays (0 quantized)
2019-12-11 07:22:14.709946: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 73: 1954 operators, 4092 arrays (0 quantized)
2019-12-11 07:22:14.973819: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 74: 1954 operators, 4092 arrays (0 quantized)
2019-12-11 07:22:15.247743: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 75: 1906 operators, 4007 arrays (0 quantized)
2019-12-11 07:22:15.508479: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 76: 1900 operators, 4001 arrays (0 quantized)
2019-12-11 07:22:15.768632: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 77: 1964 operators, 4141 arrays (0 quantized)
2019-12-11 07:22:16.042654: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 78: 1964 operators, 4141 arrays (0 quantized)
2019-12-11 07:22:16.315995: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 79: 2027 operators, 4291 arrays (0 quantized)
2019-12-11 07:22:16.599728: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 80: 2027 operators, 4291 arrays (0 quantized)
2019-12-11 07:22:16.876653: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 81: 2026 operators, 4301 arrays (0 quantized)
2019-12-11 07:22:17.155476: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 82: 2026 operators, 4301 arrays (0 quantized)
2019-12-11 07:22:17.455543: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 83: 1978 operators, 4216 arrays (0 quantized)
2019-12-11 07:22:17.732213: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 84: 1972 operators, 4210 arrays (0 quantized)
2019-12-11 07:22:18.041275: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 85: 2036 operators, 4350 arrays (0 quantized)
2019-12-11 07:22:18.337704: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 86: 2036 operators, 4350 arrays (0 quantized)
2019-12-11 07:22:18.645178: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 87: 2099 operators, 4500 arrays (0 quantized)
2019-12-11 07:22:18.960635: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 88: 2099 operators, 4500 arrays (0 quantized)
2019-12-11 07:22:19.269232: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 89: 2098 operators, 4510 arrays (0 quantized)
2019-12-11 07:22:19.562883: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 90: 2098 operators, 4510 arrays (0 quantized)
2019-12-11 07:22:19.889353: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 91: 2050 operators, 4425 arrays (0 quantized)
2019-12-11 07:22:20.190117: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 92: 2044 operators, 4416 arrays (0 quantized)
2019-12-11 07:22:20.501514: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 93: 2108 operators, 4556 arrays (0 quantized)
2019-12-11 07:22:20.810962: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 94: 2108 operators, 4556 arrays (0 quantized)
2019-12-11 07:22:21.129394: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 95: 2171 operators, 4706 arrays (0 quantized)
2019-12-11 07:22:21.450294: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 96: 2171 operators, 4706 arrays (0 quantized)
2019-12-11 07:22:21.782083: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 97: 2170 operators, 4716 arrays (0 quantized)
2019-12-11 07:22:22.105969: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 98: 2170 operators, 4716 arrays (0 quantized)
2019-12-11 07:22:22.442836: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 99: 2158 operators, 4698 arrays (0 quantized)
2019-12-11 07:22:22.764761: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 100: 2155 operators, 4692 arrays (0 quantized)
2019-12-11 07:22:23.096868: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Group bidirectional sequence lstm/rnn: 2155 operators, 4692 arrays (0 quantized)
2019-12-11 07:22:23.324249: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before dequantization graph transformations: 2155 operators, 4692 arrays (0 quantized)
2019-12-11 07:22:23.549716: I tensorflow/lite/toco/allocate_transient_arrays.cc:345] Total transient array allocated size: 5111808 bytes, theoretical optimal value: 4718592 bytes.
2019-12-11 07:22:23.613548: I tensorflow/lite/toco/toco_tooling.cc:439] Estimated count of arithmetic ops: 22884682880 ops, equivalently 11442341440 MACs
2019-12-11 07:22:23.613795: I tensorflow/lite/toco/toco_tooling.cc:454] Number of parameters: 11065920
2019-12-11 07:22:23.618965: E tensorflow/lite/toco/toco_tooling.cc:481] We are continually in the process of adding support to TensorFlow Lite for more ops. It would be helpful if you could inform us of how this conversion went by opening a github issue at https://github.com/tensorflow/tensorflow/issues/new?template=40-tflite-op-request.md
 and pasting the following:

Some of the operators in the model are not supported by the standard TensorFlow Lite runtime. If those are native TensorFlow operators, you might be able to use the extended runtime by passing --enable_select_tf_ops, or by setting target_ops=TFLITE_BUILTINS,SELECT_TF_OPS when calling tf.lite.TFLiteConverter(). Otherwise, if you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: ADD, AVERAGE_POOL_2D, CAST, DIV, FULLY_CONNECTED, GATHER, MEAN, MUL, PACK, POW, RESHAPE, RSQRT, SLICE, SOFTMAX, SQUARED_DIFFERENCE, SUB, TANH, TRANSPOSE. Here is a list of operators for which you will need custom implementations: IdentityN.
Traceback (most recent call last):
  File "/usr/local/bin/toco_from_protos", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 89, in main
    app.run(main=execute, argv=[sys.argv[0]] + unparsed)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_core/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python2.7/dist-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/usr/local/lib/python2.7/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 52, in execute
    enable_mlir_converter)
Exception: We are continually in the process of adding support to TensorFlow Lite for more ops. It would be helpful if you could inform us of how this conversion went by opening a github issue at https://github.com/tensorflow/tensorflow/issues/new?template=40-tflite-op-request.md
 and pasting the following:

Some of the operators in the model are not supported by the standard TensorFlow Lite runtime. If those are native TensorFlow operators, you might be able to use the extended runtime by passing --enable_select_tf_ops, or by setting target_ops=TFLITE_BUILTINS,SELECT_TF_OPS when calling tf.lite.TFLiteConverter(). Otherwise, if you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: ADD, AVERAGE_POOL_2D, CAST, DIV, FULLY_CONNECTED, GATHER, MEAN, MUL, PACK, POW, RESHAPE, RSQRT, SLICE, SOFTMAX, SQUARED_DIFFERENCE, SUB, TANH, TRANSPOSE. Here is a list of operators for which you will need custom implementations: IdentityN.

Also, please include a link to a GraphDef or the model if possible. -> I am using "bert-for-tf2" to load albert_base.

def load_pretrained_albert():
    model_name = "albert_base"
    model_dir = bert.fetch_tfhub_albert_model(model_name, ".models")
    model_params = bert.albert_params(model_name)
    l_bert = bert.BertModelLayer.from_params(model_params, name="albert")

    # use in Keras Model here, and call model.build()
    max_seq_len = 128

    l_input_ids = Input(shape=(max_seq_len,), dtype='int32', name="l_input_ids")
    #l_token_type_ids = Input(shape=(max_seq_len,), dtype='int32')

    output = l_bert(l_input_ids)                              # output: [batch_size, max_seq_len, hidden_size]
    pooled_output = AveragePooling1D(pool_size=max_seq_len, data_format="channels_last")(output)
    pooled_output = Flatten()(pooled_output)

    model = Model(inputs=[l_input_ids], outputs=[pooled_output])
    model.build(input_shape=(None, max_seq_len))

    bert.load_albert_weights(l_bert, model_dir)

    return model

Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

terryheo commented 4 years ago

It seeems that you resolved this by using SELECT_TF_OPS. https://www.tensorflow.org/lite/guide/ops_select

converter = tf.lite.TFLiteConverter.from_saved_model(path)
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
lite_albert = converter.convert()

So, let's close this. Please feel free to reopen it if you have an issue with this.