第一个caffe案例

caffe案例

import caffe
from caffe import layers as L
from caffe import params as P 


def net(dbfile,batch_size,mean_value=0):
	d = caffe.NetSpec()
	d.data, d.label=L.Data(source=dbfile, backend = P.Data.LMDB, batch_size=batch_size, ntop=2, transform_param=dict(scale=0.00390625))
	d.ip1 = L.InnerProduct(d.data, num_output=500, weight_filler=dict(type='xavier'))
	d.relu1 = L.ReLU(d.ip1, in_place=True)
	d.ip2 = L.InnerProduct(d.relu1, num_output=10, weight_filler=dict(type='xavier'))
	d.loss = L.SoftmaxWithLoss(d.ip2, d.label)
	d.accu = L.Accuracy(d.ip2, d.label, include={'phase':caffe.TEST})
	return d.to_proto()
	
def main():
	with open( 'auto_train00.prototxt', 'w') as f:
		f.write(str(net( 'mnist/mnist_train_lmdb', 64)))
	with open('auto_test00.prototxt', 'w') as f:
		f.write(str(net('mnist/mnist_test_lmdb', 100)))
	solver = caffe.SGDSolver("hbk_mnist_solver_py.prototxt")
	solver.net.forward()
	solver.test_nets[0].forward()
	solver.step(1)

if __name__=="__main__":
	main()

第一个caffe案例_第1张图片
并生成两个文件。

相关文件

链接:https://pan.baidu.com/s/1XRQNQdQUVUjPQFWUykYXGQ
提取码:r4e0
复制这段内容后打开百度网盘手机App,操作更方便哦

你可能感兴趣的:(caffe,python)