如何使用Keras在CNN中执行前馈传播? [英] How to perform feed forward propagation in CNN using Keras?

查看:84
本文介绍了如何使用Keras在CNN中执行前馈传播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Keras在CNN上执行前馈传播.我正在尝试使用自己的优化器来训练CNN,我无法将其放入Keras的优化器文件中.我的无梯度优化器.我不想使用任何内置的东西.

I want to perform feed forward propagation on CNN using Keras. I am trying to train CNN using my own optimizer, which I can't fit in the optimiser file of Keras. My optimiser in gradient free. I don't want any inbuilt to be used.

推荐答案

我找到了此问题的答案.我们只需要使模型不可训练即可.

I found answer to this question. We just have to make model non trainable.

import numpy as np
import keras

x = keras.layers.Input(shape=(3,))
y = keras.layers.Dense(5)(x)

model = keras.models.Model(x, y)
model.trainable = False
model.compile(optimizer='rmsprop', loss='mse')

x = np.random.random((10, 3))
y = np.random.random((10, 5))
model.fit(x, y, epochs=10)

这篇关于如何使用Keras在CNN中执行前馈传播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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