tf.randm_normal和tf.constant

本文详细解析了TensorFlow中tf.Variable的初始化参数tf.random_normal与tf.constant。tf.random_normal通过指定形状、均值和标准差生成高斯分布的张量,而tf.constant则用于创建指定值和形状的常量张量。

以下两个函数都是tf.Variable中initializer的主要参数,目的是为了生成张量,下面简要的说下。

1.tf.random_normal
他的函数如下,就是一个高斯分布
在这里插入图片描述
即随机生成满足高斯分布的张量
tf.random.normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None)
shape:一个一维整数张量或python数组,代表张量形状
mean:数据类型为dtype或python数组的张量类型,正态分布的均值,对应整个分布的中心center
stddev:数据类型为dtype或python数组的张量类型,正态分布的标准差,越大模型越矮胖,越小越瘦高
dtype:输出的数据类型
seed:随机种子
name:操作的名称

可以只用一个参数shape,就是默认的高斯分布类型

2.tf.constant
他也是用来创建张量的
tf.constant(
value,
dtype=None,
shape=None,
name=‘Const’,
verify_shape=False
)
value:必选,可以是一个数也可以是一个列表
dtype:数据的类型
shape:数据的维度,若value是数字,那么所有的维度都是这个数,若value是列表,那么这个列表要小于等于shape的行列乘积才行
name:可以是任何内容
verify_shape:默认为false,若为true检查value的大小是否符合value,不符合会报错

<!DOCTYPE html> <!-- NOTES: 1. All tokens are represented by '$' sign in the template. 2. You can write your code only wherever mentioned. 3. All occurrences of existing tokens will be replaced by their appropriate values. 4. Blank lines will be removed automatically. 5. Remove unnecessary comments before creating your template. --> <html> <head> <meta charset="UTF-8"> <meta name="authoring-tool" content="Adobe_Animate_CC"> <title>012_a</title> <!-- write your code here --> <style> #animation_container, #_preload_div_ { position:absolute; margin:auto; left:0;right:0; top:0;bottom:0; } </style> <script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script> <script> function LoadGFonts(families, comp) { var lib=comp.getLibrary(); var googleObject = {type: "Google", loadedFonts: 0, totalFonts: families.length, callOnLoad: lib.gfontAvailable}; for(var i =0; i < families.length; i++) isFontAvailable(gFontsFamilies[i], googleObject); } function isFontAvailable(font, obj) { var timeOut = 5000; var delay = 200; var interval = 0; var timeElapsed = 0; function checkFont() { var node = document.createElement("span"); node.innerHTML = "giItT1WQy@!-/#"; node.style.position = "absolute"; node.style.left = "-1000px"; node.style.top = "-1000px"; node.style.fontSize = "300px"; node.style.fontFamily = "sans-serif"; node.style.fontVariant = "normal"; node.style.fontStyle = "normal"; node.style.fontWeight = "normal"; node.style.letterSpacing = "0"; document.body.appendChild(node); var width = node.offsetWidth; node.style.fontFamily = font+","+node.style.fontFamily; var returnVal = false; if((node && node.offsetWidth != width) || timeElapsed >=timeOut) { obj.loadedFonts++; if(interval) clearInterval(interval); obj.callOnLoad(font, obj.totalFonts); returnVal = true; } if(node) { node.parentNode.removeChild(node); node = null; } timeElapsed += delay; return returnVal; } if(!checkFont()) { interval = setInterval(checkFont, delay); } } </script> <script> var gFontsFamilies = ["Roboto"]; </script> <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:regular&subset=latin"> <script src="012_a.js?1554997525621"></script> <script> // Global Scripts // プレビュー時はスーパーリロードを使用(Macの場合) //Command + Shift + R //Chromeとサファリは画面クリックしないと音が出ない仕様らしい //alert("112"); アラート //ページ全体の色を変える場合、パブリッシュ後のhtmlの //<body>タグ内に background-color:rgba(0, 0, 0, 1.00); 例:黒 書き込んで変更する事 //animatecc内からでは操作できないらしい? var jump_fr = 0; //ブラックアウト後の移動フレーム var iziri_count = 0; //いじりアクションカウント //var speed_count = 0; //いじりスピードカウント var next_count = 0; //トータルいじり回数カウント var syokai_act = 0; //初回いじり判定 var serif_flg = [0,0]; //セリフフラグ function black_out (num) { jump_fr = num; exportRoot.black_out.gotoAndPlay(2); }; function randomizer1 (num) { var ran_num = Math.floor( Math.random() * num ); exportRoot.test_tex.text = "randm" + ran_num; return ran_num; }; var vo_rondom_num = 0; function vo_rondom (num) {//ボイスランダム var i = Math.floor( Math.random() * num ); if(i == vo_rondom_num){ i ++; }; if(i > (num - 1)){ i = 0; }; vo_rondom_num = i; //exportRoot.test_tex.text = i; return i; }; var se_rondom_num = 0; function se_rondom (num) {//seランダム var i = Math.floor( Math.random() * num ); if(i == se_rondom_num){ i ++; }; if(i > (num - 1)){ i = 0; }; se_rondom_num = i; //exportRoot.test_tex.text = i; return i; }; function start_func (evt) {//初回クリックスタート exportRoot.start_mc.gotoAndPlay("act1"); createjs.Sound.play("claick_se"); evt.currentTarget.removeEventListener('mousedown', start_func, false);//自分消去 //evt.remove(); ※自己消去機能せず //evt.currentTarget.removeEventListener('mousedown', arguments.callee, false);//自分消去 //※arguments.calleeでも可能だが非推奨らしい }; function act_func (evt) {//メイン操作 iziri_counter(1); if((exportRoot.main_mc.currentFrame >= 88) && (exportRoot.main_mc.currentFrame <= 147)){ exportRoot.main_mc.gotoAndPlay("brs2_ed") ; }; }; function iziri_counter (num) {//いじり回数カウンタ if((iziri_count + num <= 3)&&(iziri_count + num >= 0 )){ iziri_count += num; }; //exportRoot.test_tex.text = iziri_count; }; function next_counter (num) {//next回数カウンタ if((next_count + num <= 60)&&(next_count + num >= 0 )){ next_count += num; }; exportRoot.test_tex2.text = next_count; //ハート反映 heart_counter (num); }; //ハート増減 function heart_counter (num) {//next回数カウンタ if(num < 0){//マイナス(減る場合 if((next_count + num < 50) && (exportRoot.meter_mc.heart_mc3.currentFrame == 14)){ exportRoot.meter_mc.heart_mc3.gotoAndPlay("act2"); }else if((next_count + num < 30) && (exportRoot.meter_mc.heart_mc2.currentFrame == 14)){ exportRoot.meter_mc.heart_mc2.gotoAndPlay("act2"); }else if((next_count + num < 10) && (exportRoot.meter_mc.heart_mc1.currentFrame == 14)){ exportRoot.meter_mc.heart_mc1.gotoAndPlay("act2"); }; }else{//プラス 増える場合 if((next_count + num >= 55) && (exportRoot.meter_mc.heart_mc3.currentFrame == 0)){ exportRoot.meter_mc.heart_mc3.gotoAndPlay("act1"); }else if((next_count + num >= 35) && (exportRoot.meter_mc.heart_mc2.currentFrame == 0)){ exportRoot.meter_mc.heart_mc2.gotoAndPlay("act1"); }else if((next_count + num >= 15) && (exportRoot.meter_mc.heart_mc1.currentFrame == 0)){ exportRoot.meter_mc.heart_mc1.gotoAndPlay("act1"); }; }; }; //function replay_func (evt) {//リプレイボタン // iziri_count = 0; //いじりアクションカウント // next_count = 0; //トータルいじり回数カウント // syokai_act = 0; //初回いじり判定 // exportRoot.main_mc.gotoAndPlay("end"); // black_out (0); // evt.currentTarget.removeEventListener('mousedown', replay_func, false);//自分消去 // //};</script> <script> var canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation; function init() { canvas = document.getElementById("canvas"); anim_container = document.getElementById("animation_container"); dom_overlay_container = document.getElementById("dom_overlay_container"); var comp=AdobeAn.getComposition("E97E3F900F5A45D99B05755D6A83A742"); var lib=comp.getLibrary(); try { if(!(typeof gFontsFamilies === 'undefined' || gFontsFamilies === null)) LoadGFonts(gFontsFamilies, comp); if(!(typeof totalTypekitFonts === 'undefined' || totalTypekitFonts === null)) { var typekitObject = {type: 'Typekit', loadedFonts: 0, totalFonts: totalTypekitFonts, callOnLoad: lib.tfontAvailable}; Typekit.load({ async: true, 'fontactive': function(family) { isFontAvailable(family, typekitObject); } }); } } catch(e) {}; var loader = new createjs.LoadQueue(false); loader.installPlugin(createjs.Sound); loader.addEventListener("fileload", function(evt){handleFileLoad(evt,comp)}); loader.addEventListener("complete", function(evt){handleComplete(evt,comp)}); var lib=comp.getLibrary(); loader.loadManifest(lib.properties.manifest); } function handleFileLoad(evt, comp) { var images=comp.getImages(); if (evt && (evt.item.type == "image")) { images[evt.item.id] = evt.result; } } function handleComplete(evt,comp) { //This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage. var lib=comp.getLibrary(); var ss=comp.getSpriteSheet(); var queue = evt.target; var ssMetadata = lib.ssMetadata; for(i=0; i<ssMetadata.length; i++) { ss[ssMetadata[i].name] = new createjs.SpriteSheet( {"images": [queue.getResult(ssMetadata[i].name)], "frames": ssMetadata[i].frames} ) } var preloaderDiv = document.getElementById("_preload_div_"); preloaderDiv.style.display = 'none'; canvas.style.display = 'block'; exportRoot = new lib._012_a(); stage = new lib.Stage(canvas); //Registers the "tick" event listener. fnStartAnimation = function() { stage.addChild(exportRoot); createjs.Ticker.setFPS(lib.properties.fps); createjs.Ticker.addEventListener("tick", stage); } //Code to support hidpi screens and responsive scaling. function makeResponsive(isResp, respDim, isScale, scaleType) { var lastW, lastH, lastS=1; window.addEventListener('resize', resizeCanvas); resizeCanvas(); function resizeCanvas() { var w = lib.properties.width, h = lib.properties.height; var iw = window.innerWidth, ih=window.innerHeight; var pRatio = window.devicePixelRatio || 1, xRatio=iw/w, yRatio=ih/h, sRatio=1; if(isResp) { if((respDim=='width'&&lastW==iw) || (respDim=='height'&&lastH==ih)) { sRatio = lastS; } else if(!isScale) { if(iw<w || ih<h) sRatio = Math.min(xRatio, yRatio); } else if(scaleType==1) { sRatio = Math.min(xRatio, yRatio); } else if(scaleType==2) { sRatio = Math.max(xRatio, yRatio); } } canvas.width = w*pRatio*sRatio; canvas.height = h*pRatio*sRatio; canvas.style.width = anim_container.style.width = dom_overlay_container.style.width = preloaderDiv.style.width = w*sRatio+'px'; canvas.style.height = anim_container.style.height = dom_overlay_container.style.height = preloaderDiv.style.height = h*sRatio+'px'; stage.scaleX = pRatio*sRatio; stage.scaleY = pRatio*sRatio; lastW = iw; lastH = ih; lastS = sRatio; stage.tickOnUpdate = false; stage.update(); stage.tickOnUpdate = true; } } makeResponsive(true,'height',true,1); AdobeAn.compositionLoaded(lib.properties.id); fnStartAnimation(); } function playSound(id, loop) { return createjs.Sound.play(id, createjs.Sound.INTERRUPT_EARLY, 0, 0, loop); } </script> <!-- write your code here --> </head> <body onload="init();" style="margin:0px; background-color:rgba(0, 0, 0, 1.00);"> <div id="animation_container" style="background-color:rgba(0, 0, 0, 1.00); width:640px; height:1136px"> <canvas id="canvas" width="640" height="1136" style="position: absolute; display: none; background-color:rgba(0, 0, 0, 1.00);"></canvas> <div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:640px; height:1136px; position: absolute; left: 0px; top: 0px; display: none;"> </div> </div> <div id='_preload_div_' style='position:absolute; top:0; left:0; display: inline-block; height:1136px; width: 640px; text-align: center;'> <span style='display: inline-block; height: 100%; vertical-align: middle;'></span> <img src=images/_preloader.gif?1554997525622 style='vertical-align: middle; max-height: 100%'/></div> </body> </html>解析代码
最新发布
01-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值