简体   繁体   English

加载CNN模型以进行文本分类预测时出错

[英]Error in loading CNN model for text classification prediction

I am very new to Convolutional Neural Network and I basically followed this example: https://mxnet.incubator.apache.org/tutorials/nlp/cnn.html?highlight=convolutional in training my data. 我是卷积神经网络的新手,我基本上遵循以下示例: https : //mxnet.incubator.apache.org/tutorials/nlp/cnn.html?highlight=convolutional训练我的数据。

Now I run and had the .params and .json file, I was trying to load the model using this code: 现在我运行并拥有.params和.json文件,我正尝试使用以下代码加载模型:

sym, arg_params, aux_params = mx.model.load_checkpoint('cnn', 9)
mod = mx.mod.Module(symbol=sym, context=mx.cpu(), label_names=None)
mod.bind(for_training=False, data_shapes=[('data', (1,51))], 
         label_shapes=mod._label_shapes)
mod.set_params(arg_params, aux_params, allow_missing=True)

but it always shows an error like this: 但它始终显示如下错误:

MXNetError: Error in operator reshape4: [11:59:49] src/operator/tensor/./matrix_op-inl.h:182: Check failed: oshape.Size() == dshape.Size() Target shape size is different to source. MXNetError:操作符重整4中的错误:[11:59:49] src / operator / tensor /./ matrix_op-inl.h:182:检查失败:oshape.Size()== dshape.Size()目标形状大小不同源。 Target: 255000 Source: 2550 目标:255000来源:2550

I am not sure which part did I do wrong. 我不确定我做错了哪一部分。

For data_shapes it should be: 对于data_shapes,应为:

data_shapes=[('data', (50,56))]

with 50 being batch_size and 56 being sentence_size / sequence_length. 其中50为batch_size,56为句子大小/ sequence_length。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM