layerstopng(svg格式转png)

admin 360 0

大家好,感谢邀请,今天来为大家分享一下layerstopng的问题,以及和svg格式转png的一些困惑,大家要是还不太明白的话,也没有关系,因为接下来将为大家分享,希望可以帮助到大家,解决大家的问题,下面就开始吧!

一、CNN之Lenet5

LeNet诞生于 1994年,是最早的卷积神经网络之一,并且推动了深度学习领域的发展。

LeNet-5是Yann LeCun等人在多次研究后提出的最终卷积神经网络结构,主要用于手写数字识别

LeNet-5包含七层,不包括输入,每一层都包含可训练参数(权重),当时使用的输入数据是32*32像素的图像。下面逐层介绍LeNet-5的结构,并且,卷积层将用Cx表示,子采样层则被标记为Sx,全连接层被标记为Fx,其中x是层索引。

该层使用了6个卷积核,每个卷积核的大小为5×5,这样就得到了6个feature map(特征图)。

每个卷积核(5×5)与原始的输入图像(32×32)进行卷积,这样得到的feature map(特征图)大小为(32-5+1)×(32-5+1)= 28×28

卷积核与输入图像按卷积核大小逐个区域进行匹配计算,匹配后原始输入图像的尺寸将变小,因为边缘部分卷积核无法越出界,只能匹配一次,匹配计算后的尺寸变为Cr×Cc=(Ir-Kr+1)×(Ic-Kc+1),其中Cr、Cc,Ir、Ic,Kr、Kc分别表示卷积后结果图像、输入图像、卷积核的行列大小。

由于参数(权值)共享的原因,对于同个卷积核每个神经元均使用相同的参数,因此,参数个数为(5×5+1)×6= 156,其中5×5为卷积核参数,1为偏置参数

卷积后的图像大小为28×28,因此每个特征图有28×28个神经元,每个卷积核参数为(5×5+1)×6,因此,该层的连接数为(5×5+1)×6×28×28=122304

这一层主要是做池化或者特征映射(特征降维),池化单元为2×2,因此,6个特征图的大小经池化后即变为14×14。池化单元之间没有重叠,在池化区域内进行聚合统计后得到新的特征值,因此经2×2池化后,每两行两列重新算出一个特征值出来,相当于图像大小减半,因此卷积后的28×28图像经2×2池化后就变为14×14。

这一层的计算过程是:2×2单元里的值相加,然后再乘以训练参数w,再加上一个偏置参数b(每一个特征图共享相同的w和b),然后取sigmoid值(S函数:0-1区间),作为对应的该单元的值。卷积操作与池化的示意图如下:

S2层由于每个特征图都共享相同的w和b这两个参数,因此需要2×6=12个参数

下采样之后的图像大小为14×14,因此S2层的每个特征图有14×14个神经元,每个池化单元连接数为2×2+1(1为偏置量),因此,该层的连接数为(2×2+1)×14×14×6= 5880

C3层有16个卷积核,卷积模板大小为5×5。

与C1层的分析类似,C3层的特征图大小为(14-5+1)×(14-5+1)= 10×10

需要注意的是,C3与S2并不是全连接而是部分连接,有些是C3连接到S2三层、有些四层、甚至达到6层,通过这种方式提取更多特征,连接的规则如下表所示:

例如第一列表示C3层的第0个特征图(feature map)只跟S2层的第0、1和2这三个feature maps相连接,计算过程为:用3个卷积模板分别与S2层的3个feature maps进行卷积,然后将卷积的结果相加求和,再加上一个偏置,再取sigmoid得出卷积后对应的feature map了。其它列也是类似(有些是3个卷积模板,有些是4个,有些是6个)。因此,C3层的参数数目为(5×5×3+1)×6+(5×5×4+1)×9+5×5×6+1= 1516

卷积后的特征图大小为10×10,参数数量为1516,因此连接数为1516×10×10= 151600

与S2的分析类似,池化单元大小为2×2,因此,该层与C3一样共有16个特征图,每个特征图的大小为5×5。

与S2的计算类似,所需要参数个数为16×2= 32

连接数为(2×2+1)×5×5×16= 2000

该层有120个卷积核,每个卷积核的大小仍为5×5,因此有120个特征图。由于S4层的大小为5×5,而该层的卷积核大小也是5×5,因此特征图大小为(5-5+1)×(5-5+1)= 1×1。这样该层就刚好变成了全连接,这只是巧合,如果原始输入的图像比较大,则该层就不是全连接了。

与前面的分析类似,本层的参数数目为120×(5×5×16+1)= 48120

由于该层的特征图大小刚好为1×1,因此连接数为48120×1×1=48120

F6层有84个单元,之所以选这个数字的原因是来自于输出层的设计,对应于一个7×12的比特图,如下图所示,-1表示白色,1表示黑色,这样每个符号的比特图的黑白色就对应于一个编码。

该层有84个特征图,特征图大小与C5一样都是1×1,与C5层全连接。

由于是全连接,参数数量为(120+1)×84=10164。跟经典神经网络一样,F6层计算输入向量和权重向量之间的点积,再加上一个偏置,然后将其传递给sigmoid函数得出结果。

由于是全连接,连接数与参数数量一样,也是10164。

Output层也是全连接层,共有10个节点,分别代表数字0到9。如果第i个节点的值为0,则表示网络识别的结果是数字i。

该层采用径向基函数(RBF)的网络连接方式,假设x是上一层的输入,y是RBF的输出,则RBF输出的计算方式是:

上式中的Wij的值由i的比特图编码确定,i从0到9,j取值从0到7×12-1。RBF输出的值越接近于0,表示当前网络输入的识别结果与字符i越接近。

由于是全连接,参数个数为84×10=840

由于是全连接,连接数与参数个数一样,也是840

from skimage import io,transform

#将所有的图片重新设置尺寸为32*32

#mnist数据集中训练数据和测试数据保存地址

train_path="E:/data/datasets/mnist/train/"

test_path="E:/data/datasets/mnist/test/"

'''os.listdir()返回指定的文件夹包含的文件或文件夹的名字,存放于一个列表中;os.path.isdir()判断某一路径是否为目录

enumerate()将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,数据下标和相应数据'''

   label_dir= [path+x for x in os.listdir(path) if os.path.isdir(path+x)]

   for index,folder in enumerate(label_dir):

     for img in glob.glob(folder+'/*.png'):

       print("reading the image:%s"%img)

       image= io.imread(img)

       image= transform.resize(image,(w,h,c))

       images.append(image)

       labels.append(index)

   return np.asarray(images,dtype=np.float32),np.asarray(labels,dtype=np.int32)

#读取训练数据及测试数据      

train_data,train_label= read_image(train_path)

test_data,test_label= read_image(test_path)

#打乱训练数据及测试数据  np.arange()返回一个有终点和起点的固定步长的排列,

train_image_num= len(train_data)

train_image_index= np.arange(train_image_num)##起始点0,结束点train_image_num,步长1,返回类型array,一维

np.random.shuffle(train_image_index)

train_data= train_data[train_image_index]

train_label= train_label[train_image_index]

test_image_num= len(test_data)

test_image_index= np.arange(test_image_num)

np.random.shuffle(test_image_index)

test_data= test_data[test_image_index]

test_label= test_label[test_image_index]

#搭建CNN此函数可以理解为形参,用于定义过程,在执行的时候再赋具体的值,形参名X,y_

x= tf.placeholder(tf.float32,[None,w,h,c],name='x')

y_= tf.placeholder(tf.int32,[None],name='y_')

def inference(input_tensor,train,regularizer):

  #第一层:卷积层,过滤器的尺寸为5×5,深度为6,不使用全0补充,步长为1。

  #尺寸变化:32×32×1->28×28×6

  '''参数的初始化:tf.truncated_normal_initializer()或者简写为tf.TruncatedNormal()、tf.RandomNormal()去掉_initializer,大写首字母即可

生成截断正态分布的随机数,这个初始化方法好像在tf中用得比较多mean=0.0, stddev=1.0正态分布

http://www.mamicode.com/info-detail-1835147.html'''

   with tf.variable_scope('layer1-conv1'):

     conv1_weights= tf.get_variable('weight',[5,5,c,6],initializer=tf.truncated_normal_initializer(stddev=0.1))

     conv1_biases= tf.get_variable('bias',[6],initializer=tf.constant_initializer(0.0))

     conv1= tf.nn.conv2d(input_tensor,conv1_weights,strides=[1,1,1,1],padding='VALID')

     relu1= tf.nn.relu(tf.nn.bias_add(conv1,conv1_biases))

  #第二层:池化层,过滤器的尺寸为2×2,使用全0补充,步长为2。

  #尺寸变化:28×28×6->14×14×6

   with tf.name_scope('layer2-pool1'):

     pool1= tf.nn.max_pool(relu1,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')

  #第三层:卷积层,过滤器的尺寸为5×5,深度为16,不使用全0补充,步长为1。

  #尺寸变化:14×14×6->10×10×16

   with tf.variable_scope('layer3-conv2'):

     conv2_weights= tf.get_variable('weight',[5,5,6,16],initializer=tf.truncated_normal_initializer(stddev=0.1))

     conv2_biases= tf.get_variable('bias',[16],initializer=tf.constant_initializer(0.0))

     conv2= tf.nn.conv2d(pool1,conv2_weights,strides=[1,1,1,1],padding='VALID')

     relu2= tf.nn.relu(tf.nn.bias_add(conv2,conv2_biases))

  #第四层:池化层,过滤器的尺寸为2×2,使用全0补充,步长为2。

  #尺寸变化:10×10×6->5×5×16

   with tf.variable_scope('layer4-pool2'):

     pool2= tf.nn.max_pool(relu2,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')

  #将第四层池化层的输出转化为第五层全连接层的输入格式。第四层的输出为5×5×16的矩阵,然而第五层全连接层需要的输入格式

  #为向量,所以我们需要把代表每张图片的尺寸为5×5×16的矩阵拉直成一个长度为5×5×16的向量。

  #举例说,每次训练64张图片,那么第四层池化层的输出的size为(64,5,5,16),拉直为向量,nodes=5×5×16=400,尺寸size变为(64,400)

   pool_shape= pool2.get_shape().as_list()

   nodes= pool_shape[1]*pool_shape[2]*pool_shape[3]

   reshaped= tf.reshape(pool2,[-1,nodes])

  #第五层:全连接层,nodes=5×5×16=400,400->120的全连接

  #尺寸变化:比如一组训练样本为64,那么尺寸变化为64×400->64×120

  #训练时,引入dropout,dropout在训练时会随机将部分节点的输出改为0,dropout可以避免过拟合问题。

  #这和模型越简单越不容易过拟合思想一致,和正则化限制权重的大小,使得模型不能任意拟合训练数据中的随机噪声,以此达到避免过拟合思想一致。

  #本文最后训练时没有采用dropout,dropout项传入参数设置成了False,因为训练和测试写在了一起没有分离,不过大家可以尝试。

  '''tf.matmul()这个函数是专门矩阵或者tensor乘法,而不是矩阵元素对应元素相乘

   tf.multiply()两个矩阵中对应元素各自相乘

   tf.nn.dropout(x, keep_prob):TensorFlow里面为了防止或减轻过拟合而使用的函数,它一般用在全连接层,

   x:指输入;keep_prob:设置神经元被选中的概率,使输入tensor中某些元素变为0,其它没变0的元素变为原来的1/keep_prob大小,可以想象下,比如某些元素弃用

  在初始化时keep_prob是一个占位符,keep_prob= tf.placeholder(tf.float32).

   tensorflow在run时设置keep_prob具体的值,例如keep_prob: 0.5,train的时候才是dropout起作用的时候

   keep_prob: A scalar Tensor with the same type as x. The probability that each element is kept.'''

   with tf.variable_scope('layer5-fc1'):

     fc1_weights= tf.get_variable('weight',[nodes,120],initializer=tf.truncated_normal_initializer(stddev=0.1))

     if regularizer!= None:

       tf.add_to_collection('losses',regularizer(fc1_weights))

     fc1_biases= tf.get_variable('bias',[120],initializer=tf.constant_initializer(0.1))

     fc1= tf.nn.relu(tf.matmul(reshaped,fc1_weights)+ fc1_biases)

     if train:

       fc1= tf.nn.dropout(fc1,0.5)

  #第六层:全连接层,120->84的全连接

  #尺寸变化:比如一组训练样本为64,那么尺寸变化为64×120->64×84

  '''tf.add_to_collection:把变量放入一个集合,把很多变量变成一个列表

   tf.get_collection:从一个结合中取出全部变量,是一个列表

   tf.add_n:把一个列表的东西都依次加起来'''

   with tf.variable_scope('layer6-fc2'):

     fc2_weights= tf.get_variable('weight',[120,84],initializer=tf.truncated_normal_initializer(stddev=0.1))

     if regularizer!= None:

       tf.add_to_collection('losses',regularizer(fc2_weights))

     fc2_biases= tf.get_variable('bias',[84],initializer=tf.truncated_normal_initializer(stddev=0.1))

     fc2= tf.nn.relu(tf.matmul(fc1,fc2_weights)+ fc2_biases)

     if train:

       fc2= tf.nn.dropout(fc2,0.5)

  #第七层:全连接层(近似表示),84->10的全连接

  #尺寸变化:比如一组训练样本为64,那么尺寸变化为64×84->64×10。最后,64×10的矩阵经过softmax之后就得出了64张图片分类于每种数字的概率,

  #即得到最后的分类结果。

   with tf.variable_scope('layer7-fc3'):

     fc3_weights= tf.get_variable('weight',[84,10],initializer=tf.truncated_normal_initializer(stddev=0.1))

     if regularizer!= None:

       tf.add_to_collection('losses',regularizer(fc3_weights))

     fc3_biases= tf.get_variable('bias',[10],initializer=tf.truncated_normal_initializer(stddev=0.1))

     logit= tf.matmul(fc2,fc3_weights)+ fc3_biases

#正则化,交叉熵,平均交叉熵,损失函数,最小化损失函数,预测和实际equal比较,tf.equal函数会得到True或False,

#accuracy首先将tf.equal比较得到的布尔值转为float型,即True转为1.,False转为0,最后求平均值,即一组样本的正确率。

#比如:一组5个样本,tf.equal比较为[True False True False False],转化为float型为[1. 0 1. 0 0],准确率为2./5=40%。

'''规则化可以帮助防止过度配合,提高模型的适用性。(让模型无法完美匹配所有的训练项。)(使用规则来使用尽量少的变量去拟合数据)

规则化就是说给需要训练的目标函数加上一些规则(限制),让他们不要自我膨胀。

TensorFlow会将L2的正则化损失值除以2使得求导得到的结果更加简洁

如tf.contrib.layers.apply_regularization/l1_regularizer/l2_regularizer/sum_regularizer

https://blog.csdn.net/liushui94/article/details/73481112

sparse_softmax_cross_entropy_with_logits()是将softmax和cross_entropy放在一起计算

https://blog.csdn.net/ZJRN1027/article/details/80199248'''

regularizer= tf.contrib.layers.l2_regularizer(0.001)

y= inference(x,False,regularizer)

cross_entropy= tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y,labels=y_)

cross_entropy_mean= tf.reduce_mean(cross_entropy)

loss= cross_entropy_mean+ tf.add_n(tf.get_collection('losses'))

train_op= tf.train.AdamOptimizer(0.001).minimize(loss)

correct_prediction= tf.equal(tf.cast(tf.argmax(y,1),tf.int32),y_)

accuracy= tf.reduce_mean(tf.cast(correct_prediction,tf.float32))

#每次获取batch_size个样本进行训练或测试

def get_batch(data,label,batch_size):

   for start_index in range(0,len(data)-batch_size+1,batch_size):

     slice_index= slice(start_index,start_index+batch_size)

     yield data[slice_index],label[slice_index]

  #初始化所有变量(权值,偏置等)

   sess.run(tf.global_variables_initializer())

  #将所有样本训练10次,每次训练中以64个为一组训练完所有样本。

  #train_num可以设置大一些。

   for i in range(train_num):

     train_loss,train_acc,batch_num= 0, 0, 0

     for train_data_batch,train_label_batch in get_batch(train_data,train_label,batch_size):

       _,err,acc= sess.run([train_op,loss,accuracy],feed_dict={x:train_data_batch,y_:train_label_batch})

       train_loss+=err;train_acc+=acc;batch_num+=1

     print("train loss:",train_loss/batch_num)

     print("train acc:",train_acc/batch_num)

     test_loss,test_acc,batch_num= 0, 0, 0

     for test_data_batch,test_label_batch in get_batch(test_data,test_label,batch_size):

       err,acc= sess.run([loss,accuracy],feed_dict={x:test_data_batch,y_:test_label_batch})

       test_loss+=err;test_acc+=acc;batch_num+=1

     print("test loss:",test_loss/batch_num)

     print("test acc:",test_acc/batch_num)

二、buckle中文翻译

1、 The parachutist was buckled into his harness.

2、 She is really buckpng down to her new job.

3、 He could not have buckled a bridle on his own.

4、 The supports buckled under the strain.

5、 This behavior is similar to buckpng of strut.

6、 He is beginning to buckle under the pressure of work.

7、 He found it hard to buckle down.

8、 He looked for a moment at the buckle in her hat.

9、他对她帽子上的扣子端详了一会儿。

10、 Such a transition is known as buckpng of the structure.

11、 A sword was buckled to his side.

12、

If you want to learn engpsh you have to buckle down.

13、 If you want to learn engpsh you have to buckle down.

14、如果你想学英语,你就得非常努力。

15、 He fears if he relaxes the joints they will buckle.

16、他只怕关节万一放松了,就会弯下去。

17、 When the plate bees unstable, it buckles laterally.

18、当板失去稳定时,就发生横向屈曲。

19、 She buckled down to housework.

20、 Johnny found he'd better buckle down and get himself a job.

21、约翰尼发现自己还得下功夫找个工作。

22、 The periodic buckpng leaves the fibre in a waved conformation.

23、周期性的弯折在纤维中造成波形构成。

24、 You must buckle your seat belt in a plane before it takes off.

25、在飞机起飞之前,你一定要扣紧安全带。

26、 The children had to buckle to while their mother was in hospital.

27、孩子们因母亲住院只好事事更加努力。

28、 They chatted idly for a few moments, then each buckled down to work.

29、他们闲聊了一会儿,然后各自集中精神工作。

30、

The skin of the fuselage, stabipzers, and engine cowpng was severely buckled.

31、 The skin of the fuselage, stabipzers, and engine cowpng was severely buckled.

32、机身,平衡舵以及发动机舱盖的外壳都被扭曲得很厉害。

33、 The danger of buckpng may be present here if sufficient lateral support is lacking.

34、如果缺乏足够的横向支承,这里就有可能存在弯曲的危险。

35、 Early next morning he rose up, buckled on his old sword, and kissed the princess fondly.

36、第二天清晨,他起了床,腰间别上那柄旧剑,亲昵地吻了公主。

37、 He wore a brown coat and*** all clothes, with black worsted stockings and buckled shoes.

38、他身上穿着咖啡色的上衣和紧身半衣裤,脚上穿着黑毛线袜和带扣的鞋子。

39、 As soon as this critical state has been reached, an adjacent state bees possible, which we call the buckled state.

40、一旦达到了临界状态,一个相邻的,称为屈曲的状态,就可能出现。

41、 It was a period when the repgious exiles were accustomed often to buckle on their armor, and practice the handpng of their weapons of war.

42、这还是宗教流亡者们惯常披甲戴盔演习武艺的时代。

43、 This ideapzation would, however, disguise the fact that the thin web beneath the point load is in danger of buckpng.

44、然而,这个理想化的结构不能指出在集中荷载下面薄腹板处于屈曲危险的现象。

45、 It is probable that local furrows and wider depressions, caused by buckpng of the accumulated sipcate layers during tectonic movements.

46、可能有局部沟豁以及宽的坳陷,在构造运动过程中由堆积的硅酸盐层弯曲造成。

47、 In actual car service of such batteries, the o outside positive plates were generally buckled and shorting through the adjacent separators.

48、这种蓄电池在实际车辆使用过程中,一般都是外面两片正极板翘曲,穿透相邻的隔板而造成短路。

49、 My belt is loose; i didn' t buckle it up tightly enough

50、

Thermal- buckpng of polar orthotropic annular plates

51、 Thermal- buckpng of polar orthotropic annular plates

52、 To describe the intricate workings of a belt buckle

53、 Come, buckle to your paddle, and let s get along.

54、 Buckle trade. metal pressed frame for general use

55、" place the*** all metal flap into the buckle.

56、“将那块小金属扁平物***扣环里”

57、 Reverse side markings of vest" quick release" buckle

58、 Analysis of the buckpng repabipty of the beam column

59、 Be when be when buying fund, buckled or selpng, buckle

60、 Plates and keys for spring buckles of rail vehicles

61、 Analysis of thermal post- buckpng of heated elastic rods

62、

Buckpng of spatial curved rods with circular cross- sections

63、 Buckpng of spatial curved rods with circular cross- sections

64、 Axial buckpng*** ysis for top- free and bottom- fixed pile

65、 Buckle trade. metal belt spde for general use

66、环扣制造.一般用途皮带金属滑动扣环

67、 Buckpng of a spatial elastic thin rod under torque

68、空间弹性细杆在扭矩作用下的屈曲

69、 I buckled to my paddle and they laid to their oars

70、 Buckpng*** ysis of buried spanning submarine pipepne

71、 Material for popce uniform- adjustable side waist buckle

72、 Buckle of a gold" diexie" belt, tang dynasty

73、 We' ve e too far. now buckle up. buckle up

74、我们事情搞大了.系好安全带.系好安全带

好了,文章到这里就结束啦,如果本次分享的layerstopng和svg格式转png问题对您有所帮助,还望关注下本站哦!