回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我的目的是知道在卷积过程中使用的核权重,然后对图像进行前向传递以进行分类。这项工作使用kerasapi很容易完成,但这是我硕士论文的要求,因为我想在FPGA上建立一个CNN模型,只用于测试/分类。在</p>
<p>不使用Keras API:</p>
<blockquote>
<p>1/ I will write a plain code where I will give my preprocessed image as an input</p>
<p>2/ I will write convolution algorithm and give the extracted information of the Kernel to do the convolution</p>
<p>3/ I will write the algorithm for Flatten and </p>
<p>4/ By using Dense algorithm I want to <strong>predict</strong> the <strong>class</strong> </p>
</blockquote>
<p>我的问题是:</p>
<blockquote>
<p>1/ What is the information actually is giving by <strong>layer.get_weights()</strong>? Is it giving us the kernel weight which will use for the convolution?</p>
<p>2/ If I want to do the classification with the help of extracted weight how can I approach?</p>
</blockquote>
<p>下面是我的模型:(为了简单起见,我刚刚编写了一个具有最小层的模型)</p>
<pre><code>def cnn_model():
model = Sequential()
model.add(Conv2D(1, (3, 3), padding='same',
input_shape=input_shape,
activation='relu'))
model.add(Flatten())
model.add(Dense(num_classes, activation='softmax'))
return model
model = cnn_model()
lr = 0.01
sgd = SGD(lr=lr, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
optimizer=sgd,
metrics=['accuracy'])
</code></pre>
<p>输入图像为灰度和宽度,高度为80,80。
我使用以下代码训练了我的模型:</p>
^{pr2}$
<p>我使用以下方法提取了层权重:</p>
^{3}$
<p><strong>weight_数组=[0]</strong>的输出为</p>
<pre><code> [array([[[[ 0.3856341 ]],
[[-0.35276324]],
[[-0.51678646]]],
[[[-0.62636113]],
[[ 0.43428165]],
[[-0.26765126]]],
[[[ 0.461921 ]],
[[-0.14468761]],
[[-0.3061749 ]]]], dtype=float32), array([-0.1087065], dtype=float32)]
</code></pre>
<p>任何建议都是值得赞赏的。在</p>