c++ - C++ 中嵌入层定义的问题(mlpack lib)
问题描述
我面临以下问题。我想建立一个 LSTM 模型来进行情绪分析。在 C++ 中,我使用 mlpack 库。首先,为了理解架构,我通过 python 和 Keras 从一些教程中建议了这个问题。本教程有以下代码:
from keras.models import Sequential
from keras.layers import Dense, Embedding, LSTM, GRU
from keras.layers.embeddings import Embedding
EMBEDDING_DIM = 100
print('Build model...')
model = Sequential()
model.add(Embedding(vocab_size, EMBEDDING_DIM, input_length=max_length())
model.add(GRU(units=32, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
在我的代码中,在 C++ 中,我编写了这个块:
model.Add<IdentityLayer<> >();
model.Add<Embedding<> >(vocabSize, embedSize);
model.Add<LSTM<> >(inputSize, lstmCells, maxRho);
model.Add<Dropout<> >(0.5);
model.Add<ReLULayer<> >();
model.Add<Linear<> >(lstmCells, outputSize);
输出控制台给了我这个错误:
error: conv_to(): given object can't be interpreted as a vector
terminate called after throwing an instance of 'std::logic_error'
what(): conv_to(): given object can't be interpreted as a vector
经过几个小时的调试,我无法理解错误在哪里......谢谢
解决方案
推荐阅读
- python - 通过 JSON 文件中的 dicts 列表循环
- python-3.x - 无法调用从导入模块创建的机器人框架中的关键字
- c# - System.IO.FileNotFoundException:“在 asp.net MVC 中找不到文件”
- javascript - 从文本中删除我认为是静态的
- sql - 我需要将以下函数从 DB2 转换为 Oracle,有人可以帮忙吗?我不知道 DB2
- postgresql - 使用安装在不同 Postgres Schema 中的 Postgis 扩展
- postman - newman 运行的文件夹中的断言总数
- sql - 计数 2 Group by(s) 没有子查询/CTE
- vuejs2 - 在 VueJS 中不工作的组件之间动态切换
- python - 没有将 Django 数据插入到 postgresql 中