我正在使用Keras(与Theano)来训练我的CNN模型.有谁知道如何在我的C++应用程序中使用它?有没有人尝试类似的东西?我有想法写一些python代码,它将生成一个带有网络功能的c ++代码 - 有什么建议吗?
我使用tensorflow在python中训练了一个图像分类网络.训练有素的模型保存为.pb
.现在,我想测试模型,我需要在C++中完成.
我用过numpy
操纵和处理数据.在训练阶段,图像作为numpy数组传递.图像作为一维数组延伸,类标签前置于此数组.
我很困惑如何在C++中运行模型时传递图像数据numpy
,我无法使用.我使用numpy
操作来操纵和处理数据.如果我必须在C++中执行它,我应该以什么格式传入数据.
以下是我训练和保存模型的方法
def trainModel(data):
global_step = tf.Variable(0, name='global_step', trainable=False)
X, y,keep_prob = modelInputs((741, 620, 1),4)
logits = cnnModel(X,keep_prob)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=y), name="cost")
optimizer = tf.train.AdamOptimizer(.0001, name='Adam').minimize(cost)
prediction = tf.argmax(logits, 1, name="prediction")
correct_pred = tf.equal(prediction, tf.argmax(y, 1), name="correct_pred")
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32), name='accuracy')
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()
batch_size = 30
for e in range(11):
batch_x, batch_y = data.next_batch(batch_size)
batch_y = batch_y.astype('int32')
x = np.reshape(batch_x, [batch_size, 741, …
Run Code Online (Sandbox Code Playgroud)