How to build a Neural Network with sentence embeding concatenated to pre-trained CNN

醉酒当歌 提交于 2021-02-18 08:48:40

问题


I want to build a neural network that will take the feature map from the last layer of a CNN (VGG or resnet for example), concatenate an additional vector (for example , 1X768 bert vector) , and re-train the last layer on classification problem. So the architecture should be like in:

but I want to concat an additional vector to each feature vector (I have a sentence to describe each frame).

I have 5 possible labels , and 100 frames in the input frames.

Can someone help me as to how to implement this type of network?


回答1:


I would recommend looking into the Keras functional API.

Unlike a sequential model (which is usually enough for many introductory problems), the functional API allows you to create any acyclic graph you want. This means that you can have two input branches, one for the CNN (image data) and the other for any NLP you need to do (relating to the descriptive sentence that you mentioned). Then, you can feed in the combined outputs of these two branches into the final layers of your network and produce your result.

Even if you've already created your model using models.Sequential(), it shouldn't be too hard to rewrite it to use the functional API.

For more information and implementation details, look at the official documentation here: https://keras.io/guides/functional_api/



来源:https://stackoverflow.com/questions/63547650/how-to-build-a-neural-network-with-sentence-embeding-concatenated-to-pre-trained

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!