未捕获(承诺)错误:未知层 [英] Uncaught (in promise) Error: Unknown layer

查看:34
本文介绍了未捕获(承诺)错误:未知层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 来自 google 的图像分类教程.在某些时候,完成了一些数据增强:RandomFlipRandomRotationRandomZoom.

I am following an image classification tutorial from google. At some point, there are some data augmentation that are done: RandomFlip, RandomRotation, RandomZoom.

完成训练后,我使用 tfjs.converters.save_keras_model 导出模型以在我的节点应用程序中使用.在节点启动时,我收到此错误:

When done with the training, I exported the model using tfjs.converters.save_keras_model to be used in my node application. At node start, I get this error:

未捕获(承诺)错误:未知层:RandomFlip.这可能是由于以下原因之一:该层是用 Python 定义的,在这种情况下,它需要移植到 TensorFlow.js 或您的 JavaScript 代码.自定义层在 JavaScript 中定义,但未使用 tf.serialization.registerClass() 正确注册.

我在某处读到我可以通过某种方式编辑 model.json 文件以使其工作.但是我不知道如何将其应用于这三个转换.这是 modej.json 文件的第一行:

I read somewhere that I could edit the model.json file in some ways to make it work. But I don't know how to apply it to these three transformations. Here is the first lines of the modej.json file:

    {"format": "layers-model", "generatedBy": "keras v2.4.0", "convertedBy": "TensorFlow.js Converter v2.4.0", "modelTopology": {"keras_version": "2.4.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential_2", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, 200, 200, 3], "dtype": "float32", "sparse": false, "ragged": false, "name": "sequential_1_input"}}, {"class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, 200, 200, 3], "dtype": "float32", "sparse": false, "ragged": false, "name": "random_flip_input"}}, {"class_name": "RandomFlip", "config": {"name": "random_flip", "trainable": true, "batch_input_shape": [null, 200, 200, 3], "dtype": "float32", "mode": "horizontal", "seed": null}}, {"class_name": "RandomRotation", "config": {"name": "random_rotation", "trainable": true, "dtype": "float32", "factor": 0.1, "fill_mode": "reflect", "interpolation": "bilinear", "seed": null}}, {"class_name": "RandomZoom", "config": {"name": "random_zoom", "trainable": true, "dtype": "float32", "height_factor": 0.1, "width_factor": null, "fill_mode": "reflect", "interpolation": "bilinear", "seed": null}}]}}, {"class_name": "Rescaling", "config": {"name": "rescaling_2", "trainable": true, "dtype": "float32", "scale": 0.00392156862745098, "offset": 0.0}}, {"class_name": "Conv2D", "config": {"name": "conv2d_3", "trainable": true, "dtype": "float32", "filters": 16, "kernel_size": [

有什么办法可以帮助解决这个问题吗?

Any way to help with this?

推荐答案

modelTopology.model_config.class_nameSequential 更改为 Model.

Change modelTopology.model_config.class_name from Sequential to Model.

 {"format": "layers-model", "generatedBy": "keras v2.4.0", "convertedBy": "TensorFlow.js Converter v2.4.0", "modelTopology": {"keras_version": "2.4.0", "backend": "tensorflow", "model_config": {"class_name": "Model", "config": {"name": "sequential_2", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, 200, 200, 3], "dtype": "float32", "sparse": false, "ragged": false, "name": "sequential_1_input"}}, {"class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, 200, 200, 3], "dtype": "float32", "sparse": false, "ragged": false, "name": "random_flip_input"}}, {"class_name": "RandomFlip", "config": {"name": "random_flip", "trainable": true, "batch_input_shape": [null, 200, 200, 3], "dtype": "float32", "mode": "horizontal", "seed": null}}, {"class_name": "RandomRotation", "config": {"name": "random_rotation", "trainable": true, "dtype": "float32", "factor": 0.1, "fill_mode": "reflect", "interpolation": "bilinear", "seed": null}}, {"class_name": "RandomZoom", "config": {"name": "random_zoom", "trainable": true, "dtype": "float32", "height_factor": 0.1, "width_factor": null, "fill_mode": "reflect", "interpolation": "bilinear", "seed": null}}]}}, {"class_name": "Rescaling", "config": {"name": "rescaling_2", "trainable": true, "dtype": "float32", "scale": 0.00392156862745098, "offset": 0.0}}, {"class_name": "Conv2D", "config": {"name": "conv2d_3", "trainable": true, "dtype": "float32", "filters": 16, "kernel_size": [

这篇关于未捕获(承诺)错误:未知层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆