当前位置: 首页>>代码示例>>Python>>正文


Python Layer.addNeuron方法代码示例

本文整理汇总了Python中layer.Layer.addNeuron方法的典型用法代码示例。如果您正苦于以下问题:Python Layer.addNeuron方法的具体用法?Python Layer.addNeuron怎么用?Python Layer.addNeuron使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在layer.Layer的用法示例。


在下文中一共展示了Layer.addNeuron方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initNetwork

# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import addNeuron [as 别名]
def initNetwork():

	#
	# Initialize neural network
	# The parameter sendt in is the learningRate of ther neural network,
	# in this case we set it to 0.001
	#
	nn = ConvolutionalNeuralNetwork(0.001)

	#
	# Layer 0, the input layer
	#
	layer0 = Layer("layer0")

	# Creates the neurons in the layer0 and adds them into the layer. 
	for i in range(0,841):
		layer0.addNeuron()
		
	# Adds the layer into the neural network
	nn.addLayer(layer0)

	#
	# Layer 1: Convolutional layer
	# 6 feature maps. Each feature map is 13x13, and each unit in the feature map is a 5x5 convolutional kernel 
	# from the input layer.
	# So there are 13x13x6 = 1014 neurons, (5x5+1)x6 weights
	#
	layer1 = Layer("layer1")

	# Sets the previous layer as layer0
	layer1.setPrevLayer(layer0)


	# Add the neurons
	for i in range(0,1014):
		layer1.addNeuron()

	# Add weights from layer0 to layer1
	for i in range(0,156):
		# Uniform random distribution
		initWeight = 0.05*random.uniform(-1,1)

		layer1.addWeight(initWeight)

	


	# interconnections with previous layer: this is difficult
	# The previous layer is a top-down bitmap
	# image that has been padded to size 29x29
	# Each neuron in this layer is connected
	# to a 5x5 kernel in its feature map, which 
	# is also a top-down bitmap of size 13x13. 
	# We move the kernel by TWO pixels, i.e., we
	# skip every other pixel in the input image

	kernelTemplate = [0,1,2,3,4,29,30,31,32,33,58,59,60,61,62,87,88,89,90,91,116,117,118,119,120]

	#Feature maps
	for fm in range(0,6):

		for i in range(0,13):

			for j in range(0,13):

				# 26 is the number of weights per featuremaps
				iNumWeights = fm * 26;

				# Bias weight
				layer1.neurons[fm*169+j+i*13].addConnection(-10000,iNumWeights)
				iNumWeights +=1

				for k in range(0,25):

					layer1.neurons[fm*169+j+i*13].addConnection(2*j+58*i+kernelTemplate[k],iNumWeights)
					iNumWeights +=1


	# Add layer to network
	nn.addLayer(layer1)


	#
	# Layer two: This layer is a convolutional layer 
	# 50 feature maps. Each feature map is 5x5, and each unit in the feature maps is a 5x5 convolutional kernel of
	# corresponding areas of all 6 of the previous layers, each of which is a 13x13 feature map. 
	# So, there are 5x5x50 = 1250 neurons, (5X5+1)x6x50 = 7800 weights


	layer2 = Layer("layer2")
	layer2.setPrevLayer(layer1)

	# Add the neurons
	for i in range(0,1250):
		layer2.addNeuron()

	# Add weights
	for i in range(0,7800):
		# Uniform random distribution
		initWeight = 0.05*random.uniform(-1,1)
#.........这里部分代码省略.........
开发者ID:hessenh,项目名称:Digit-Classification---Convolutional-Neural-Network,代码行数:103,代码来源:main.py


注:本文中的layer.Layer.addNeuron方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。