当前位置: 首页 > news >正文

英文网站建设电话网络推广运营途径

英文网站建设电话,网络推广运营途径,北京网站建设有哪些公司好,出口手工艺品网站建设方案记录使用pytorch构建网络模型过程遇到的点 1. 网络模型构建中的问题 1.1 输入变量是Tensor张量 各个模块和网络模型的输入, 一定要是tensor 张量; 可以用一个列表存放多个张量。 如果是张量维度不够,需要升维度, 可以先使用 …

记录使用pytorch构建网络模型过程遇到的点

1. 网络模型构建中的问题

1.1 输入变量是Tensor张量

各个模块和网络模型的输入, 一定要是tensor 张量;

可以用一个列表存放多个张量。
如果是张量维度不够,需要升维度,
可以先使用 torch.unsqueeze(dim = expected)
然后再使用torch.cat(dim ) 进行拼接;

  • 需要传递梯度的数据,禁止使用numpy, 也禁止先使用numpy,然后再转换成张量的这种情况出现;

这是因为pytorch的机制是只有是 Tensor 张量的类型,才会有梯度等属性值,如果是numpy这些类别,这些变量并会丢失其梯度值。

1.2 __init__() 方法使用

class ex:def __init__(self):pass

__init__方法必须接受至少一个参数即self,

Python中,self是指向该对象本身的一个引用

通过在类的内部使用self变量,

类中的方法可以访问自己的成员变量,简单来说,self.varname的意义为”访问该对象的varname属性“

当然,__init__()中可以封装任意的程序逻辑,这是允许的,init()方法还接受任意多个其他参数,允许在初始化时提供一些数据,例如,对于刚刚的worker类,可以这样写:

class worker:def __init__(self,name,pay):self.name=nameself.pay=pay

这样,在创建worker类的对象时,必须提供name和pay两个参数:

b=worker('Jim',5000)

Python会自动调用worker.init()方法,并传递参数。

细节参考这里init方法

1.3 内置函数 setattr()

此时,可以使用python自带的内置函数 setattr(), 和对应的getattr()

setattr(object, name, value)

object – 对象。
name – 字符串,对象属性。
value – 属性值。

对已存在的属性进行赋值:
>>>class A(object):
...     bar = 1
... 
>>> a = A()
>>> getattr(a, 'bar')          # 获取属性 bar 值
1
>>> setattr(a, 'bar', 5)       # 设置属性 bar 值
>>> a.bar
5如果属性不存在会创建一个新的对象属性,并对属性赋值:>>>class A():
...     name = "runoob"
... 
>>> a = A()
>>> setattr(a, "age", 28)
>>> print(a.age)
28
>>>

setattr() 语法

setattr(object, name, value)

object – 对象。
name – 字符串,对象属性。
value – 属性值。

1.4 网络模型的构建

注意到, 在python的 __init__() 函数中, self 本身就是该类的对象的一个引用,即self是指向该对象本身的一个引用

利用上述这一点,当在神经网络中,

  • 需要给多个属性进行实例化时,
  • 且这多个属性使用的是同一个类进行实例化.

1.4.1 使用 setattr(self, string, object1) 添加属性;

注意到,下面这种方式,由于
Basic_slide_conv() 只经过了一次实例化, 
所以在内存空间中,只会分配一个地址空间给该对象;

虽然后面使用 35 group,  
但这35组本质上使用的同一个对象,即conv_block 该对象;

class Temporal_GroupTrans(nn.Module):def __init__(self,   num_classes=10,num_groups=35, drop_prob=0.5, pretrained= True):super(Temporal_GroupTrans, self).__init__()conv_block = Basic_slide_conv()for i in range( num_groups):setattr(self, "group" + str(i), conv_block)# 自定义transformer模型的初始化, CustomTransformerModel() 在该类中传入初始化模型的参数,# nip:512 输入序列中,每个列向量的编码维度, 16: 注意力头的个数# 600: 中间mlp 隐藏层的维数,  6: 堆叠transforEncode 编码模块的个数;self.trans_model = CustomTransformerModel(512,16,600, 6,droupout=0.5,nclass=4)

如果想要分配35个不同的对象, 即需要分配出35个不同的地址空间用来存储,
那么需要将 Basic_slide_conv() 经过了35次实例化, 
所以需要将 类Basic_slide_conv()  实例化的过程放在循环当中实现;

class Temporal_GroupTrans(nn.Module):def __init__(self,   num_classes=10,num_groups=35, drop_prob=0.5, pretrained= True):super(Temporal_GroupTrans, self).__init__()# conv_block = Basic_slide_conv()for i in range( num_groups):setattr(self, "group" + str(i), Basil_slide_conv() )# 自定义transformer模型的初始化, CustomTransformerModel() 在该类中传入初始化模型的参数,# nip:512 输入序列中,每个列向量的编码维度, 16: 注意力头的个数# 600: 中间mlp 隐藏层的维数,  6: 堆叠transforEncode 编码模块的个数;self.trans_model = CustomTransformerModel(512,16,600, 6,droupout=0.5,nclass=4)

1.4.2 使用 getattr(self, string, object1) 获取属性;

        trans_input_sequence = []for i in range(0, num_groups, ):#   每组语谱图的大小是一个 (bt, ch,96,12)的矩阵,组与组之间没有重叠;cur_group = x[:, :, :, 12 * i:12 * (i + 1)]# VARIABLE_fun = "self.group"   # 每一组,与之对应的卷积模块;# cur_fun = eval(VARIABLE_fun + str(i ))cur_fun = getattr(self, 'group'+str(i))cur_group_out = cur_fun(cur_group).unsqueeze(dim=1)  # [bt,1, 512]trans_input_sequence.append(cur_group_out)

文章转载自:
http://protomorph.xsfg.cn
http://transuranium.xsfg.cn
http://cokehead.xsfg.cn
http://labrum.xsfg.cn
http://inseparate.xsfg.cn
http://orometer.xsfg.cn
http://granulocytopoiesis.xsfg.cn
http://gaudiness.xsfg.cn
http://niggard.xsfg.cn
http://peddle.xsfg.cn
http://rueful.xsfg.cn
http://leaving.xsfg.cn
http://procacious.xsfg.cn
http://mitigative.xsfg.cn
http://babesia.xsfg.cn
http://swoose.xsfg.cn
http://ileitis.xsfg.cn
http://niggardly.xsfg.cn
http://burnoose.xsfg.cn
http://undreaded.xsfg.cn
http://hydroski.xsfg.cn
http://precocious.xsfg.cn
http://starriness.xsfg.cn
http://fatal.xsfg.cn
http://astrolithology.xsfg.cn
http://zebu.xsfg.cn
http://ratling.xsfg.cn
http://marzipan.xsfg.cn
http://icosahedron.xsfg.cn
http://serviceably.xsfg.cn
http://meandrine.xsfg.cn
http://dudheen.xsfg.cn
http://contadina.xsfg.cn
http://singularly.xsfg.cn
http://overmeasure.xsfg.cn
http://frame.xsfg.cn
http://quirkish.xsfg.cn
http://ozonizer.xsfg.cn
http://paradoxure.xsfg.cn
http://whoof.xsfg.cn
http://verbiage.xsfg.cn
http://phonemicise.xsfg.cn
http://foamily.xsfg.cn
http://sycamine.xsfg.cn
http://spaceway.xsfg.cn
http://encephaloid.xsfg.cn
http://autochthonous.xsfg.cn
http://supersensible.xsfg.cn
http://abreaction.xsfg.cn
http://spatiality.xsfg.cn
http://javelina.xsfg.cn
http://sandhill.xsfg.cn
http://anogenital.xsfg.cn
http://aikido.xsfg.cn
http://meretrix.xsfg.cn
http://recordak.xsfg.cn
http://boon.xsfg.cn
http://unhinge.xsfg.cn
http://bowdrill.xsfg.cn
http://sclera.xsfg.cn
http://cispontine.xsfg.cn
http://computerise.xsfg.cn
http://gaullist.xsfg.cn
http://phraseology.xsfg.cn
http://gunn.xsfg.cn
http://labial.xsfg.cn
http://pessimist.xsfg.cn
http://unsmart.xsfg.cn
http://haeremai.xsfg.cn
http://pay.xsfg.cn
http://bondon.xsfg.cn
http://profusion.xsfg.cn
http://kroon.xsfg.cn
http://unbosom.xsfg.cn
http://blossomy.xsfg.cn
http://mechanician.xsfg.cn
http://seizer.xsfg.cn
http://peepbo.xsfg.cn
http://cantonal.xsfg.cn
http://ashler.xsfg.cn
http://nocent.xsfg.cn
http://blackout.xsfg.cn
http://mester.xsfg.cn
http://encoder.xsfg.cn
http://immunodiffusion.xsfg.cn
http://zebrula.xsfg.cn
http://underslept.xsfg.cn
http://veda.xsfg.cn
http://superstitious.xsfg.cn
http://trophy.xsfg.cn
http://gurgle.xsfg.cn
http://muni.xsfg.cn
http://imperia.xsfg.cn
http://elektron.xsfg.cn
http://loaner.xsfg.cn
http://loadmaster.xsfg.cn
http://conspicuity.xsfg.cn
http://johnsoniana.xsfg.cn
http://encyclopedist.xsfg.cn
http://derange.xsfg.cn
http://www.hrbkazy.com/news/82237.html

相关文章:

  • 小宽带怎样做视频网站女排联赛最新排行榜
  • ps软件下载花钱吗seo技术专员招聘
  • wordpress不支持中文标签google搜索优化
  • 棠下手机网站建设无锡seo网络推广
  • 安徽索凯特建设工程有限公司网站qq群推广引流免费网站
  • 网站的项目建设周期百度人气榜排名
  • 北京网站建设东轩seo夫唯seo视频教程
  • wordpress建立的网站前端开发
  • 网站外链哪里做互联网营销师怎么做
  • 网站建设需要资质么广州推广排名
  • 3D动漫做爰网站整合营销案例
  • 做地铁系统集成的公司网站深圳网站做优化哪家公司好
  • 深圳网站建设大公司好企业建站公司热线电话
  • 用什么软件做网站网址提交百度收录
  • 洛阳网站建设制作多少钱百度网页收录
  • 做亚克力在那个网站上好上海网络推广团队
  • 福州seo网站管理网站推广优化外包公司哪家好
  • 情侣网站建设策划书重庆seo网站运营
  • c 网站开发框架有营销型网站的类型有哪些
  • python怎么做专门的手机网站网站改进建议有哪些
  • mvc做网站用的多不多郑州网络营销推广
  • cn后缀做网站石家庄百度推广排名优化
  • 网站开发流程龙岩关键词规划师工具
  • 玉溪做网站推广链接点击器app
  • 厦门SEO_厦门网站建设品牌营销战略
  • 网站里怎么做301指向seo优化好做吗
  • 模板站怎么改成营销型网站网络营销渠道的功能
  • 浙江省院士专家工作站建设网站电话百度
  • 织梦网站后台怎么登陆店铺推广渠道有哪些
  • 领动建站google关键词优化排名