aliyun-rtc-sdk 6.11.3-beta.5 → 6.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aliyun-rtc-sdk.js +6 -6
- package/dist/plugins/beautyPlugin.js +178 -178
- package/dist/plugins/queen-FlAAeipC.js +1 -0
- package/dist/plugins/queen-full-DgUzXXaA.js +1 -0
- package/dist/plugins/queen-lite-BcW1Sf7f.js +1 -0
- package/dist/plugins/queen-pro-BF2LwKO0.js +1 -0
- package/dist/plugins/queen-simd-DQQCU-XB.js +1 -0
- package/dist/plugins/queen-simd-full-CgzwfIzl.js +1 -0
- package/dist/plugins/queen-simd-lite-DfCTDs0x.js +1 -0
- package/dist/plugins/queen-simd-pro-Dp0ynTmZ.js +1 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +5 -4
- package/dist/plugins/queen-bb600e27.js +0 -1
- package/dist/plugins/queen-full-018b0563.js +0 -1
- package/dist/plugins/queen-lite-c4ef0218.js +0 -1
- package/dist/plugins/queen-pro-ab2bf928.js +0 -1
- package/dist/plugins/queen-simd-120164b8.js +0 -1
- package/dist/plugins/queen-simd-full-ef25016f.js +0 -1
- package/dist/plugins/queen-simd-lite-abe5b2f5.js +0 -1
- package/dist/plugins/queen-simd-pro-5ba58a81.js +0 -1
- /package/dist/plugins/{Empty-afb87ea8.js → Empty-FmFgRqLi.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"@/core/plugin";function t(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}var n,s=Object.defineProperty,r=(e,t,n)=>(((e,t,n)=>{t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),a=((n=a||{})[n.SkinBuffing=0]="SkinBuffing",n[n.FaceBuffing=1]="FaceBuffing",n[n.Makeup=2]="Makeup",n[n.FaceShape=3]="FaceShape",n[n.SkinWhiting=4]="SkinWhiting",n[n.LUT=5]="LUT",n[n.BackgroundProcess=6]="BackgroundProcess",n[n.AutoFilter=7]="AutoFilter",n[n.BodyShape=8]="BodyShape",n[n.HandGestureDetect=9]="HandGestureDetect",n[n.Max=10]="Max",n),i=(e=>(e[e.None=0]="None",e[e.Horizontal=1]="Horizontal",e[e.Vertical=2]="Vertical",e[e.Both=3]="Both",e[e.Max=4]="Max",e))(i||{}),o=(e=>(e[e.SkinBuffing=1]="SkinBuffing",e[e.Sharpen=2]="Sharpen",e[e.Whitening=3]="Whitening",e[e.Pouch=4]="Pouch",e[e.NasolabialFolds=5]="NasolabialFolds",e[e.LUT=6]="LUT",e[e.WhiteTeeth=7]="WhiteTeeth",e[e.Lipstick=8]="Lipstick",e[e.Blush=9]="Blush",e[e.LipstickColorParam=10]="LipstickColorParam",e[e.LipstickGlossParam=11]="LipstickGlossParam",e[e.LipstickBrightnessParam=12]="LipstickBrightnessParam",e[e.BrightenEye=13]="BrightenEye",e[e.SkinRed=14]="SkinRed",e[e.Wrinkles=15]="Wrinkles",e[e.BrightenFace=16]="BrightenFace",e[e.AutoLRate=17]="AutoLRate",e[e.AutoARate=18]="AutoARate",e[e.AutoBRate=19]="AutoBRate",e))(o||{}),u=(e=>(e[e.FullBody=0]="FullBody",e[e.LongLag=1]="LongLag",e[e.SmallHead=2]="SmallHead",e[e.ThinLag=3]="ThinLag",e[e.LongNeck=4]="LongNeck",e[e.ThinWaist=5]="ThinWaist",e[e.EnhanceBreast=6]="EnhanceBreast",e[e.ThinArm=7]="ThinArm",e[e.MAX=8]="MAX",e))(u||{}),l=(e=>(e[e.Whole=0]="Whole",e[e.Highlight=1]="Highlight",e[e.Eyeball=2]="Eyeball",e[e.Mouth=3]="Mouth",e[e.Wocan=4]="Wocan",e[e.EyeBrow=5]="EyeBrow",e[e.Blush=6]="Blush",e[e.EyeShadow=7]="EyeShadow",e[e.Eyeliner=8]="Eyeliner",e[e.Eyelash=9]="Eyelash",e[e.MakeupMax=10]="MakeupMax",e))(l||{}),c=(e=>(e[e.CutCheek=0]="CutCheek",e[e.CutFace=1]="CutFace",e[e.ThinFace=2]="ThinFace",e[e.LongFace=3]="LongFace",e[e.LowerJaw=4]="LowerJaw",e[e.HigherJaw=5]="HigherJaw",e[e.ThinJaw=6]="ThinJaw",e[e.ThinMandible=7]="ThinMandible",e[e.BigEye=8]="BigEye",e[e.EyeAngle1=9]="EyeAngle1",e[e.Canthus=10]="Canthus",e[e.Canthus1=11]="Canthus1",e[e.EyeAngle2=12]="EyeAngle2",e[e.EyeTDAngle=13]="EyeTDAngle",e[e.ThinNose=14]="ThinNose",e[e.Nosewing=15]="Nosewing",e[e.NasalHeight=16]="NasalHeight",e[e.NoseTipHeight=17]="NoseTipHeight",e[e.MouthWidth=18]="MouthWidth",e[e.MouthSize=19]="MouthSize",e[e.MouthHigh=20]="MouthHigh",e[e.Philtrum=21]="Philtrum",e[e.HairLine=22]="HairLine",e[e.Smile=23]="Smile",e[e.MAX=24]="MAX",e))(c||{}),h=(e=>(e[e.Normal=0]="Normal",e[e.Lighten=1]="Lighten",e[e.Darken=2]="Darken",e[e.Multiply=3]="Multiply",e[e.Divide=4]="Divide",e[e.Average=5]="Average",e[e.Add=6]="Add",e[e.Subtract=7]="Subtract",e[e.Difference=8]="Difference",e[e.Negation=9]="Negation",e[e.Exclusion=10]="Exclusion",e[e.Screen=11]="Screen",e[e.Overlay=12]="Overlay",e[e.SoftLight=13]="SoftLight",e[e.HardLight=14]="HardLight",e[e.ColorDodge=15]="ColorDodge",e[e.ColorBurn=16]="ColorBurn",e[e.LinearDodge=17]="LinearDodge",e[e.LinearBurn=18]="LinearBurn",e[e.LinearLight=19]="LinearLight",e[e.VividLight=20]="VividLight",e[e.PinLight=21]="PinLight",e[e.HardMix=22]="HardMix",e[e.Reflect=23]="Reflect",e[e.Glow=24]="Glow",e[e.Phoenix=25]="Phoenix",e[e.Hue=26]="Hue",e[e.Saturation=27]="Saturation",e[e.Luminosity=28]="Luminosity",e[e.Color=29]="Color",e[e.Curve=30]="Curve",e[e.LabMix=31]="LabMix",e[e.Max=32]="Max",e))(h||{}),d=(e=>(e[e.kBackgroundBlur=0]="kBackgroundBlur",e[e.kBackgroundTransparent=1]="kBackgroundTransparent",e[e.kBackgroundNormal=2]="kBackgroundNormal",e))(d||{}),p=(e=>(e[e.Auto=0]="Auto",e[e.Quality=1]="Quality",e[e.Balanced=2]="Balanced",e[e.Performance=3]="Performance",e))(p||{}),f=(e=>(e[e.Lite=0]="Lite",e[e.Advance=1]="Advance",e[e.Pro=2]="Pro",e[e.Full=3]="Full",e))(f||{}),m=(e=>(e[e.Initialize=100]="Initialize",e[e.Render=101]="Render",e[e.RenderMediaObjectToTexture=102]="RenderMediaObjectToTexture",e[e.RenderTextureId=103]="RenderTextureId",e[e.RenderWithTextureId=104]="RenderWithTextureId",e[e.RenderWithMediaObject=105]="RenderWithMediaObject",e[e.MediaStreamRender=106]="MediaStreamRender",e[e.EngineDestory=107]="EngineDestory",e[e.RenderWorkerTest=110]="RenderWorkerTest",e[e.SetQueenBeautyType=200]="SetQueenBeautyType",e[e.SetQueenBeautyParams=201]="SetQueenBeautyParams",e[e.SetLutImageUrl=203]="SetLutImageUrl",e[e.SetFaceShape=204]="SetFaceShape",e[e.SetMakeupWithUrl=205]="SetMakeupWithUrl",e[e.SetMakeupWithPackage=206]="SetMakeupWithPackage",e[e.SetMakeupAlphaWithType=207]="SetMakeupAlphaWithType",e[e.SetMakeupBlendWithType=208]="SetMakeupBlendWithType",e[e.ResetAllMakeupType=209]="ResetAllMakeupType",e[e.AddMaterialWithUrl=210]="AddMaterialWithUrl",e[e.RemoveMaterialWithUrl=211]="RemoveMaterialWithUrl",e[e.SetPowerSaving=212]="SetPowerSaving",e[e.SetMakeupWithTypeFps=213]="SetMakeupWithTypeFps",e[e.SetBodyShape=214]="SetBodyShape",e[e.SetEngineParams=215]="SetEngineParams",e[e.SetGreenScreenWithUrl=300]="SetGreenScreenWithUrl",e[e.EnableBokehBackground=301]="EnableBokehBackground",e[e.SetSegmentBackgroundUrl=302]="SetSegmentBackgroundUrl",e[e.SetSegmentBackgroundProcessType=303]="SetSegmentBackgroundProcessType",e[e.SetAISegmentForegroundPadding=304]="SetAISegmentForegroundPadding",e[e.SetPureColorBackgroundUrl=305]="SetPureColorBackgroundUrl",e[e.LoadResourceFileWithUrl=401]="LoadResourceFileWithUrl",e[e.LoadResourceFileWithUrlSaveAs=402]="LoadResourceFileWithUrlSaveAs",e[e.LoadResourceFileWithData=403]="LoadResourceFileWithData",e[e.CheckResourceFile=404]="CheckResourceFile",e[e.LoadQueenAssets=405]="LoadQueenAssets",e[e.ShowFaceDetectPoint=500]="ShowFaceDetectPoint",e[e.ShowMakeupLine=501]="ShowMakeupLine",e[e.ShowBodyDetectPoint=502]="ShowBodyDetectPoint",e[e.GetQueenBeautyParams=503]="GetQueenBeautyParams",e[e.ShowQueenParam=504]="ShowQueenParam",e[e.ShowQueenParamJson=505]="ShowQueenParamJson",e[e.SetArWriting=600]="SetArWriting",e[e.CleanScreenArWriting=601]="CleanScreenArWriting",e[e.AnimojiInitialize=700]="AnimojiInitialize",e[e.SetAnimojiBackgroundWithMode=701]="SetAnimojiBackgroundWithMode",e[e.AnimojiRender=702]="AnimojiRender",e[e.AnimojiRenderWithMediaObject=703]="AnimojiRenderWithMediaObject",e[e.AnimojiRenderMediaObjectToTexture=704]="AnimojiRenderMediaObjectToTexture",e[e.AnimojiRenderTextureId=705]="AnimojiRenderTextureId",e[e.AnimojiResize=706]="AnimojiResize",e[e.AnimojiDestroy=707]="AnimojiDestroy",e))(m||{}),g=(e=>(e[e.Initialize=1e3]="Initialize",e[e.LoaddingProgress=1001]="LoaddingProgress",e[e.Render=1002]="Render",e[e.RenderWithTextureId=1003]="RenderWithTextureId",e[e.RenderTextureId=1004]="RenderTextureId",e[e.RenderImageData=1005]="RenderImageData",e[e.RenderImageBuffer=1006]="RenderImageBuffer",e[e.LoadUrlComplate=4001]="LoadUrlComplate",e[e.GetQueenBeautyParams=5e3]="GetQueenBeautyParams",e[e.GetQueenBeautyParamsConfig=5001]="GetQueenBeautyParamsConfig",e[e.ShowQueenParam=5002]="ShowQueenParam",e[e.Complate=6e3]="Complate",e[e.Fail=6001]="Fail",e[e.State=6002]="State",e[e.RenderComplate=6003]="RenderComplate",e[e.RenderTimestamp=9e3]="RenderTimestamp",e))(g||{}),y=(e=>(e[e.kLogNone=0]="kLogNone",e[e.kLogError=1]="kLogError",e[e.kLogWarning=2]="kLogWarning",e[e.kLogInfo=3]="kLogInfo",e[e.kLogDebug=4]="kLogDebug",e))(y||{}),b=(e=>(e[e.Auto=0]="Auto",e[e.WebGL=1]="WebGL",e[e.WebGPU=2]="WebGPU",e[e.Max=3]="Max",e))(b||{});const x="https://g.alicdn.com/apsara-media-box/imp-web-queen-wasm/6.3.3/dist/",w=x+"queen_res/",k="sticker/",v=["bimuyu.2.1.png","lingjing.2.1.png","liwu.2.1.png","meidusha.2.1.png","milanda.2.1.png","ningmengcao.2.1.png","senlin.2.1.png","siyecao.2.1.png","wanhuatong.2.1.png"],I=["1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png"],S=["anyezi.1.2.3.bin","chidousha.1.2.3.bin","fuguse.1.2.3.bin","guimeihong.1.2.3.bin","jiangguose.1.2.3.bin","nanguase.1.2.3.bin","shiliuhong.1.2.3.bin","shipshape.1.2.3.bin","standout.1.2.3.bin"],C=["biaozhunmei.2.3.png","cupingmei.2.3.png","juanyanmei.2.3.png","liuxingmei.2.3.png","liuyemei.2.3.png","qiubomei.2.3.png","wanyuemei.2.3.png","xinyuemei.2.3.png","yeshengmei.2.3.png"],N=["biaozhunmei.2.3.bin","cupingmei.2.3.bin","juanyanmei.2.3.bin","liuxingmei.2.3.bin","liuyemei.2.3.bin","qiubomei.2.3.bin","wanyuemei.2.3.bin","xinyuemei.2.3.bin","yeshengmei.2.3.bin"],T=["1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png"],$=["dadise.1.2.3.bin","fangtangfen.1.2.3.bin","fuguse.1.2.3.bin","huoliju.1.2.3.bin","jinzongse.1.2.3.bin","pengkezong.1.2.3.bin","xingguangfen.1.2.3.bin","yanfense.1.2.3.bin","yeqiangwei.1.2.3.bin"],R=["dayan.2.3.png","guima.2.3.png","juanqiao.2.3.png","keai.2.3.png","lingdong.2.3.png","qizhi.2.3.png","wenrou.2.3.png","wugu.2.3.png","xiaoyemao.2.3.png"],E=["chenjing.2.3.png","huopo.2.3.png","jichu.2.3.png","keai.2.3.png","lingdong.2.3.png","shaonv.2.3.png","wugu.2.3.png","yesheng.2.3.png","zhixing.2.3.png"],A=["blush_wugu.2.3.png","chayi.2.3.png","chulian.2.3.png","chunqing.2.3.png","qiji.2.3.png","shaonv.2.3.png"],_=["huoli.2.31.png","jichu.2.31.png","meihuo.2.31.png","meizi.2.31.png","mitao.2.31.png","naiju.2.31.png","xingfen.2.31.png","youya.2.31.png","yuanqishaonv.2.31.png"],F=["highlight.2.12.png"],D=["M1.png","M2.png","M3.png","M4.png","M5.png","M6.png","M7.png","M8.png","PF1.png","PF2.png","PF3.png","PF4.png","PF5.png","PF6.png","PF7.png","PF8.png","PF9.png","PFA.png","PFB.png","PFC.png","PI4.png","PL1.png","PI1.png","PI2.png","PI3.png","PL2.png","PL3.png","PL4.png","PJ1.png","PJ2.png","PJ3.png","PJ4.png","delta.png","electric.png","faded.png","slowlived.png","urbex.png","warm.png","F4.png","F5.png","tokoyo.png","F1.png","F2.png","F3.png","F6.png","F7.png","PV1.png","PV2.png","PV3.png","PV4.png","PV5.png","PV6.png","A1.png","A2.png","A3.png","A4.png","A5.png","A6.png"];var M=(e=>(e[e.BiMuYu=0]="BiMuYu",e[e.LingJing=1]="LingJing",e[e.LiWu=2]="LiWu",e[e.MeiDuSha=3]="MeiDuSha",e[e.MiLanDa=4]="MiLanDa",e[e.NingMengCao=5]="NingMengCao",e[e.SenLin=6]="SenLin",e[e.SiYeCao=7]="SiYeCao",e[e.WanHuaTong=8]="WanHuaTong",e))(M||{}),O=(e=>(e[e.AnYeZi=0]="AnYeZi",e[e.ChiDouSha=1]="ChiDouSha",e[e.FuGuSe=2]="FuGuSe",e[e.GuiMeiHong=3]="GuiMeiHong",e[e.JiangGuoSe=4]="JiangGuoSe",e[e.NanGuaSe=5]="NanGuaSe",e[e.ShiLiuHong=6]="ShiLiuHong",e[e.ShipShape=7]="ShipShape",e[e.StandOut=8]="StandOut",e))(O||{}),L=(e=>(e[e.BiaoZhunMei=0]="BiaoZhunMei",e[e.CuPingMei=1]="CuPingMei",e[e.JuanYanMei=2]="JuanYanMei",e[e.LiuXingMei=3]="LiuXingMei",e[e.LiuYeMei=4]="LiuYeMei",e[e.QiuBoMei=5]="QiuBoMei",e[e.WanYueMei=6]="WanYueMei",e[e.XinYueMei=7]="XinYueMei",e[e.YeShengMei=8]="YeShengMei",e))(L||{}),P=(e=>(e[e.DaDiSe=0]="DaDiSe",e[e.FangTangFen=1]="FangTangFen",e[e.FuGuSe=2]="FuGuSe",e[e.HuoLiJu=3]="HuoLiJu",e[e.JinZongSe=4]="JinZongSe",e[e.PengKeZong=5]="PengKeZong",e[e.XingGuangFen=6]="XingGuangFen",e[e.YanFenSe=7]="YanFenSe",e[e.YeQiangWei=8]="YeQiangWei",e))(P||{}),z=(e=>(e[e.DaYan=0]="DaYan",e[e.GuiMa=1]="GuiMa",e[e.JuanQiao=2]="JuanQiao",e[e.KeAi=3]="KeAi",e[e.LingDong=4]="LingDong",e[e.QiZhi=5]="QiZhi",e[e.WenRou=6]="WenRou",e[e.WuGu=7]="WuGu",e[e.XiaoYeMao=8]="XiaoYeMao",e))(z||{}),B=(e=>(e[e.ChenJing=0]="ChenJing",e[e.HuoPo=1]="HuoPo",e[e.JiChu=2]="JiChu",e[e.KeAi=3]="KeAi",e[e.LingDong=4]="LingDong",e[e.ShaoNv=5]="ShaoNv",e[e.WuGu=6]="WuGu",e[e.YeSheng=7]="YeSheng",e[e.ZhiXing=8]="ZhiXing",e))(B||{}),W=(e=>(e[e.BlushWuGu=0]="BlushWuGu",e[e.ChaYi=1]="ChaYi",e[e.ChuLian=2]="ChuLian",e[e.ChunQing=3]="ChunQing",e[e.QiJi=4]="QiJi",e[e.ShaoNv=5]="ShaoNv",e))(W||{}),U=(e=>(e[e.HuoLi=0]="HuoLi",e[e.JiChu=1]="JiChu",e[e.MeiHuo=2]="MeiHuo",e[e.MeiZi=3]="MeiZi",e[e.MiTao=4]="MiTao",e[e.NaiJu=5]="NaiJu",e[e.XingFen=6]="XingFen",e[e.YouYa=7]="YouYa",e[e.YuanQiShaoNv=8]="YuanQiShaoNv",e))(U||{}),V=(e=>(e[e.Highlight=0]="Highlight",e))(V||{}),G=(e=>(e[e.BrownBear=0]="BrownBear",e[e.Ding3Duo=1]="Ding3Duo",e[e.Pumpkin=2]="Pumpkin",e[e.Rabbit=3]="Rabbit",e[e.RedPanda=4]="RedPanda",e[e.SanXingDui=5]="SanXingDui",e[e.TaoGongZai=6]="TaoGongZai",e))(G||{}),H=(e=>(e[e.M1=0]="M1",e[e.M2=1]="M2",e[e.M3=2]="M3",e[e.M4=3]="M4",e[e.M5=4]="M5",e[e.M6=5]="M6",e[e.M7=6]="M7",e[e.M8=7]="M8",e[e.PF1=8]="PF1",e[e.PF2=9]="PF2",e[e.PF3=10]="PF3",e[e.PF4=11]="PF4",e[e.PF5=12]="PF5",e[e.PF6=13]="PF6",e[e.PF7=14]="PF7",e[e.PF8=15]="PF8",e[e.PF9=16]="PF9",e[e.PFA=17]="PFA",e[e.PFB=18]="PFB",e[e.PFC=19]="PFC",e[e.PI4=20]="PI4",e[e.PL1=21]="PL1",e[e.PI1=22]="PI1",e[e.PI2=23]="PI2",e[e.PI3=24]="PI3",e[e.PL2=25]="PL2",e[e.PL3=26]="PL3",e[e.PL4=27]="PL4",e[e.PJ1=28]="PJ1",e[e.PJ2=29]="PJ2",e[e.PJ3=30]="PJ3",e[e.PJ4=31]="PJ4",e[e.Delta=32]="Delta",e[e.Electric=33]="Electric",e[e.Faded=34]="Faded",e[e.Slowlived=35]="Slowlived",e[e.Urbex=36]="Urbex",e[e.Warm=37]="Warm",e[e.F4=38]="F4",e[e.F5=39]="F5",e[e.Tokoyo=40]="Tokoyo",e[e.F1=41]="F1",e[e.F2=42]="F2",e[e.F3=43]="F3",e[e.F6=44]="F6",e[e.F7=45]="F7",e[e.PV1=46]="PV1",e[e.PV2=47]="PV2",e[e.PV3=48]="PV3",e[e.PV4=49]="PV4",e[e.PV5=50]="PV5",e[e.PV6=51]="PV6",e[e.A1=52]="A1",e[e.A2=53]="A2",e[e.A3=54]="A3",e[e.A4=55]="A4",e[e.A5=56]="A5",e[e.A6=57]="A6",e))(H||{}),q=(e=>(e[e.ILoveChina=0]="ILoveChina",e[e.HongXing=1]="HongXing",e[e.HuDieJie=2]="HuDieJie",e[e.MiLaoShu=3]="MiLaoShu",e[e.LuJiao=4]="LuJiao",e[e.KuaiLeXingQiu=5]="KuaiLeXingQiu",e[e.KeAi=6]="KeAi",e[e.DaiMoJing1=0]="DaiMoJing1",e[e.MaoZi=0]="MaoZi",e[e.DaiMoJing2=0]="DaiMoJing2",e[e.XiaoKeAi=0]="XiaoKeAi",e[e.XiaRiXiGua=0]="XiaRiXiGua",e[e.XiaoMaoMi=0]="XiaoMaoMi",e[e.NvWang=0]="NvWang",e[e.DanGao=0]="DanGao",e[e.MiaoSha=0]="MiaoSha",e[e.NianHuoJie=0]="NianHuoJie",e[e.MianDanFanJu=0]="MianDanFanJu",e[e.ZhouNianQing=0]="ZhouNianQing",e[e.ShiShen=0]="ShiShen",e[e.Com=0]="Com",e[e.Gdp=0]="Gdp",e[e.DiaoBao=0]="DiaoBao",e[e.WuMei=0]="WuMei",e[e.Icon=0]="Icon",e[e.CaiHong=0]="CaiHong",e[e.DaHuZi1=0]="DaHuZi1",e[e.ShouZhang=0]="ShouZhang",e[e.HeiGuo=0]="HeiGuo",e[e.BBTV=0]="BBTV",e[e.FenDou=0]="FenDou",e[e.HongSheng=0]="HongSheng",e[e.XiZhuang=0]="XiZhuang",e[e.MeiHuo=0]="MeiHuo",e[e.Money=0]="Money",e[e.BoLiXin=0]="BoLiXin",e[e.KPI=0]="KPI",e[e.FenNu=0]="FenNu",e[e.XiaoXingXing=0]="XiaoXingXing",e[e.LiWu=0]="LiWu",e[e.QueShen=0]="QueShen",e[e.MaoMi2=0]="MaoMi2",e[e.HaiXiu=0]="HaiXiu",e[e.ChiXueGao=0]="ChiXueGao",e[e.GongZuoKuang=0]="GongZuoKuang",e[e.FuMo=0]="FuMo",e[e.NvShen=0]="NvShen",e[e.DaShen=0]="DaShen",e[e.BaJian=0]="BaJian",e[e.HuaXin=0]="HuaXin",e[e.DaHuZi2=0]="DaHuZi2",e[e.Christmas1=0]="Christmas1",e[e.Christmas2=0]="Christmas2",e[e.Christmas3=0]="Christmas3",e))(q||{});function j(){}j.getMakeupEyeBallUrl=function(e){return w+"makeup/eyeball/"+v[e]},j.getMakeupMouthRes=function(e){return[I[e],w+"makeup/mouth_yaochun/"+S[e]]},j.getMakeupEyeBrowRes=function(e){return[C[e],w+"makeup/eyebrow/"+N[e]]},j.getMakeupEyeShadowRes=function(e){return[T[e],w+"makeup/eyeshadow/"+$[e]]},j.getMakeupEyeLinerUrl=function(e){return w+"makeup/eyeliner/"+R[e]},j.getMakeupEyeLashUrl=function(e){return w+"makeup/eyelash/"+E[e]},j.getMakeupBlushUrl=function(e){return w+"makeup/blush/"+A[e]},j.getMakeupWholeUrl=function(e){return w+"makeup/whole/"+_[e]},j.getMakeupHighLightUrl=function(e){return w+"makeup/highlight/"+F[e]},j.getLutUrl=function(e){return w+"lookups/"+D[e]},j.getStickerUrl=function(e){return w+k+e+".bin"},j.getStickerUrlByIndex=function(e){return w+k+e+".bin"};const X=Object.freeze(Object.defineProperty({__proto__:null,QueenAssets:j,kAnimojiRes:G,kResLut:H,kResMakeupBlush:W,kResMakeupEyeBall:M,kResMakeupEyeBrow:L,kResMakeupEyeLash:B,kResMakeupEyeLiner:z,kResMakeupEyeShadow:P,kResMakeupHighLight:V,kResMakeupMouth:O,kResMakeupWhole:U,kResSticker:q},Symbol.toStringTag,{value:"Module"}));class K{constructor(){r(this,"_readResourceData",((e,t,n)=>{n()})),r(this,"clearAssetsCache",(()=>{}))}loadResourceData(e,t,n,s,r,a){const i=this;this._readResourceData(e,(function(e){t&&t((r+1)/a*100),n(e)}),(function(){i.fetchRemotePackage(e,t,(function(s){t&&t((r+1)/a*100),i.saveResourceData(e,s),n(s)}),s,r,a)}))}fetchRemotePackage(e,t,n,s,r=0,a=1){const i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onprogress=function(e){e.loaded&&e.total&&t&&t(100*r/a+e.loaded/e.total*100*(1/a))},i.onerror=function(){throw s(),new Error("NetworkError for: "+e)},i.onload=function(){if(!(200===i.status||304===i.status||206===i.status||0===i.status&&i.response))throw s(),new Error(i.statusText+" : "+i.responseURL);{const e=i.response;n&&n(e)}},i.send(null)}saveResourceData(e,t){}EncodeName(e){}}var Y=Object.defineProperty,Q=(e,t,n)=>(((e,t,n)=>{t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),J=(e,t,n)=>new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));let Z=class{constructor(e){Q(this,"webglContext"),Q(this,"renderProgram"),Q(this,"glVertexBuff"),Q(this,"glTexBuff"),Q(this,"glVloc"),Q(this,"glTloc"),Q(this,"width"),Q(this,"height"),Q(this,"getBufferSubData",(function(e,t,n){const s=this.webglContext,r=s.createBuffer();s.bindBuffer(s.PIXEL_PACK_BUFFER,r),s.bufferData(s.PIXEL_PACK_BUFFER,t*n*4,s.DYNAMIC_READ);const a=s.createFramebuffer();s.bindFramebuffer(s.FRAMEBUFFER,a),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,e,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.bindBuffer(s.PIXEL_PACK_BUFFER,r);let i=new Uint8Array(t*n*4);return s.getBufferSubData(s.PIXEL_PACK_BUFFER,0,i),i})),this.webglContext=e,this.width=e.canvas.width,this.height=e.canvas.height;const t=this.loadShader(e.VERTEX_SHADER,"attribute vec2 aVertex;attribute vec2 aUV;varying vec2 vTex;uniform vec2 pos;void main(void) { gl_Position = vec4(aVertex + pos, 0.0, 1.0); vTex = aUV;}"),n=this.loadShader(e.FRAGMENT_SHADER,"precision mediump float;varying vec2 vTex;uniform sampler2D sampler0;void main(void){ gl_FragColor = texture2D(sampler0, vTex);}");this.renderProgram=e.createProgram(),null!=t&&null!=n&&(e.attachShader(this.renderProgram,t),e.attachShader(this.renderProgram,n),e.linkProgram(this.renderProgram),this.glVertexBuff=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.glVertexBuff),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),e.STATIC_DRAW),this.glTexBuff=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.glTexBuff),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,0,1,1]),e.STATIC_DRAW),this.glVloc=e.getAttribLocation(this.renderProgram,"aVertex"),this.glTloc=e.getAttribLocation(this.renderProgram,"aUV"))}loadShader(e,t){const n=this.webglContext,s=n.createShader(e);return s?(n.shaderSource(s,t),n.compileShader(s),s):null}drawTexture(e,t,n){const s=this.webglContext;null!==s&&null!==e&&(null==t&&(t=this.width),null==n&&(n=this.height),s.useProgram(this.renderProgram),s.viewport(0,0,t,n),s.enableVertexAttribArray(this.glVloc),s.bindBuffer(s.ARRAY_BUFFER,this.glVertexBuff),s.vertexAttribPointer(this.glVloc,2,s.FLOAT,!1,0,0),s.enableVertexAttribArray(this.glTloc),s.bindBuffer(s.ARRAY_BUFFER,this.glTexBuff),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,e),s.vertexAttribPointer(this.glTloc,2,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLE_FAN,0,4),s.disableVertexAttribArray(this.glVloc),s.disableVertexAttribArray(this.glTloc),s.bindTexture(s.TEXTURE_2D,null))}createBlankTexture(e=1,t=1){const n=this.webglContext,s=n.createTexture();return n.bindTexture(n.TEXTURE_2D,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.bindTexture(n.TEXTURE_2D,null),s}createMediaTexture(e){const t=this.webglContext;t.pixelStorei(t.UNPACK_ALIGNMENT,4);const n=t.createTexture();return t.bindTexture(t.TEXTURE_2D,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),n}createBufferTexture(e,t,n){const s=this.webglContext;s.pixelStorei(s.UNPACK_ALIGNMENT,4);const r=s.createTexture();return s.bindTexture(s.TEXTURE_2D,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,t,n,0,s.RGBA,s.UNSIGNED_BYTE,e),s.bindTexture(s.TEXTURE_2D,null),r}updateTexture(e,t){const n=this.webglContext;n.pixelStorei(n.UNPACK_ALIGNMENT,4),n.bindTexture(n.TEXTURE_2D,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t),n.bindTexture(n.TEXTURE_2D,null)}updateTextureData(e,t,n,s){const r=this.webglContext;r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.bindTexture(r.TEXTURE_2D,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,n,s,0,r.RGBA,r.UNSIGNED_BYTE,t),r.bindTexture(r.TEXTURE_2D,null)}readPixels(e,t,n){const s=this.webglContext,r=new Uint8Array(t*n*4),a=s.createFramebuffer();return s.bindFramebuffer(s.FRAMEBUFFER,a),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,e,0),s.pixelStorei(s.PACK_ALIGNMENT,4),s.readPixels(0,0,t,n,s.RGBA,s.UNSIGNED_BYTE,r),s.bindFramebuffer(s.FRAMEBUFFER,null),s.deleteFramebuffer(a),r}};class ee{constructor(){Q(this,"wasmUrl"),Q(this,"webgl"),Q(this,"cacheHelper"),Q(this,"queenEngine"),Q(this,"wasmInvoker"),Q(this,"inputTextureId"),Q(this,"queenCanvas"),Q(this,"hasRenderCanvas"),Q(this,"cameraStream"),Q(this,"queenReady"),Q(this,"authState"),Q(this,"arWriteReady"),Q(this,"materialMap"),Q(this,"configUrlResources"),Q(this,"zipResources"),Q(this,"ModelConfig"),this.queenReady=!1,this.authState=!1,this.arWriteReady=!1,this.inputTextureId=0,this.hasRenderCanvas=!0,this.wasmInvoker=null,this.queenEngine=null,this.queenCanvas=null,this.wasmUrl="",this.materialMap=new Map,this.configUrlResources=new Map,this.zipResources=new Map,this.ModelConfig={SegmentModel:i.Horizontal,PoseModel:i.None,InferenceBackend:b.WebGL},this.cacheHelper=new K}checkSupportSIMD(){try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,9,1,7,0,65,0,253,15,26,11]))}catch(e){return!1}}checkSupportMutiThread(){try{return(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch(e){return!1}}getFullWasmName(e){let t=e?"-simd":"";return this.getWasmUrl()+`queen${t}.wasm`}getFullBinName(){return this.getWasmUrl()+"queen.bin"}getWasmLoaderUrl(e){return()=>import("./Empty-afb87ea8.js")}getWasmUrl(){return this.wasmUrl}setWasmUrl(e){console.info("base setWasmUrl",e),this.wasmUrl=e||`${x}wasm/advance/`}initialize(e,t,n,s,r={}){this.init(e,t,n,document.getElementById(s),r)}initializeWithUrl(e,t,n,s,r,a={}){this.setWasmUrl(e),this.init(t,n,s,r,a)}init(e,t,n,s,r={}){let a={SdkLicenseKey:e,OnInit:t,OnProgress:n,RenderCanvas:s,SegmentModel:i.Horizontal,PoseModel:i.None,InferenceBackend:b.WebGL,LogLevel:y.kLogNone};this._setModelConfig(r,a),this.create(a)}create(e){this._updateModel(e);const t=this;""===this.wasmUrl&&this.setWasmUrl(),this.initTensorflow();const n=this.checkSupportSIMD(),s=this.getWasmLoaderUrl(n),r=this.getFullWasmName(n);s().then((n=>{const s=this.getFullBinName();this.loadResourceData(s,e.OnProgress,(function(s){const a={onRuntimeInitialized:function(){t.wasmInvoker=a,t.loadQueenAssets(s)?t.queenInitialize(e.SdkLicenseKey,void 0!==e.OnFaceDetect,e.RenderCanvas).then((n=>{t.queenReady=!0,e.OnInit&&e.OnInit(n)})):(console.info("assets file load failed."),t.clearResourceCache(),e.OnInit&&e.OnInit(!1))},onTensorflowInferenceCallback:function(e,n,s,r){return t.segmentInferenceExecute(e,n,s,r)},onPoseTensorflowInferenceCallback:function(e,n,s,r){return t.poseInferenceExecute(e,n,s,r)},onFaceDataCallback:function(t){e.OnFaceDetect&&e.OnFaceDetect(t)},onAbort:function(t){e.OnError?e.OnError(t):console.error("wasm error,",t),e.OnInit&&e.OnInit(!1)},locateFile:function(e){return r}};n.default(a)}),(function(){e.OnProgress&&e.OnProgress(-1)}),0,1)}))}loadResourceData(e,t=function(){},n,s,r=0,a=1){this.cacheHelper.loadResourceData(e,t,n,s,r,a)}clearResourceCache(){this.cacheHelper.clearAssetsCache()}initializeWithBuffer(e,t,n,s,r,a={}){let o={SdkLicenseKey:e,OnInit:t,RenderCanvas:r,SegmentModel:i.None,PoseModel:i.None,InferenceBackend:b.WebGL,LogLevel:y.kLogNone};this._setModelConfig(a,o),this._updateModel(o);const u=this;""===this.wasmUrl&&this.setWasmUrl(),this.initTensorflow();const l=this.checkSupportSIMD();this.getWasmLoaderUrl(l)().then((a=>{const i={onRuntimeInitialized:function(){u.wasmInvoker=i,u.loadQueenAssets(s)?u.queenInitialize(e,!1,r).then((e=>{u.queenReady=!0,void 0!==t&&t(e)})):(console.info("assets file load failed."),u.clearResourceCache(),void 0!==t&&t(!1))},onTensorflowInferenceCallback:function(e,t,n,s){return u.segmentInferenceExecute(e,t,n,s)},onPoseTensorflowInferenceCallback:function(e,t,n,s){return u.poseInferenceExecute(e,t,n,s)},wasmBinary:n};a.default(i)}))}segmentInferenceExecute(e,t,n,s){}poseInferenceExecute(e,t,n,s){}setEngineParams(e){let[t,n]=this._splitConfig(e);this.queenEngine.setEngineParams(JSON.stringify(t)),this.setResourceParam(n)}setResourceParam(e){return J(this,null,(function*(){const t=this;this._replaceConfigUrl(e).then((e=>{t.queenEngine.setEngineParams(JSON.stringify(e))}))}))}_splitConfig(e){const t={},n={},s=["basicBeauty","advanceBeauty","faceShapeBeauty","segmentBackgroundProcess","bodyShapeBeauty"];for(const[r,a]of Object.entries(e))s.includes(r)?t[r]=a:n[r]=a;return[t,n]}_replaceConfigUrl(e){const t=this;return new Promise((function(n,s){t._processAndUploadResources(e).then((()=>{let s=t._updateConfigResource(e);n(s)}))}))}_updateConfigResource(e){const t={};for(const[n,s]of Object.entries(e)){if(s&&"object"==typeof s)if(Array.isArray(s)){let e=[];for(let t=0;t<s.length;t++){let n=this._updateConfigResource(s[t]);e.push(n)}t[n]=e}else t[n]=this._updateConfigResource(s);else t[n]=s;if(n.endsWith("Url")&&""!==s){const e=n.replace(/Url$/,"Path");if(s.indexOf(",")){let n=s.split(","),r="";for(let e=0;e<n.length;e++){let t=n[e].trim();this.configUrlResources.has(t)&&(r+=this.configUrlResources.get(t),e<n.length-1&&(r+=","))}t[e]=r}else this.configUrlResources.has(s)&&(t[e]=this.configUrlResources.get(s));delete t[n]}}return t}_isZipKey(e){return!!e.hasOwnProperty("isZip")&&e.isZip}_findConfigUrls(e,t=[],n=!1){for(const[s,r]of Object.entries(e))if("object"==typeof r)if(Array.isArray(r))for(let e of r)"object"==typeof e&&(n=this._isZipKey(e),this._findConfigUrls(e,t,n));else n=this._isZipKey(r),this._findConfigUrls(r,t,n);else if(s.endsWith("Url")&&null!==r){let e=r.split(",");for(let s of e)t.push(s.trim()),n&&this.zipResources.set(s.trim(),!0)}return t}_processAndUploadResources(e){const t=this,n=this._findConfigUrls(e).map((e=>t.configUrlResources.has(e)?Promise.resolve():t.loadResourceFileWithUrl(e,t.zipResources.has(e)).then((n=>{t.configUrlResources.set(e,n)}))));return Promise.all(n)}_updateModel(e){void 0!==e.SegmentModel&&(this.ModelConfig.SegmentModel=e.SegmentModel),void 0!==e.PoseModel&&(this.ModelConfig.PoseModel=e.PoseModel),void 0!==e.InferenceBackend&&(this.ModelConfig.InferenceBackend=e.InferenceBackend)}_setModelConfig(e,t){e.hasOwnProperty("segment")&&e.segment>=0&&e.segment<i.Max&&(t.SegmentModel=e.segment),e.hasOwnProperty("pose")&&e.pose>=0&&e.pose<i.Max&&(t.PoseModel=e.pose),e.hasOwnProperty("backend")&&e.backend>=0&&e.backend<b.Max&&(t.InferenceBackend=e.backend)}getModelConfig(){return this.ModelConfig}initTensorflow(){return J(this,arguments,(function*(e=i.None){}))}openCameraAndRender(e,t,n){const s=this;return null==e&&(e={audio:!1,video:{width:{ideal:1280},height:{ideal:720}}}),new Promise(((r,a)=>{void 0===navigator.mediaDevices?a("Your browser doesn't support the MediaDevices API"):navigator.mediaDevices.getUserMedia(e).then((e=>{s.cameraStream=e;let a=this.renderMediaStream(e,t,n);r(a)})).catch((e=>{a(e)}))}))}stopCamera(){this.cameraStream&&this.cameraStream.getTracks().forEach((e=>e.stop()))}render(e,t,n,s){if(!this.queenReady)return void this.queenAssert();const r=e.length,a=this.wasmInvoker._malloc(r);this.wasmInvoker.HEAPU8.set(e,a);const i=this.wasmInvoker._malloc(r);this.queenEngine.engineRender(a,t,n,i),this.wasmInvoker._free(a),this.renderDataCallback(i,r,t,n,s)}renderTextureId(e,t,n,s=0){if(!this.queenReady)return this.queenAssert(),null;const r=this.queenEngine.engineRenderWithTextureId(e,t,n,s);return this.wasmInvoker.GL.textures[r]}renderMediaObjectToRenderCanvas(e,t,n){if(!this.queenReady)return void this.queenAssert();if(!this.hasRenderCanvas)return void console.error("Please configure the RenderCanvas object used for rendering when initializing the SDK.");if("undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement&&(0==e.videoWidth||0==e.width))return;null!=t&&null!=n||("undefined"!=typeof VideoFrame&&e instanceof VideoFrame?(t=e.codedWidth,n=e.codedHeight):(t=e.width,n=e.height));const s=this.renderMediaObjectToTexture(e,t,n);s&&(t&&(this.queenCanvas.width=t),n&&(this.queenCanvas.height=n),this.webgl.drawTexture(s,t,n))}renderMediaObjectToTexture(e,t,n){if(!this.queenReady)return this.queenAssert(),null;if(null!=t&&null!=n||("undefined"!=typeof VideoFrame&&e instanceof VideoFrame?(t=e.codedWidth,n=e.codedHeight):(t=e.width,n=e.height)),0===t||0===n)return null;let s=this.buildInputTexture(e,t,n),r=this.queenEngine.engineRenderWithTextureId(s,t,n,0);return this.wasmInvoker.GL.textures[r]}renderWithMediaObject(e,t,n,s){if(!this.queenReady)return void this.queenAssert();let r=this.buildInputTexture(e,t,n),a=this.queenEngine.engineRenderWithTextureId(r,t,n,0),i=this.wasmInvoker.GL.textures[a];s(this.webgl.readPixels(i,t,n),t,n)}renderDataCallback(e,t,n,s,r){const a=this.wasmInvoker.HEAPU8.subarray(e,e+t);this.wasmInvoker._free(e),void 0!==r&&r(a,n,s)}renderMediaStream(e,t,n){if(0===e.getVideoTracks().length)return console.warn("Input media stream does not contain a video track."),e;const s=e.getVideoTracks()[0],r=this.renderMediaStreamTrack(s,t,n);if(r){const e=new MediaStream;return e.addTrack(r),e}return e}renderMediaStreamTrack(e,t,n){if("undefined"==typeof MediaStreamTrackProcessor||"undefined"==typeof MediaStreamTrackGenerator)return console.info("Your browser doesn't support the MediaStreamTrackProcessor API yet"),e;if(!this.queenReady)return this.queenAssert(),e;const s=new MediaStreamTrackProcessor({track:e}),r=new MediaStreamTrackGenerator({kind:"video"});return s.readable.pipeThrough(this.getTransformStream(t,n)).pipeTo(r.writable),r}getTransformStream(e,t){const n=this;return new TransformStream({transform(s,r){try{let a,i;if(a=e||n.hasRenderCanvas&&300!=n.queenCanvas.width&&n.queenCanvas.width||s.displayWidth||s.codedWidth,i=t||n.hasRenderCanvas&&150!=n.queenCanvas.height&&n.queenCanvas.height||s.displayHeight||s.codedHeight,n.queenCanvas.width=a,n.queenCanvas.height=i,null!==n.queenEngine){let e=n.renderMediaObjectToTexture(s,a,i);if(e){n.webgl.drawTexture(e,a,i);const t=s.timestamp,o=new VideoFrame(n.queenCanvas,{format:s.format,timestamp:t,codedHeight:i,codedWidth:a,displayHeight:i,displayWidth:a});r.enqueue(o),s.close()}}else r.enqueue(s)}catch(e){r.enqueue(s)}}})}queenInitialize(e,t=!1,n){const s=this;return new Promise(((r,a)=>{if(null===s.queenEngine){s.queenCanvas=n,null!==s.queenCanvas&&void 0!==s.queenCanvas||(s.hasRenderCanvas=!1,s.queenCanvas=s.createRenderCanvas()),s.webgl=new Z(s.getWebglContext()),s.initGLContext(s.queenCanvas),s.queenEngine=new s.wasmInvoker.Engine;const a=s.wasmInvoker.SdkInitCallback.implement({OnInit:e=>{-1===e&&console.error("queen license authentication failed."),s.authState=-1!==e,r(0===e)}});let i={licenseKey:e,faceData:t};s.queenEngine.engineInit(JSON.stringify(i),'{"basicBeauty":{"whitening":0.001}}',a),a.delete()}else a(!1)}))}disableGreenScreen(){this.setGreenScreenWithUrl(!1,"")}setGreenScreenWithUrl(e,t,n=1,s=!1,r=!1,a=d.kBackgroundBlur){const i=this,o=e;return new Promise(((e,u)=>{""===t?(i.queenEngine.setGreenScreen("",o,n,s,r,a),e()):i.loadResourceFileWithUrlSaveAs(t,"bg.png",!1).then((t=>{i.queenEngine.setGreenScreen(t,o,n,s,r,a),e()}),(function(){u()}))}))}enableBokehBackground(e){this.enableBackgroundByType(e,d.kBackgroundBlur)}enableTransparentBackground(e){this.enableBackgroundByType(e,d.kBackgroundTransparent)}enableBackgroundByType(e,t){e?(this.queenEngine.setSegmentBackgroundProcessType(t),this.setQueenBeautyType(a.BackgroundProcess,!0)):this.setQueenBeautyType(a.BackgroundProcess,!1)}disableSegmentBackground(){this.setSegmentBackgroundImage("")}setSegmentBackgroundUrl(e){const t=this;return new Promise((function(n,s){""===e?(t.setSegmentBackgroundImage(""),n()):t.loadResourceFileWithUrlSaveAs(e,"bg.png",!1).then((e=>{t.setSegmentBackgroundImage(e),n()}),(function(){s()}))}))}setSegmentBackgroundImage(e,t=d.kBackgroundNormal,n=!1,s=!1){this.setSegmentBackgroundProcessType(t),""===e?(this.setQueenBeautyType(a.BackgroundProcess,!1),this.queenEngine.setSegmentBackgroundImage("",n,s)):(this.setQueenBeautyType(a.BackgroundProcess,!0),this.queenEngine.setSegmentBackgroundImage(e,n,s))}setSegmentBackgroundProcessType(e){this.queenEngine.setSegmentBackgroundProcessType(e)}setAISegmentForegroundPadding(e){this.queenEngine.setAISegmentForegroundPadding(e)}setPureColorBackgroundUrl(e,t=1,n){const s=this;return new Promise((function(r,a){""===e?(s.setPureColorToBackground("",t,n),r()):s.loadResourceFileWithUrlSaveAs(e,"bg.png",!1).then((e=>{s.setPureColorToBackground(e,t,n),r()}),(function(){a()}))}))}setPureColorToBackground(e,t=1,n){this.queenEngine.setPureColorToBackground(e,n,t)}showQueenParamJson(){return this.queenEngine.getQueenBeautyParamsJsonConfig()}loadResourceFileWithUrl(e,t){const n=this;return new Promise((function(s,r){if(""===e)return void s(e);const a=n.wasmInvoker.LoadResourceCallback.implement({OnSuccess:(e,t)=>{t>0?s(e):r(e+"load fail.")},OnFailure:e=>{r(e)}});n.wasmInvoker.Resource.loadResourceFileWithUrl(e,"",t,a),a.delete()}))}loadQueenAssets(e){let t=new Uint8Array(e);const n=t.length,s=this.wasmInvoker._malloc(n);this.wasmInvoker.HEAPU8.set(t,s);var r=this.wasmInvoker.Resource.loadQueenAssets(s,n);return this.wasmInvoker._free(s),r}loadResourceFileWithUrlSaveAs(e,t,n){const s=this;return new Promise((function(r,a){fetch(e).then((e=>e.blob())).then((e=>e.arrayBuffer())).then((i=>{const o=s.wasmInvoker.LoadResourceCallback.implement({OnSuccess:(e,t)=>{t>0?r(e):a(e+"load fail.")},OnFailure:e=>{a(e)}});""===t&&(t=e.split("/").pop()+"");const u=new Uint8Array(i),l=u.length,c=s.wasmInvoker._malloc(l);s.wasmInvoker.HEAPU8.set(u,c),s.wasmInvoker.Resource.loadResourceFileWithData(c,l,t,n,o),o.delete(),s.wasmInvoker._free(c)}))}))}loadResourceFileWithData(e,t,n){const s=this;return new Promise((function(r,a){const i=s.wasmInvoker.LoadResourceCallback.implement({OnSuccess:(e,t)=>{t>0?r(e):a(e+"load fail.")},OnFailure:e=>{a(e)}});let o=new Uint8Array(e);const u=o.length,l=s.wasmInvoker._malloc(u);s.wasmInvoker.HEAPU8.set(o,l),s.wasmInvoker.Resource.loadResourceFileWithData(l,u,t,n,i),i.delete(),s.wasmInvoker._free(l)}))}checkResourceFile(e){return this.wasmInvoker.Resource.checkResourceFile(e)}setQueenBeautyType(e,t){this.queenEngine.setQueenBeautyType(e,t)}setQueenBeautyParams(e,t){this.queenEngine.setQueenBeautyParams(e,t)}getQueenBeautyParams(e){return this.queenEngine.getQueenBeautyParams(e)}setInputFlip(e){this.queenEngine.setInputFlip(e)}disableLut(){this.queenEngine.setLutImagePath("")}setLutByType(e,t=.5){const n=j.getLutUrl(e);return this.setQueenBeautyType(a.LUT,!0),this.setQueenBeautyParams(o.LUT,t),this.setLutImageUrl(n)}setLutImageUrl(e){const t=this;return new Promise((function(n,s){""===e?(t.queenEngine.setLutImagePath(""),n()):t.loadResourceFileWithUrl(e,!1).then((e=>{t.queenEngine.setLutImagePath(e),n()}),(function(){s()}))}))}setLutImagePath(e){this.queenEngine.setLutImagePath(e)}setFaceShape(e,t){this.queenEngine.setFaceShape(e,t)}setMakeupEyeBrow(e,t,n=h.LabMix){const[s,r]=j.getMakeupEyeBrowRes(e);return this.setMakeupAlphaWithType(l.EyeBrow,!0,t),this.setMakeupWithPackage(l.EyeBrow,r,s,n)}setMackupEyeLash(e,t,n=h.LabMix){const s=j.getMakeupEyeLashUrl(e);return this.setMakeupAlphaWithType(l.Eyelash,!0,t),this.setMakeupWithUrl(l.Eyelash,s,n)}setMakeupEyeShadow(e,t,n=h.LabMix){const[s,r]=j.getMakeupEyeShadowRes(e);return this.setMakeupAlphaWithType(l.EyeShadow,!0,t),this.setMakeupWithPackage(l.EyeShadow,r,s,n)}setMakeupEyeLiner(e,t,n=h.LabMix){const s=j.getMakeupEyeLinerUrl(e);return this.setMakeupAlphaWithType(l.Eyeliner,!0,t),this.setMakeupWithUrl(l.Eyeliner,s,n)}setMakeupEyeBall(e,t,n=h.LabMix){const s=j.getMakeupEyeBallUrl(e);return this.setMakeupAlphaWithType(l.Eyeball,!0,t),this.setMakeupWithUrl(l.Eyeball,s,n)}setMakeupMouth(e,t,n=h.LabMix){const[s,r]=j.getMakeupMouthRes(e);return this.setMakeupAlphaWithType(l.Mouth,!0,t),this.setMakeupWithPackage(l.Mouth,r,s,n)}setMakeupWhole(e,t,n=h.LabMix){const s=j.getMakeupWholeUrl(e);return this.setMakeupAlphaWithType(l.Whole,!0,t),this.setMakeupWithUrl(l.Whole,s,n)}setMakeupBlush(e,t,n=h.LabMix){const s=j.getMakeupBlushUrl(e);return this.setMakeupAlphaWithType(l.Blush,!0,t),this.setMakeupWithUrl(l.Blush,s,n)}setMakeupHighlight(e,t,n=h.LabMix){const s=j.getMakeupHighLightUrl(e);return this.setMakeupAlphaWithType(l.Highlight,!0,t),this.setMakeupWithUrl(l.Highlight,s,n)}setMakeupWithUrl(e,t,n){const s=this;return new Promise((function(r,a){s.loadResourceFileWithUrl(t,!1).then((t=>{s.setMakeupWithType(e,t,n,20),r()}),(function(){a()}))}))}setMakeupWithPackage(e,t,n,s){const r=this;return new Promise((function(a,i){r.loadResourceFileWithUrl(t,!0).then((t=>{r.setMakeupWithType(e,t+n,s,20),a()}),(function(){i()}))}))}setMakeupWithType(e,t,n,s=20){this.queenEngine.setMakeupWithTypeFps(e,t,n,s)}setMakeupFemaleAlpha(e,t){this.setMakeupAlphaWithType(e,!0,t)}setMakeupMaleAlpha(e,t){this.setMakeupAlphaWithType(e,!1,t)}setMakeupAlphaWithType(e,t,n){this.queenEngine.setMakeupAlphaWithType(e,t,n)}setMakeupBlendWithType(e,t){this.queenEngine.setMakeupBlendWithType(e,t)}removeMakeupWithType(e){this.setMakeupWithType(e,"",0)}resetAllMakeupType(){this.queenEngine.resetAllMakeupType()}addMaterialWithType(e){const t=j.getStickerUrl(e);return this.addMaterialWithUrl(t)}addMaterialWithIndex(e){const t=j.getStickerUrlByIndex(e);return this.addMaterialWithUrl(t)}addMaterialWithIndexs(e){const t=e.map((e=>J(this,null,(function*(){const t=j.getStickerUrlByIndex(e);yield this.addMaterialWithUrl(t)}))));return Promise.all(t)}addMaterialWithUrl(e,t=0){const n=this;return new Promise((function(s,r){n.loadResourceFileWithUrl(e,!0).then((r=>{n.materialMap.set(e,r),n.queenEngine.addMaterialWithPath(r,t),s()}),(function(){r()}))}))}addMaterialWithPath(e,t=0){this.queenEngine.addMaterialWithPath(e,t)}removeMaterialWithType(e){const t=j.getStickerUrl(e);this.removeMaterialWithUrl(t)}removeMaterialWithIndex(e){const t=j.getStickerUrlByIndex(e);this.removeMaterialWithUrl(t)}removeMaterialWithUrl(e){if(this.materialMap.has(e)){const t=this.materialMap.get(e);this.removeMaterialWithPath(t)}}removeMaterialWithPath(e){this.queenEngine.removeMaterialWithPath(e)}showFaceDetectPoint(e){this.queenEngine.setQueenBeautyType(a.Makeup,!0),this.setMakeupHighlight(V.Highlight,.01),this.queenEngine.showFaceDetectPoint(e)}showMakeupLine(e){this.queenEngine.setQueenBeautyType(a.Makeup,!0),this.setMakeupHighlight(V.Highlight,.01),this.queenEngine.showMakeupLine(e)}showBodyDetectPoint(e){this.queenEngine.showBodyDetectPoint(e)}engineDestory(){this.queenReady=!1,this.authState=!1,setTimeout((()=>{this.queenEngine.engineDestory()}),100)}initArWriteResource(){const e=this,t=this.getWasmUrl()+"models/handmodels.bin";return new Promise((function(n,s){e.arWriteReady?n(!0):e.loadResourceData(t,(e=>{}),(function(t){e.loadQueenAssets(t)?(n(!0),e.arWriteReady=!0):n(!1)}),(()=>{}),0,1)}))}setArWriting(e,t){this.queenEngine.setArWriting(e,t)}cleanScreenArWriting(){this.queenEngine.cleanScreenArWriting()}setPowerSaving(e){this.queenEngine.setPowerSaving(e)}setBodyShape(e,t){this.queenEngine.setBodyShape(e,t)}animojiInitialize(e,t,n,s){const r=this;return new Promise((function(a,i){r.loadResourceFileWithUrl(e,!0).then((e=>{r.queenEngine.animojiInit(e,t,n,s),a()}),(function(){i()}))}))}setAnimojiBackgroundWithMode(e,t){const n=this;return new Promise((function(s,r){""===t?(n.queenEngine.setAnimojiBackgroundMode(e,""),s()):n.loadResourceFileWithUrl(t,!1).then((t=>{n.queenEngine.setAnimojiBackgroundMode(e,t),s()}),(function(){r()}))}))}animojiRenderMediaObjectToRenderCanvas(e,t,n){if(!this.queenReady)return void this.queenAssert();if(!this.hasRenderCanvas)return void console.error("Please configure the RenderCanvas object used for rendering when initializing the SDK.");if("undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement&&(0==e.videoWidth||0==e.width))return;const s=this.animojiRenderMediaObjectToTexture(e,t,n);s&&(t&&(this.queenCanvas.width=t),n&&(this.queenCanvas.height=n),this.webgl.drawTexture(s,t,n))}animojiRender(e,t,n,s){if(!this.queenReady)return void this.queenAssert();const r=e.length,a=this.wasmInvoker._malloc(r);this.wasmInvoker.HEAPU8.set(e,a);const i=this.wasmInvoker._malloc(r);this.queenEngine.animojiRender(a,t,n,i),this.renderDataCallback(i,r,t,n,s),this.wasmInvoker._free(a)}animojiRenderWithMediaObject(e,t,n,s){if(!this.queenReady)return void this.queenAssert();let r=this.buildInputTexture(e,t,n),a=this.queenEngine.animojiRenderWithTextureId(r,t,n),i=this.wasmInvoker.GL.textures[a];s(this.webgl.readPixels(i,t,n),t,n)}animojiRenderMediaObjectToTexture(e,t,n){if(!this.queenReady)return this.queenAssert(),null;null!=t&&null!=n||("undefined"!=typeof VideoFrame&&e instanceof VideoFrame?(t=e.codedWidth,n=e.codedHeight):(t=e.width,n=e.height));let s=this.buildInputTexture(e,t,n),r=this.queenEngine.animojiRenderWithTextureId(s,t,n);return this.wasmInvoker.GL.textures[r]}animojiRenderTextureId(e,t,n){if(!this.queenReady)return this.queenAssert(),null;let s=this.queenEngine.animojiRenderWithTextureId(e,t,n);return this.wasmInvoker.GL.textures[s]}animojiResize(e){this.queenEngine.animojiResize(e)}animojiDestroy(){this.queenEngine.animojiDestroy()}getEngine(){return this.queenEngine}getWebglUtil(){return this.webgl}createRenderCanvas(){let e=document.createElement("canvas");return e.id="queen_wasm_canvas_effect_render_1",e.style.display="none",document.body.appendChild(e),e}getWebglContext(){return this.queenCanvas.getContext("webgl2")?this.queenCanvas.getContext("webgl2"):this.queenCanvas.getContext("webgl")}initGLContext(e){const t=this.wasmInvoker.GL.createContext(e,{explicitSwapControl:0,majorVersion:2,minorVersion:0,alpha:0,antialias:0,premultipliedAlpha:0,preserveDrawingBuffer:0,depth:0,stencil:0,powerPreference:"high-performance",failIfMajorPerformanceCaveat:1});this.wasmInvoker.canvas=e,this.wasmInvoker.GL.makeContextCurrent(t);let n=this.getWebglContext();n.disable(n.DEPTH_TEST),n.disable(n.STENCIL_TEST),n.disable(n.BLEND),n.disable(n.DITHER),n.disable(n.POLYGON_OFFSET_FILL),n.disable(n.SAMPLE_COVERAGE),n.disable(n.SCISSOR_TEST)}resetGLContext(){const e=this.getWebglContext();this.wasmInvoker.GL.deleteContext(e),this.initGLContext(this.queenCanvas)}_getInputTexture(e=1,t=1){if(0===this.inputTextureId){const n=this.webgl.createBlankTexture(e,t);this.inputTextureId=this.buildTextureId(n)}return[this.inputTextureId,this.wasmInvoker.GL.textures[this.inputTextureId]]}buildInputTexture(e,t=1,n=1){let[s,r]=this._getInputTexture(t,n);return e instanceof Uint8Array?this.webgl.updateTextureData(r,e,t,n):this.webgl.updateTexture(r,e),s}generateTexture(e,t,n){let s;return s=e instanceof Uint8Array?this.webgl.createBufferTexture(e,t,n):this.webgl.createMediaTexture(e),this.buildTextureId(s)}generateBlankTexture(e=1,t=1){let n=this.webgl.createBlankTexture(e,t);return this.buildTextureId(n)}buildTextureId(e){const t=this.wasmInvoker.GL.getNewId(this.wasmInvoker.GL.textures);return this.wasmInvoker.GL.textures[t]=e,t}getGLTextureById(e){return this.wasmInvoker.GL.textures[e]}drawOutTexture(e,t,n){this.webgl.drawTexture(e,t,n)}queenAssert(){this.queenReady||console.error("Queen Engine initialization failed."),this.authState||console.error("queen license authentication failed.")}assertMessage(e,t){e||console.error(t)}}var te=Object.defineProperty,ne=(e,t,n)=>(((e,t,n)=>{t in e?te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class se extends ee{constructor(){super()}setWasmUrl(e){let t=e||`${x}wasm/advance/`;super.setWasmUrl(t)}getWasmLoaderUrl(e){return e?()=>import("./queen-simd-120164b8.js"):()=>import("./queen-bb600e27.js")}initTensorflow(){return e=this,t=arguments,n=function*(e=i.None){},new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));var e,t,n}segmentInferenceExecute(e,t,n,s){}poseInferenceExecute(e,t,n,s){}}ne(se,"Assets",X),ne(se,"kQueenBeautyType",a),ne(se,"kQueenBeautyParams",o),ne(se,"kBackgroundProcessType",d),ne(se,"kQueenBeautyMakeupType",l),ne(se,"kQueenBeautyFaceShapeType",c),ne(se,"kQueenBeautyBlend",h),ne(se,"kSegmentPerformanceMode",p),ne(se,"kQueenBeautyBodyShapeType",u),ne(se,"kQueenModelShapeType",i);var re=Object.defineProperty,ae=(e,t,n)=>(((e,t,n)=>{t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class ie extends ee{constructor(){super()}setWasmUrl(e){let t=e||`${x}wasm/lite/`;super.setWasmUrl(t)}getWasmLoaderUrl(e){return e?()=>import("./queen-simd-lite-abe5b2f5.js"):()=>import("./queen-lite-c4ef0218.js")}initTensorflow(){return e=this,t=arguments,n=function*(e=i.None){},new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));var e,t,n}segmentInferenceExecute(e,t,n,s){}poseInferenceExecute(e,t,n,s){}}ae(ie,"kQueenBeautyType",a),ae(ie,"kQueenBeautyParams",o);class oe{constructor(e,t){this.backend=e,this.dataMover=t,this.data=new WeakMap,this.dataIdsCount=0}get(e){return this.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)}set(e,t){this.dataIdsCount++,this.data.set(e,t)}has(e){return this.data.has(e)}delete(e){return this.dataIdsCount--,this.data.delete(e)}numDataIds(){return this.dataIdsCount}}class ue{refCount(e){return le("refCount")}incRef(e){return le("incRef")}timerAvailable(){return!0}time(e){return le("time")}read(e){return le("read")}readSync(e){return le("readSync")}readToGPU(e,t){return le("readToGPU")}numDataIds(){return le("numDataIds")}disposeData(e,t){return le("disposeData")}write(e,t,n){return le("write")}move(e,t,n,s,r){return le("move")}createTensorFromGPUData(e,t,n){return le("createTensorFromGPUData")}memory(){return le("memory")}floatPrecision(){return le("floatPrecision")}epsilon(){return 32===this.floatPrecision()?1e-7:1e-4}dispose(){return le("dispose")}}function le(e){throw new Error(`'${e}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`)}
|
|
1
|
+
import e from"@/core/plugin";function t(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}var n,s=Object.defineProperty,r=(e,t,n)=>(((e,t,n)=>{t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),a=((n=a||{})[n.SkinBuffing=0]="SkinBuffing",n[n.FaceBuffing=1]="FaceBuffing",n[n.Makeup=2]="Makeup",n[n.FaceShape=3]="FaceShape",n[n.SkinWhiting=4]="SkinWhiting",n[n.LUT=5]="LUT",n[n.BackgroundProcess=6]="BackgroundProcess",n[n.AutoFilter=7]="AutoFilter",n[n.BodyShape=8]="BodyShape",n[n.HandGestureDetect=9]="HandGestureDetect",n[n.Max=10]="Max",n),i=(e=>(e[e.None=0]="None",e[e.Horizontal=1]="Horizontal",e[e.Vertical=2]="Vertical",e[e.Both=3]="Both",e[e.Max=4]="Max",e))(i||{}),o=(e=>(e[e.SkinBuffing=1]="SkinBuffing",e[e.Sharpen=2]="Sharpen",e[e.Whitening=3]="Whitening",e[e.Pouch=4]="Pouch",e[e.NasolabialFolds=5]="NasolabialFolds",e[e.LUT=6]="LUT",e[e.WhiteTeeth=7]="WhiteTeeth",e[e.Lipstick=8]="Lipstick",e[e.Blush=9]="Blush",e[e.LipstickColorParam=10]="LipstickColorParam",e[e.LipstickGlossParam=11]="LipstickGlossParam",e[e.LipstickBrightnessParam=12]="LipstickBrightnessParam",e[e.BrightenEye=13]="BrightenEye",e[e.SkinRed=14]="SkinRed",e[e.Wrinkles=15]="Wrinkles",e[e.BrightenFace=16]="BrightenFace",e[e.AutoLRate=17]="AutoLRate",e[e.AutoARate=18]="AutoARate",e[e.AutoBRate=19]="AutoBRate",e))(o||{}),u=(e=>(e[e.FullBody=0]="FullBody",e[e.LongLag=1]="LongLag",e[e.SmallHead=2]="SmallHead",e[e.ThinLag=3]="ThinLag",e[e.LongNeck=4]="LongNeck",e[e.ThinWaist=5]="ThinWaist",e[e.EnhanceBreast=6]="EnhanceBreast",e[e.ThinArm=7]="ThinArm",e[e.MAX=8]="MAX",e))(u||{}),l=(e=>(e[e.Whole=0]="Whole",e[e.Highlight=1]="Highlight",e[e.Eyeball=2]="Eyeball",e[e.Mouth=3]="Mouth",e[e.Wocan=4]="Wocan",e[e.EyeBrow=5]="EyeBrow",e[e.Blush=6]="Blush",e[e.EyeShadow=7]="EyeShadow",e[e.Eyeliner=8]="Eyeliner",e[e.Eyelash=9]="Eyelash",e[e.MakeupMax=10]="MakeupMax",e))(l||{}),c=(e=>(e[e.CutCheek=0]="CutCheek",e[e.CutFace=1]="CutFace",e[e.ThinFace=2]="ThinFace",e[e.LongFace=3]="LongFace",e[e.LowerJaw=4]="LowerJaw",e[e.HigherJaw=5]="HigherJaw",e[e.ThinJaw=6]="ThinJaw",e[e.ThinMandible=7]="ThinMandible",e[e.BigEye=8]="BigEye",e[e.EyeAngle1=9]="EyeAngle1",e[e.Canthus=10]="Canthus",e[e.Canthus1=11]="Canthus1",e[e.EyeAngle2=12]="EyeAngle2",e[e.EyeTDAngle=13]="EyeTDAngle",e[e.ThinNose=14]="ThinNose",e[e.Nosewing=15]="Nosewing",e[e.NasalHeight=16]="NasalHeight",e[e.NoseTipHeight=17]="NoseTipHeight",e[e.MouthWidth=18]="MouthWidth",e[e.MouthSize=19]="MouthSize",e[e.MouthHigh=20]="MouthHigh",e[e.Philtrum=21]="Philtrum",e[e.HairLine=22]="HairLine",e[e.Smile=23]="Smile",e[e.MAX=24]="MAX",e))(c||{}),h=(e=>(e[e.Normal=0]="Normal",e[e.Lighten=1]="Lighten",e[e.Darken=2]="Darken",e[e.Multiply=3]="Multiply",e[e.Divide=4]="Divide",e[e.Average=5]="Average",e[e.Add=6]="Add",e[e.Subtract=7]="Subtract",e[e.Difference=8]="Difference",e[e.Negation=9]="Negation",e[e.Exclusion=10]="Exclusion",e[e.Screen=11]="Screen",e[e.Overlay=12]="Overlay",e[e.SoftLight=13]="SoftLight",e[e.HardLight=14]="HardLight",e[e.ColorDodge=15]="ColorDodge",e[e.ColorBurn=16]="ColorBurn",e[e.LinearDodge=17]="LinearDodge",e[e.LinearBurn=18]="LinearBurn",e[e.LinearLight=19]="LinearLight",e[e.VividLight=20]="VividLight",e[e.PinLight=21]="PinLight",e[e.HardMix=22]="HardMix",e[e.Reflect=23]="Reflect",e[e.Glow=24]="Glow",e[e.Phoenix=25]="Phoenix",e[e.Hue=26]="Hue",e[e.Saturation=27]="Saturation",e[e.Luminosity=28]="Luminosity",e[e.Color=29]="Color",e[e.Curve=30]="Curve",e[e.LabMix=31]="LabMix",e[e.Max=32]="Max",e))(h||{}),d=(e=>(e[e.kBackgroundBlur=0]="kBackgroundBlur",e[e.kBackgroundTransparent=1]="kBackgroundTransparent",e[e.kBackgroundNormal=2]="kBackgroundNormal",e))(d||{}),p=(e=>(e[e.Auto=0]="Auto",e[e.Quality=1]="Quality",e[e.Balanced=2]="Balanced",e[e.Performance=3]="Performance",e))(p||{}),f=(e=>(e[e.Lite=0]="Lite",e[e.Advance=1]="Advance",e[e.Pro=2]="Pro",e[e.Full=3]="Full",e))(f||{}),m=(e=>(e[e.Initialize=100]="Initialize",e[e.Render=101]="Render",e[e.RenderMediaObjectToTexture=102]="RenderMediaObjectToTexture",e[e.RenderTextureId=103]="RenderTextureId",e[e.RenderWithTextureId=104]="RenderWithTextureId",e[e.RenderWithMediaObject=105]="RenderWithMediaObject",e[e.MediaStreamRender=106]="MediaStreamRender",e[e.EngineDestory=107]="EngineDestory",e[e.RenderWorkerTest=110]="RenderWorkerTest",e[e.SetQueenBeautyType=200]="SetQueenBeautyType",e[e.SetQueenBeautyParams=201]="SetQueenBeautyParams",e[e.SetLutImageUrl=203]="SetLutImageUrl",e[e.SetFaceShape=204]="SetFaceShape",e[e.SetMakeupWithUrl=205]="SetMakeupWithUrl",e[e.SetMakeupWithPackage=206]="SetMakeupWithPackage",e[e.SetMakeupAlphaWithType=207]="SetMakeupAlphaWithType",e[e.SetMakeupBlendWithType=208]="SetMakeupBlendWithType",e[e.ResetAllMakeupType=209]="ResetAllMakeupType",e[e.AddMaterialWithUrl=210]="AddMaterialWithUrl",e[e.RemoveMaterialWithUrl=211]="RemoveMaterialWithUrl",e[e.SetPowerSaving=212]="SetPowerSaving",e[e.SetMakeupWithTypeFps=213]="SetMakeupWithTypeFps",e[e.SetBodyShape=214]="SetBodyShape",e[e.SetEngineParams=215]="SetEngineParams",e[e.SetGreenScreenWithUrl=300]="SetGreenScreenWithUrl",e[e.EnableBokehBackground=301]="EnableBokehBackground",e[e.SetSegmentBackgroundUrl=302]="SetSegmentBackgroundUrl",e[e.SetSegmentBackgroundProcessType=303]="SetSegmentBackgroundProcessType",e[e.SetAISegmentForegroundPadding=304]="SetAISegmentForegroundPadding",e[e.SetPureColorBackgroundUrl=305]="SetPureColorBackgroundUrl",e[e.LoadResourceFileWithUrl=401]="LoadResourceFileWithUrl",e[e.LoadResourceFileWithUrlSaveAs=402]="LoadResourceFileWithUrlSaveAs",e[e.LoadResourceFileWithData=403]="LoadResourceFileWithData",e[e.CheckResourceFile=404]="CheckResourceFile",e[e.LoadQueenAssets=405]="LoadQueenAssets",e[e.ShowFaceDetectPoint=500]="ShowFaceDetectPoint",e[e.ShowMakeupLine=501]="ShowMakeupLine",e[e.ShowBodyDetectPoint=502]="ShowBodyDetectPoint",e[e.GetQueenBeautyParams=503]="GetQueenBeautyParams",e[e.ShowQueenParam=504]="ShowQueenParam",e[e.ShowQueenParamJson=505]="ShowQueenParamJson",e[e.SetArWriting=600]="SetArWriting",e[e.CleanScreenArWriting=601]="CleanScreenArWriting",e[e.AnimojiInitialize=700]="AnimojiInitialize",e[e.SetAnimojiBackgroundWithMode=701]="SetAnimojiBackgroundWithMode",e[e.AnimojiRender=702]="AnimojiRender",e[e.AnimojiRenderWithMediaObject=703]="AnimojiRenderWithMediaObject",e[e.AnimojiRenderMediaObjectToTexture=704]="AnimojiRenderMediaObjectToTexture",e[e.AnimojiRenderTextureId=705]="AnimojiRenderTextureId",e[e.AnimojiResize=706]="AnimojiResize",e[e.AnimojiDestroy=707]="AnimojiDestroy",e))(m||{}),g=(e=>(e[e.Initialize=1e3]="Initialize",e[e.LoaddingProgress=1001]="LoaddingProgress",e[e.Render=1002]="Render",e[e.RenderWithTextureId=1003]="RenderWithTextureId",e[e.RenderTextureId=1004]="RenderTextureId",e[e.RenderImageData=1005]="RenderImageData",e[e.RenderImageBuffer=1006]="RenderImageBuffer",e[e.LoadUrlComplate=4001]="LoadUrlComplate",e[e.GetQueenBeautyParams=5e3]="GetQueenBeautyParams",e[e.GetQueenBeautyParamsConfig=5001]="GetQueenBeautyParamsConfig",e[e.ShowQueenParam=5002]="ShowQueenParam",e[e.Complate=6e3]="Complate",e[e.Fail=6001]="Fail",e[e.State=6002]="State",e[e.RenderComplate=6003]="RenderComplate",e[e.RenderTimestamp=9e3]="RenderTimestamp",e))(g||{}),y=(e=>(e[e.kLogNone=0]="kLogNone",e[e.kLogError=1]="kLogError",e[e.kLogWarning=2]="kLogWarning",e[e.kLogInfo=3]="kLogInfo",e[e.kLogDebug=4]="kLogDebug",e))(y||{}),b=(e=>(e[e.Auto=0]="Auto",e[e.WebGL=1]="WebGL",e[e.WebGPU=2]="WebGPU",e[e.Max=3]="Max",e))(b||{});const x="https://g.alicdn.com/apsara-media-box/imp-web-queen-wasm/6.3.3/dist/",w=x+"queen_res/",k="sticker/",v=["bimuyu.2.1.png","lingjing.2.1.png","liwu.2.1.png","meidusha.2.1.png","milanda.2.1.png","ningmengcao.2.1.png","senlin.2.1.png","siyecao.2.1.png","wanhuatong.2.1.png"],I=["1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png"],S=["anyezi.1.2.3.bin","chidousha.1.2.3.bin","fuguse.1.2.3.bin","guimeihong.1.2.3.bin","jiangguose.1.2.3.bin","nanguase.1.2.3.bin","shiliuhong.1.2.3.bin","shipshape.1.2.3.bin","standout.1.2.3.bin"],C=["biaozhunmei.2.3.png","cupingmei.2.3.png","juanyanmei.2.3.png","liuxingmei.2.3.png","liuyemei.2.3.png","qiubomei.2.3.png","wanyuemei.2.3.png","xinyuemei.2.3.png","yeshengmei.2.3.png"],N=["biaozhunmei.2.3.bin","cupingmei.2.3.bin","juanyanmei.2.3.bin","liuxingmei.2.3.bin","liuyemei.2.3.bin","qiubomei.2.3.bin","wanyuemei.2.3.bin","xinyuemei.2.3.bin","yeshengmei.2.3.bin"],T=["1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png","1.2.3.png"],$=["dadise.1.2.3.bin","fangtangfen.1.2.3.bin","fuguse.1.2.3.bin","huoliju.1.2.3.bin","jinzongse.1.2.3.bin","pengkezong.1.2.3.bin","xingguangfen.1.2.3.bin","yanfense.1.2.3.bin","yeqiangwei.1.2.3.bin"],R=["dayan.2.3.png","guima.2.3.png","juanqiao.2.3.png","keai.2.3.png","lingdong.2.3.png","qizhi.2.3.png","wenrou.2.3.png","wugu.2.3.png","xiaoyemao.2.3.png"],E=["chenjing.2.3.png","huopo.2.3.png","jichu.2.3.png","keai.2.3.png","lingdong.2.3.png","shaonv.2.3.png","wugu.2.3.png","yesheng.2.3.png","zhixing.2.3.png"],A=["blush_wugu.2.3.png","chayi.2.3.png","chulian.2.3.png","chunqing.2.3.png","qiji.2.3.png","shaonv.2.3.png"],_=["huoli.2.31.png","jichu.2.31.png","meihuo.2.31.png","meizi.2.31.png","mitao.2.31.png","naiju.2.31.png","xingfen.2.31.png","youya.2.31.png","yuanqishaonv.2.31.png"],F=["highlight.2.12.png"],D=["M1.png","M2.png","M3.png","M4.png","M5.png","M6.png","M7.png","M8.png","PF1.png","PF2.png","PF3.png","PF4.png","PF5.png","PF6.png","PF7.png","PF8.png","PF9.png","PFA.png","PFB.png","PFC.png","PI4.png","PL1.png","PI1.png","PI2.png","PI3.png","PL2.png","PL3.png","PL4.png","PJ1.png","PJ2.png","PJ3.png","PJ4.png","delta.png","electric.png","faded.png","slowlived.png","urbex.png","warm.png","F4.png","F5.png","tokoyo.png","F1.png","F2.png","F3.png","F6.png","F7.png","PV1.png","PV2.png","PV3.png","PV4.png","PV5.png","PV6.png","A1.png","A2.png","A3.png","A4.png","A5.png","A6.png"];var M=(e=>(e[e.BiMuYu=0]="BiMuYu",e[e.LingJing=1]="LingJing",e[e.LiWu=2]="LiWu",e[e.MeiDuSha=3]="MeiDuSha",e[e.MiLanDa=4]="MiLanDa",e[e.NingMengCao=5]="NingMengCao",e[e.SenLin=6]="SenLin",e[e.SiYeCao=7]="SiYeCao",e[e.WanHuaTong=8]="WanHuaTong",e))(M||{}),O=(e=>(e[e.AnYeZi=0]="AnYeZi",e[e.ChiDouSha=1]="ChiDouSha",e[e.FuGuSe=2]="FuGuSe",e[e.GuiMeiHong=3]="GuiMeiHong",e[e.JiangGuoSe=4]="JiangGuoSe",e[e.NanGuaSe=5]="NanGuaSe",e[e.ShiLiuHong=6]="ShiLiuHong",e[e.ShipShape=7]="ShipShape",e[e.StandOut=8]="StandOut",e))(O||{}),L=(e=>(e[e.BiaoZhunMei=0]="BiaoZhunMei",e[e.CuPingMei=1]="CuPingMei",e[e.JuanYanMei=2]="JuanYanMei",e[e.LiuXingMei=3]="LiuXingMei",e[e.LiuYeMei=4]="LiuYeMei",e[e.QiuBoMei=5]="QiuBoMei",e[e.WanYueMei=6]="WanYueMei",e[e.XinYueMei=7]="XinYueMei",e[e.YeShengMei=8]="YeShengMei",e))(L||{}),P=(e=>(e[e.DaDiSe=0]="DaDiSe",e[e.FangTangFen=1]="FangTangFen",e[e.FuGuSe=2]="FuGuSe",e[e.HuoLiJu=3]="HuoLiJu",e[e.JinZongSe=4]="JinZongSe",e[e.PengKeZong=5]="PengKeZong",e[e.XingGuangFen=6]="XingGuangFen",e[e.YanFenSe=7]="YanFenSe",e[e.YeQiangWei=8]="YeQiangWei",e))(P||{}),z=(e=>(e[e.DaYan=0]="DaYan",e[e.GuiMa=1]="GuiMa",e[e.JuanQiao=2]="JuanQiao",e[e.KeAi=3]="KeAi",e[e.LingDong=4]="LingDong",e[e.QiZhi=5]="QiZhi",e[e.WenRou=6]="WenRou",e[e.WuGu=7]="WuGu",e[e.XiaoYeMao=8]="XiaoYeMao",e))(z||{}),B=(e=>(e[e.ChenJing=0]="ChenJing",e[e.HuoPo=1]="HuoPo",e[e.JiChu=2]="JiChu",e[e.KeAi=3]="KeAi",e[e.LingDong=4]="LingDong",e[e.ShaoNv=5]="ShaoNv",e[e.WuGu=6]="WuGu",e[e.YeSheng=7]="YeSheng",e[e.ZhiXing=8]="ZhiXing",e))(B||{}),W=(e=>(e[e.BlushWuGu=0]="BlushWuGu",e[e.ChaYi=1]="ChaYi",e[e.ChuLian=2]="ChuLian",e[e.ChunQing=3]="ChunQing",e[e.QiJi=4]="QiJi",e[e.ShaoNv=5]="ShaoNv",e))(W||{}),U=(e=>(e[e.HuoLi=0]="HuoLi",e[e.JiChu=1]="JiChu",e[e.MeiHuo=2]="MeiHuo",e[e.MeiZi=3]="MeiZi",e[e.MiTao=4]="MiTao",e[e.NaiJu=5]="NaiJu",e[e.XingFen=6]="XingFen",e[e.YouYa=7]="YouYa",e[e.YuanQiShaoNv=8]="YuanQiShaoNv",e))(U||{}),V=(e=>(e[e.Highlight=0]="Highlight",e))(V||{}),G=(e=>(e[e.BrownBear=0]="BrownBear",e[e.Ding3Duo=1]="Ding3Duo",e[e.Pumpkin=2]="Pumpkin",e[e.Rabbit=3]="Rabbit",e[e.RedPanda=4]="RedPanda",e[e.SanXingDui=5]="SanXingDui",e[e.TaoGongZai=6]="TaoGongZai",e))(G||{}),H=(e=>(e[e.M1=0]="M1",e[e.M2=1]="M2",e[e.M3=2]="M3",e[e.M4=3]="M4",e[e.M5=4]="M5",e[e.M6=5]="M6",e[e.M7=6]="M7",e[e.M8=7]="M8",e[e.PF1=8]="PF1",e[e.PF2=9]="PF2",e[e.PF3=10]="PF3",e[e.PF4=11]="PF4",e[e.PF5=12]="PF5",e[e.PF6=13]="PF6",e[e.PF7=14]="PF7",e[e.PF8=15]="PF8",e[e.PF9=16]="PF9",e[e.PFA=17]="PFA",e[e.PFB=18]="PFB",e[e.PFC=19]="PFC",e[e.PI4=20]="PI4",e[e.PL1=21]="PL1",e[e.PI1=22]="PI1",e[e.PI2=23]="PI2",e[e.PI3=24]="PI3",e[e.PL2=25]="PL2",e[e.PL3=26]="PL3",e[e.PL4=27]="PL4",e[e.PJ1=28]="PJ1",e[e.PJ2=29]="PJ2",e[e.PJ3=30]="PJ3",e[e.PJ4=31]="PJ4",e[e.Delta=32]="Delta",e[e.Electric=33]="Electric",e[e.Faded=34]="Faded",e[e.Slowlived=35]="Slowlived",e[e.Urbex=36]="Urbex",e[e.Warm=37]="Warm",e[e.F4=38]="F4",e[e.F5=39]="F5",e[e.Tokoyo=40]="Tokoyo",e[e.F1=41]="F1",e[e.F2=42]="F2",e[e.F3=43]="F3",e[e.F6=44]="F6",e[e.F7=45]="F7",e[e.PV1=46]="PV1",e[e.PV2=47]="PV2",e[e.PV3=48]="PV3",e[e.PV4=49]="PV4",e[e.PV5=50]="PV5",e[e.PV6=51]="PV6",e[e.A1=52]="A1",e[e.A2=53]="A2",e[e.A3=54]="A3",e[e.A4=55]="A4",e[e.A5=56]="A5",e[e.A6=57]="A6",e))(H||{}),q=(e=>(e[e.ILoveChina=0]="ILoveChina",e[e.HongXing=1]="HongXing",e[e.HuDieJie=2]="HuDieJie",e[e.MiLaoShu=3]="MiLaoShu",e[e.LuJiao=4]="LuJiao",e[e.KuaiLeXingQiu=5]="KuaiLeXingQiu",e[e.KeAi=6]="KeAi",e[e.DaiMoJing1=0]="DaiMoJing1",e[e.MaoZi=0]="MaoZi",e[e.DaiMoJing2=0]="DaiMoJing2",e[e.XiaoKeAi=0]="XiaoKeAi",e[e.XiaRiXiGua=0]="XiaRiXiGua",e[e.XiaoMaoMi=0]="XiaoMaoMi",e[e.NvWang=0]="NvWang",e[e.DanGao=0]="DanGao",e[e.MiaoSha=0]="MiaoSha",e[e.NianHuoJie=0]="NianHuoJie",e[e.MianDanFanJu=0]="MianDanFanJu",e[e.ZhouNianQing=0]="ZhouNianQing",e[e.ShiShen=0]="ShiShen",e[e.Com=0]="Com",e[e.Gdp=0]="Gdp",e[e.DiaoBao=0]="DiaoBao",e[e.WuMei=0]="WuMei",e[e.Icon=0]="Icon",e[e.CaiHong=0]="CaiHong",e[e.DaHuZi1=0]="DaHuZi1",e[e.ShouZhang=0]="ShouZhang",e[e.HeiGuo=0]="HeiGuo",e[e.BBTV=0]="BBTV",e[e.FenDou=0]="FenDou",e[e.HongSheng=0]="HongSheng",e[e.XiZhuang=0]="XiZhuang",e[e.MeiHuo=0]="MeiHuo",e[e.Money=0]="Money",e[e.BoLiXin=0]="BoLiXin",e[e.KPI=0]="KPI",e[e.FenNu=0]="FenNu",e[e.XiaoXingXing=0]="XiaoXingXing",e[e.LiWu=0]="LiWu",e[e.QueShen=0]="QueShen",e[e.MaoMi2=0]="MaoMi2",e[e.HaiXiu=0]="HaiXiu",e[e.ChiXueGao=0]="ChiXueGao",e[e.GongZuoKuang=0]="GongZuoKuang",e[e.FuMo=0]="FuMo",e[e.NvShen=0]="NvShen",e[e.DaShen=0]="DaShen",e[e.BaJian=0]="BaJian",e[e.HuaXin=0]="HuaXin",e[e.DaHuZi2=0]="DaHuZi2",e[e.Christmas1=0]="Christmas1",e[e.Christmas2=0]="Christmas2",e[e.Christmas3=0]="Christmas3",e))(q||{});function j(){}j.getMakeupEyeBallUrl=function(e){return w+"makeup/eyeball/"+v[e]},j.getMakeupMouthRes=function(e){return[I[e],w+"makeup/mouth_yaochun/"+S[e]]},j.getMakeupEyeBrowRes=function(e){return[C[e],w+"makeup/eyebrow/"+N[e]]},j.getMakeupEyeShadowRes=function(e){return[T[e],w+"makeup/eyeshadow/"+$[e]]},j.getMakeupEyeLinerUrl=function(e){return w+"makeup/eyeliner/"+R[e]},j.getMakeupEyeLashUrl=function(e){return w+"makeup/eyelash/"+E[e]},j.getMakeupBlushUrl=function(e){return w+"makeup/blush/"+A[e]},j.getMakeupWholeUrl=function(e){return w+"makeup/whole/"+_[e]},j.getMakeupHighLightUrl=function(e){return w+"makeup/highlight/"+F[e]},j.getLutUrl=function(e){return w+"lookups/"+D[e]},j.getStickerUrl=function(e){return w+k+e+".bin"},j.getStickerUrlByIndex=function(e){return w+k+e+".bin"};const X=Object.freeze(Object.defineProperty({__proto__:null,QueenAssets:j,kAnimojiRes:G,kResLut:H,kResMakeupBlush:W,kResMakeupEyeBall:M,kResMakeupEyeBrow:L,kResMakeupEyeLash:B,kResMakeupEyeLiner:z,kResMakeupEyeShadow:P,kResMakeupHighLight:V,kResMakeupMouth:O,kResMakeupWhole:U,kResSticker:q},Symbol.toStringTag,{value:"Module"}));class K{constructor(){r(this,"_readResourceData",((e,t,n)=>{n()})),r(this,"clearAssetsCache",(()=>{}))}loadResourceData(e,t,n,s,r,a){const i=this;this._readResourceData(e,(function(e){t&&t((r+1)/a*100),n(e)}),(function(){i.fetchRemotePackage(e,t,(function(s){t&&t((r+1)/a*100),i.saveResourceData(e,s),n(s)}),s,r,a)}))}fetchRemotePackage(e,t,n,s,r=0,a=1){const i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onprogress=function(e){e.loaded&&e.total&&t&&t(100*r/a+e.loaded/e.total*100*(1/a))},i.onerror=function(){throw s(),new Error("NetworkError for: "+e)},i.onload=function(){if(!(200===i.status||304===i.status||206===i.status||0===i.status&&i.response))throw s(),new Error(i.statusText+" : "+i.responseURL);{const e=i.response;n&&n(e)}},i.send(null)}saveResourceData(e,t){}EncodeName(e){}}var Y=Object.defineProperty,Q=(e,t,n)=>(((e,t,n)=>{t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),J=(e,t,n)=>new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));let Z=class{constructor(e){Q(this,"webglContext"),Q(this,"renderProgram"),Q(this,"glVertexBuff"),Q(this,"glTexBuff"),Q(this,"glVloc"),Q(this,"glTloc"),Q(this,"width"),Q(this,"height"),Q(this,"getBufferSubData",(function(e,t,n){const s=this.webglContext,r=s.createBuffer();s.bindBuffer(s.PIXEL_PACK_BUFFER,r),s.bufferData(s.PIXEL_PACK_BUFFER,t*n*4,s.DYNAMIC_READ);const a=s.createFramebuffer();s.bindFramebuffer(s.FRAMEBUFFER,a),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,e,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.bindBuffer(s.PIXEL_PACK_BUFFER,r);let i=new Uint8Array(t*n*4);return s.getBufferSubData(s.PIXEL_PACK_BUFFER,0,i),i})),this.webglContext=e,this.width=e.canvas.width,this.height=e.canvas.height;const t=this.loadShader(e.VERTEX_SHADER,"attribute vec2 aVertex;attribute vec2 aUV;varying vec2 vTex;uniform vec2 pos;void main(void) { gl_Position = vec4(aVertex + pos, 0.0, 1.0); vTex = aUV;}"),n=this.loadShader(e.FRAGMENT_SHADER,"precision mediump float;varying vec2 vTex;uniform sampler2D sampler0;void main(void){ gl_FragColor = texture2D(sampler0, vTex);}");this.renderProgram=e.createProgram(),null!=t&&null!=n&&(e.attachShader(this.renderProgram,t),e.attachShader(this.renderProgram,n),e.linkProgram(this.renderProgram),this.glVertexBuff=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.glVertexBuff),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),e.STATIC_DRAW),this.glTexBuff=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.glTexBuff),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,0,1,1]),e.STATIC_DRAW),this.glVloc=e.getAttribLocation(this.renderProgram,"aVertex"),this.glTloc=e.getAttribLocation(this.renderProgram,"aUV"))}loadShader(e,t){const n=this.webglContext,s=n.createShader(e);return s?(n.shaderSource(s,t),n.compileShader(s),s):null}drawTexture(e,t,n){const s=this.webglContext;null!==s&&null!==e&&(null==t&&(t=this.width),null==n&&(n=this.height),s.useProgram(this.renderProgram),s.viewport(0,0,t,n),s.enableVertexAttribArray(this.glVloc),s.bindBuffer(s.ARRAY_BUFFER,this.glVertexBuff),s.vertexAttribPointer(this.glVloc,2,s.FLOAT,!1,0,0),s.enableVertexAttribArray(this.glTloc),s.bindBuffer(s.ARRAY_BUFFER,this.glTexBuff),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,e),s.vertexAttribPointer(this.glTloc,2,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLE_FAN,0,4),s.disableVertexAttribArray(this.glVloc),s.disableVertexAttribArray(this.glTloc),s.bindTexture(s.TEXTURE_2D,null))}createBlankTexture(e=1,t=1){const n=this.webglContext,s=n.createTexture();return n.bindTexture(n.TEXTURE_2D,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.bindTexture(n.TEXTURE_2D,null),s}createMediaTexture(e){const t=this.webglContext;t.pixelStorei(t.UNPACK_ALIGNMENT,4);const n=t.createTexture();return t.bindTexture(t.TEXTURE_2D,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),n}createBufferTexture(e,t,n){const s=this.webglContext;s.pixelStorei(s.UNPACK_ALIGNMENT,4);const r=s.createTexture();return s.bindTexture(s.TEXTURE_2D,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,t,n,0,s.RGBA,s.UNSIGNED_BYTE,e),s.bindTexture(s.TEXTURE_2D,null),r}updateTexture(e,t){const n=this.webglContext;n.pixelStorei(n.UNPACK_ALIGNMENT,4),n.bindTexture(n.TEXTURE_2D,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t),n.bindTexture(n.TEXTURE_2D,null)}updateTextureData(e,t,n,s){const r=this.webglContext;r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.bindTexture(r.TEXTURE_2D,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,n,s,0,r.RGBA,r.UNSIGNED_BYTE,t),r.bindTexture(r.TEXTURE_2D,null)}readPixels(e,t,n){const s=this.webglContext,r=new Uint8Array(t*n*4),a=s.createFramebuffer();return s.bindFramebuffer(s.FRAMEBUFFER,a),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,e,0),s.pixelStorei(s.PACK_ALIGNMENT,4),s.readPixels(0,0,t,n,s.RGBA,s.UNSIGNED_BYTE,r),s.bindFramebuffer(s.FRAMEBUFFER,null),s.deleteFramebuffer(a),r}};class ee{constructor(){Q(this,"wasmUrl"),Q(this,"webgl"),Q(this,"cacheHelper"),Q(this,"queenEngine"),Q(this,"wasmInvoker"),Q(this,"inputTextureId"),Q(this,"queenCanvas"),Q(this,"hasRenderCanvas"),Q(this,"cameraStream"),Q(this,"queenReady"),Q(this,"authState"),Q(this,"arWriteReady"),Q(this,"materialMap"),Q(this,"configUrlResources"),Q(this,"zipResources"),Q(this,"ModelConfig"),this.queenReady=!1,this.authState=!1,this.arWriteReady=!1,this.inputTextureId=0,this.hasRenderCanvas=!0,this.wasmInvoker=null,this.queenEngine=null,this.queenCanvas=null,this.wasmUrl="",this.materialMap=new Map,this.configUrlResources=new Map,this.zipResources=new Map,this.ModelConfig={SegmentModel:i.Horizontal,PoseModel:i.None,InferenceBackend:b.WebGL},this.cacheHelper=new K}checkSupportSIMD(){try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,9,1,7,0,65,0,253,15,26,11]))}catch(e){return!1}}checkSupportMutiThread(){try{return(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch(e){return!1}}getFullWasmName(e){let t=e?"-simd":"";return this.getWasmUrl()+`queen${t}.wasm`}getFullBinName(){return this.getWasmUrl()+"queen.bin"}getWasmLoaderUrl(e){return()=>import("./Empty-FmFgRqLi.js")}getWasmUrl(){return this.wasmUrl}setWasmUrl(e){console.info("base setWasmUrl",e),this.wasmUrl=e||`${x}wasm/advance/`}initialize(e,t,n,s,r={}){this.init(e,t,n,document.getElementById(s),r)}initializeWithUrl(e,t,n,s,r,a={}){this.setWasmUrl(e),this.init(t,n,s,r,a)}init(e,t,n,s,r={}){let a={SdkLicenseKey:e,OnInit:t,OnProgress:n,RenderCanvas:s,SegmentModel:i.Horizontal,PoseModel:i.None,InferenceBackend:b.WebGL,LogLevel:y.kLogNone};this._setModelConfig(r,a),this.create(a)}create(e){this._updateModel(e);const t=this;""===this.wasmUrl&&this.setWasmUrl(),this.initTensorflow();const n=this.checkSupportSIMD(),s=this.getWasmLoaderUrl(n),r=this.getFullWasmName(n);s().then((n=>{const s=this.getFullBinName();this.loadResourceData(s,e.OnProgress,(function(s){const a={onRuntimeInitialized:function(){t.wasmInvoker=a,t.loadQueenAssets(s)?t.queenInitialize(e.SdkLicenseKey,void 0!==e.OnFaceDetect,e.RenderCanvas).then((n=>{t.queenReady=!0,e.OnInit&&e.OnInit(n)})):(console.info("assets file load failed."),t.clearResourceCache(),e.OnInit&&e.OnInit(!1))},onTensorflowInferenceCallback:function(e,n,s,r){return t.segmentInferenceExecute(e,n,s,r)},onPoseTensorflowInferenceCallback:function(e,n,s,r){return t.poseInferenceExecute(e,n,s,r)},onFaceDataCallback:function(t){e.OnFaceDetect&&e.OnFaceDetect(t)},onAbort:function(t){e.OnError?e.OnError(t):console.error("wasm error,",t),e.OnInit&&e.OnInit(!1)},locateFile:function(e){return r}};n.default(a)}),(function(){e.OnProgress&&e.OnProgress(-1)}),0,1)}))}loadResourceData(e,t=function(){},n,s,r=0,a=1){this.cacheHelper.loadResourceData(e,t,n,s,r,a)}clearResourceCache(){this.cacheHelper.clearAssetsCache()}initializeWithBuffer(e,t,n,s,r,a={}){let o={SdkLicenseKey:e,OnInit:t,RenderCanvas:r,SegmentModel:i.None,PoseModel:i.None,InferenceBackend:b.WebGL,LogLevel:y.kLogNone};this._setModelConfig(a,o),this._updateModel(o);const u=this;""===this.wasmUrl&&this.setWasmUrl(),this.initTensorflow();const l=this.checkSupportSIMD();this.getWasmLoaderUrl(l)().then((a=>{const i={onRuntimeInitialized:function(){u.wasmInvoker=i,u.loadQueenAssets(s)?u.queenInitialize(e,!1,r).then((e=>{u.queenReady=!0,void 0!==t&&t(e)})):(console.info("assets file load failed."),u.clearResourceCache(),void 0!==t&&t(!1))},onTensorflowInferenceCallback:function(e,t,n,s){return u.segmentInferenceExecute(e,t,n,s)},onPoseTensorflowInferenceCallback:function(e,t,n,s){return u.poseInferenceExecute(e,t,n,s)},wasmBinary:n};a.default(i)}))}segmentInferenceExecute(e,t,n,s){}poseInferenceExecute(e,t,n,s){}setEngineParams(e){let[t,n]=this._splitConfig(e);this.queenEngine.setEngineParams(JSON.stringify(t)),this.setResourceParam(n)}setResourceParam(e){return J(this,null,(function*(){const t=this;this._replaceConfigUrl(e).then((e=>{t.queenEngine.setEngineParams(JSON.stringify(e))}))}))}_splitConfig(e){const t={},n={},s=["basicBeauty","advanceBeauty","faceShapeBeauty","segmentBackgroundProcess","bodyShapeBeauty"];for(const[r,a]of Object.entries(e))s.includes(r)?t[r]=a:n[r]=a;return[t,n]}_replaceConfigUrl(e){const t=this;return new Promise((function(n,s){t._processAndUploadResources(e).then((()=>{let s=t._updateConfigResource(e);n(s)}))}))}_updateConfigResource(e){const t={};for(const[n,s]of Object.entries(e)){if(s&&"object"==typeof s)if(Array.isArray(s)){let e=[];for(let t=0;t<s.length;t++){let n=this._updateConfigResource(s[t]);e.push(n)}t[n]=e}else t[n]=this._updateConfigResource(s);else t[n]=s;if(n.endsWith("Url")&&""!==s){const e=n.replace(/Url$/,"Path");if(s.indexOf(",")){let n=s.split(","),r="";for(let e=0;e<n.length;e++){let t=n[e].trim();this.configUrlResources.has(t)&&(r+=this.configUrlResources.get(t),e<n.length-1&&(r+=","))}t[e]=r}else this.configUrlResources.has(s)&&(t[e]=this.configUrlResources.get(s));delete t[n]}}return t}_isZipKey(e){return!!e.hasOwnProperty("isZip")&&e.isZip}_findConfigUrls(e,t=[],n=!1){for(const[s,r]of Object.entries(e))if("object"==typeof r)if(Array.isArray(r))for(let e of r)"object"==typeof e&&(n=this._isZipKey(e),this._findConfigUrls(e,t,n));else n=this._isZipKey(r),this._findConfigUrls(r,t,n);else if(s.endsWith("Url")&&null!==r){let e=r.split(",");for(let s of e)t.push(s.trim()),n&&this.zipResources.set(s.trim(),!0)}return t}_processAndUploadResources(e){const t=this,n=this._findConfigUrls(e).map((e=>t.configUrlResources.has(e)?Promise.resolve():t.loadResourceFileWithUrl(e,t.zipResources.has(e)).then((n=>{t.configUrlResources.set(e,n)}))));return Promise.all(n)}_updateModel(e){void 0!==e.SegmentModel&&(this.ModelConfig.SegmentModel=e.SegmentModel),void 0!==e.PoseModel&&(this.ModelConfig.PoseModel=e.PoseModel),void 0!==e.InferenceBackend&&(this.ModelConfig.InferenceBackend=e.InferenceBackend)}_setModelConfig(e,t){e.hasOwnProperty("segment")&&e.segment>=0&&e.segment<i.Max&&(t.SegmentModel=e.segment),e.hasOwnProperty("pose")&&e.pose>=0&&e.pose<i.Max&&(t.PoseModel=e.pose),e.hasOwnProperty("backend")&&e.backend>=0&&e.backend<b.Max&&(t.InferenceBackend=e.backend)}getModelConfig(){return this.ModelConfig}initTensorflow(){return J(this,arguments,(function*(e=i.None){}))}openCameraAndRender(e,t,n){const s=this;return null==e&&(e={audio:!1,video:{width:{ideal:1280},height:{ideal:720}}}),new Promise(((r,a)=>{void 0===navigator.mediaDevices?a("Your browser doesn't support the MediaDevices API"):navigator.mediaDevices.getUserMedia(e).then((e=>{s.cameraStream=e;let a=this.renderMediaStream(e,t,n);r(a)})).catch((e=>{a(e)}))}))}stopCamera(){this.cameraStream&&this.cameraStream.getTracks().forEach((e=>e.stop()))}render(e,t,n,s){if(!this.queenReady)return void this.queenAssert();const r=e.length,a=this.wasmInvoker._malloc(r);this.wasmInvoker.HEAPU8.set(e,a);const i=this.wasmInvoker._malloc(r);this.queenEngine.engineRender(a,t,n,i),this.wasmInvoker._free(a),this.renderDataCallback(i,r,t,n,s)}renderTextureId(e,t,n,s=0){if(!this.queenReady)return this.queenAssert(),null;const r=this.queenEngine.engineRenderWithTextureId(e,t,n,s);return this.wasmInvoker.GL.textures[r]}renderMediaObjectToRenderCanvas(e,t,n){if(!this.queenReady)return void this.queenAssert();if(!this.hasRenderCanvas)return void console.error("Please configure the RenderCanvas object used for rendering when initializing the SDK.");if("undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement&&(0==e.videoWidth||0==e.width))return;null!=t&&null!=n||("undefined"!=typeof VideoFrame&&e instanceof VideoFrame?(t=e.codedWidth,n=e.codedHeight):(t=e.width,n=e.height));const s=this.renderMediaObjectToTexture(e,t,n);s&&(t&&(this.queenCanvas.width=t),n&&(this.queenCanvas.height=n),this.webgl.drawTexture(s,t,n))}renderMediaObjectToTexture(e,t,n){if(!this.queenReady)return this.queenAssert(),null;if(null!=t&&null!=n||("undefined"!=typeof VideoFrame&&e instanceof VideoFrame?(t=e.codedWidth,n=e.codedHeight):(t=e.width,n=e.height)),0===t||0===n)return null;let s=this.buildInputTexture(e,t,n),r=this.queenEngine.engineRenderWithTextureId(s,t,n,0);return this.wasmInvoker.GL.textures[r]}renderWithMediaObject(e,t,n,s){if(!this.queenReady)return void this.queenAssert();let r=this.buildInputTexture(e,t,n),a=this.queenEngine.engineRenderWithTextureId(r,t,n,0),i=this.wasmInvoker.GL.textures[a];s(this.webgl.readPixels(i,t,n),t,n)}renderDataCallback(e,t,n,s,r){const a=this.wasmInvoker.HEAPU8.subarray(e,e+t);this.wasmInvoker._free(e),void 0!==r&&r(a,n,s)}renderMediaStream(e,t,n){if(0===e.getVideoTracks().length)return console.warn("Input media stream does not contain a video track."),e;const s=e.getVideoTracks()[0],r=this.renderMediaStreamTrack(s,t,n);if(r){const e=new MediaStream;return e.addTrack(r),e}return e}renderMediaStreamTrack(e,t,n){if("undefined"==typeof MediaStreamTrackProcessor||"undefined"==typeof MediaStreamTrackGenerator)return console.info("Your browser doesn't support the MediaStreamTrackProcessor API yet"),e;if(!this.queenReady)return this.queenAssert(),e;const s=new MediaStreamTrackProcessor({track:e}),r=new MediaStreamTrackGenerator({kind:"video"});return s.readable.pipeThrough(this.getTransformStream(t,n)).pipeTo(r.writable),r}getTransformStream(e,t){const n=this;return new TransformStream({transform(s,r){try{let a,i;if(a=e||n.hasRenderCanvas&&300!=n.queenCanvas.width&&n.queenCanvas.width||s.displayWidth||s.codedWidth,i=t||n.hasRenderCanvas&&150!=n.queenCanvas.height&&n.queenCanvas.height||s.displayHeight||s.codedHeight,n.queenCanvas.width=a,n.queenCanvas.height=i,null!==n.queenEngine){let e=n.renderMediaObjectToTexture(s,a,i);if(e){n.webgl.drawTexture(e,a,i);const t=s.timestamp,o=new VideoFrame(n.queenCanvas,{format:s.format,timestamp:t,codedHeight:i,codedWidth:a,displayHeight:i,displayWidth:a});r.enqueue(o),s.close()}}else r.enqueue(s)}catch(e){r.enqueue(s)}}})}queenInitialize(e,t=!1,n){const s=this;return new Promise(((r,a)=>{if(null===s.queenEngine){s.queenCanvas=n,null!==s.queenCanvas&&void 0!==s.queenCanvas||(s.hasRenderCanvas=!1,s.queenCanvas=s.createRenderCanvas()),s.webgl=new Z(s.getWebglContext()),s.initGLContext(s.queenCanvas),s.queenEngine=new s.wasmInvoker.Engine;const a=s.wasmInvoker.SdkInitCallback.implement({OnInit:e=>{-1===e&&console.error("queen license authentication failed."),s.authState=-1!==e,r(0===e)}});let i={licenseKey:e,faceData:t};s.queenEngine.engineInit(JSON.stringify(i),'{"basicBeauty":{"whitening":0.001}}',a),a.delete()}else a(!1)}))}disableGreenScreen(){this.setGreenScreenWithUrl(!1,"")}setGreenScreenWithUrl(e,t,n=1,s=!1,r=!1,a=d.kBackgroundBlur){const i=this,o=e;return new Promise(((e,u)=>{""===t?(i.queenEngine.setGreenScreen("",o,n,s,r,a),e()):i.loadResourceFileWithUrlSaveAs(t,"bg.png",!1).then((t=>{i.queenEngine.setGreenScreen(t,o,n,s,r,a),e()}),(function(){u()}))}))}enableBokehBackground(e){this.enableBackgroundByType(e,d.kBackgroundBlur)}enableTransparentBackground(e){this.enableBackgroundByType(e,d.kBackgroundTransparent)}enableBackgroundByType(e,t){e?(this.queenEngine.setSegmentBackgroundProcessType(t),this.setQueenBeautyType(a.BackgroundProcess,!0)):this.setQueenBeautyType(a.BackgroundProcess,!1)}disableSegmentBackground(){this.setSegmentBackgroundImage("")}setSegmentBackgroundUrl(e){const t=this;return new Promise((function(n,s){""===e?(t.setSegmentBackgroundImage(""),n()):t.loadResourceFileWithUrlSaveAs(e,"bg.png",!1).then((e=>{t.setSegmentBackgroundImage(e),n()}),(function(){s()}))}))}setSegmentBackgroundImage(e,t=d.kBackgroundNormal,n=!1,s=!1){this.setSegmentBackgroundProcessType(t),""===e?(this.setQueenBeautyType(a.BackgroundProcess,!1),this.queenEngine.setSegmentBackgroundImage("",n,s)):(this.setQueenBeautyType(a.BackgroundProcess,!0),this.queenEngine.setSegmentBackgroundImage(e,n,s))}setSegmentBackgroundProcessType(e){this.queenEngine.setSegmentBackgroundProcessType(e)}setAISegmentForegroundPadding(e){this.queenEngine.setAISegmentForegroundPadding(e)}setPureColorBackgroundUrl(e,t=1,n){const s=this;return new Promise((function(r,a){""===e?(s.setPureColorToBackground("",t,n),r()):s.loadResourceFileWithUrlSaveAs(e,"bg.png",!1).then((e=>{s.setPureColorToBackground(e,t,n),r()}),(function(){a()}))}))}setPureColorToBackground(e,t=1,n){this.queenEngine.setPureColorToBackground(e,n,t)}showQueenParamJson(){return this.queenEngine.getQueenBeautyParamsJsonConfig()}loadResourceFileWithUrl(e,t){const n=this;return new Promise((function(s,r){if(""===e)return void s(e);const a=n.wasmInvoker.LoadResourceCallback.implement({OnSuccess:(e,t)=>{t>0?s(e):r(e+"load fail.")},OnFailure:e=>{r(e)}});n.wasmInvoker.Resource.loadResourceFileWithUrl(e,"",t,a),a.delete()}))}loadQueenAssets(e){let t=new Uint8Array(e);const n=t.length,s=this.wasmInvoker._malloc(n);this.wasmInvoker.HEAPU8.set(t,s);var r=this.wasmInvoker.Resource.loadQueenAssets(s,n);return this.wasmInvoker._free(s),r}loadResourceFileWithUrlSaveAs(e,t,n){const s=this;return new Promise((function(r,a){fetch(e).then((e=>e.blob())).then((e=>e.arrayBuffer())).then((i=>{const o=s.wasmInvoker.LoadResourceCallback.implement({OnSuccess:(e,t)=>{t>0?r(e):a(e+"load fail.")},OnFailure:e=>{a(e)}});""===t&&(t=e.split("/").pop()+"");const u=new Uint8Array(i),l=u.length,c=s.wasmInvoker._malloc(l);s.wasmInvoker.HEAPU8.set(u,c),s.wasmInvoker.Resource.loadResourceFileWithData(c,l,t,n,o),o.delete(),s.wasmInvoker._free(c)}))}))}loadResourceFileWithData(e,t,n){const s=this;return new Promise((function(r,a){const i=s.wasmInvoker.LoadResourceCallback.implement({OnSuccess:(e,t)=>{t>0?r(e):a(e+"load fail.")},OnFailure:e=>{a(e)}});let o=new Uint8Array(e);const u=o.length,l=s.wasmInvoker._malloc(u);s.wasmInvoker.HEAPU8.set(o,l),s.wasmInvoker.Resource.loadResourceFileWithData(l,u,t,n,i),i.delete(),s.wasmInvoker._free(l)}))}checkResourceFile(e){return this.wasmInvoker.Resource.checkResourceFile(e)}setQueenBeautyType(e,t){this.queenEngine.setQueenBeautyType(e,t)}setQueenBeautyParams(e,t){this.queenEngine.setQueenBeautyParams(e,t)}getQueenBeautyParams(e){return this.queenEngine.getQueenBeautyParams(e)}setInputFlip(e){this.queenEngine.setInputFlip(e)}disableLut(){this.queenEngine.setLutImagePath("")}setLutByType(e,t=.5){const n=j.getLutUrl(e);return this.setQueenBeautyType(a.LUT,!0),this.setQueenBeautyParams(o.LUT,t),this.setLutImageUrl(n)}setLutImageUrl(e){const t=this;return new Promise((function(n,s){""===e?(t.queenEngine.setLutImagePath(""),n()):t.loadResourceFileWithUrl(e,!1).then((e=>{t.queenEngine.setLutImagePath(e),n()}),(function(){s()}))}))}setLutImagePath(e){this.queenEngine.setLutImagePath(e)}setFaceShape(e,t){this.queenEngine.setFaceShape(e,t)}setMakeupEyeBrow(e,t,n=h.LabMix){const[s,r]=j.getMakeupEyeBrowRes(e);return this.setMakeupAlphaWithType(l.EyeBrow,!0,t),this.setMakeupWithPackage(l.EyeBrow,r,s,n)}setMackupEyeLash(e,t,n=h.LabMix){const s=j.getMakeupEyeLashUrl(e);return this.setMakeupAlphaWithType(l.Eyelash,!0,t),this.setMakeupWithUrl(l.Eyelash,s,n)}setMakeupEyeShadow(e,t,n=h.LabMix){const[s,r]=j.getMakeupEyeShadowRes(e);return this.setMakeupAlphaWithType(l.EyeShadow,!0,t),this.setMakeupWithPackage(l.EyeShadow,r,s,n)}setMakeupEyeLiner(e,t,n=h.LabMix){const s=j.getMakeupEyeLinerUrl(e);return this.setMakeupAlphaWithType(l.Eyeliner,!0,t),this.setMakeupWithUrl(l.Eyeliner,s,n)}setMakeupEyeBall(e,t,n=h.LabMix){const s=j.getMakeupEyeBallUrl(e);return this.setMakeupAlphaWithType(l.Eyeball,!0,t),this.setMakeupWithUrl(l.Eyeball,s,n)}setMakeupMouth(e,t,n=h.LabMix){const[s,r]=j.getMakeupMouthRes(e);return this.setMakeupAlphaWithType(l.Mouth,!0,t),this.setMakeupWithPackage(l.Mouth,r,s,n)}setMakeupWhole(e,t,n=h.LabMix){const s=j.getMakeupWholeUrl(e);return this.setMakeupAlphaWithType(l.Whole,!0,t),this.setMakeupWithUrl(l.Whole,s,n)}setMakeupBlush(e,t,n=h.LabMix){const s=j.getMakeupBlushUrl(e);return this.setMakeupAlphaWithType(l.Blush,!0,t),this.setMakeupWithUrl(l.Blush,s,n)}setMakeupHighlight(e,t,n=h.LabMix){const s=j.getMakeupHighLightUrl(e);return this.setMakeupAlphaWithType(l.Highlight,!0,t),this.setMakeupWithUrl(l.Highlight,s,n)}setMakeupWithUrl(e,t,n){const s=this;return new Promise((function(r,a){s.loadResourceFileWithUrl(t,!1).then((t=>{s.setMakeupWithType(e,t,n,20),r()}),(function(){a()}))}))}setMakeupWithPackage(e,t,n,s){const r=this;return new Promise((function(a,i){r.loadResourceFileWithUrl(t,!0).then((t=>{r.setMakeupWithType(e,t+n,s,20),a()}),(function(){i()}))}))}setMakeupWithType(e,t,n,s=20){this.queenEngine.setMakeupWithTypeFps(e,t,n,s)}setMakeupFemaleAlpha(e,t){this.setMakeupAlphaWithType(e,!0,t)}setMakeupMaleAlpha(e,t){this.setMakeupAlphaWithType(e,!1,t)}setMakeupAlphaWithType(e,t,n){this.queenEngine.setMakeupAlphaWithType(e,t,n)}setMakeupBlendWithType(e,t){this.queenEngine.setMakeupBlendWithType(e,t)}removeMakeupWithType(e){this.setMakeupWithType(e,"",0)}resetAllMakeupType(){this.queenEngine.resetAllMakeupType()}addMaterialWithType(e){const t=j.getStickerUrl(e);return this.addMaterialWithUrl(t)}addMaterialWithIndex(e){const t=j.getStickerUrlByIndex(e);return this.addMaterialWithUrl(t)}addMaterialWithIndexs(e){const t=e.map((e=>J(this,null,(function*(){const t=j.getStickerUrlByIndex(e);yield this.addMaterialWithUrl(t)}))));return Promise.all(t)}addMaterialWithUrl(e,t=0){const n=this;return new Promise((function(s,r){n.loadResourceFileWithUrl(e,!0).then((r=>{n.materialMap.set(e,r),n.queenEngine.addMaterialWithPath(r,t),s()}),(function(){r()}))}))}addMaterialWithPath(e,t=0){this.queenEngine.addMaterialWithPath(e,t)}removeMaterialWithType(e){const t=j.getStickerUrl(e);this.removeMaterialWithUrl(t)}removeMaterialWithIndex(e){const t=j.getStickerUrlByIndex(e);this.removeMaterialWithUrl(t)}removeMaterialWithUrl(e){if(this.materialMap.has(e)){const t=this.materialMap.get(e);this.removeMaterialWithPath(t)}}removeMaterialWithPath(e){this.queenEngine.removeMaterialWithPath(e)}showFaceDetectPoint(e){this.queenEngine.setQueenBeautyType(a.Makeup,!0),this.setMakeupHighlight(V.Highlight,.01),this.queenEngine.showFaceDetectPoint(e)}showMakeupLine(e){this.queenEngine.setQueenBeautyType(a.Makeup,!0),this.setMakeupHighlight(V.Highlight,.01),this.queenEngine.showMakeupLine(e)}showBodyDetectPoint(e){this.queenEngine.showBodyDetectPoint(e)}engineDestory(){this.queenReady=!1,this.authState=!1,setTimeout((()=>{this.queenEngine.engineDestory()}),100)}initArWriteResource(){const e=this,t=this.getWasmUrl()+"models/handmodels.bin";return new Promise((function(n,s){e.arWriteReady?n(!0):e.loadResourceData(t,(e=>{}),(function(t){e.loadQueenAssets(t)?(n(!0),e.arWriteReady=!0):n(!1)}),(()=>{}),0,1)}))}setArWriting(e,t){this.queenEngine.setArWriting(e,t)}cleanScreenArWriting(){this.queenEngine.cleanScreenArWriting()}setPowerSaving(e){this.queenEngine.setPowerSaving(e)}setBodyShape(e,t){this.queenEngine.setBodyShape(e,t)}animojiInitialize(e,t,n,s){const r=this;return new Promise((function(a,i){r.loadResourceFileWithUrl(e,!0).then((e=>{r.queenEngine.animojiInit(e,t,n,s),a()}),(function(){i()}))}))}setAnimojiBackgroundWithMode(e,t){const n=this;return new Promise((function(s,r){""===t?(n.queenEngine.setAnimojiBackgroundMode(e,""),s()):n.loadResourceFileWithUrl(t,!1).then((t=>{n.queenEngine.setAnimojiBackgroundMode(e,t),s()}),(function(){r()}))}))}animojiRenderMediaObjectToRenderCanvas(e,t,n){if(!this.queenReady)return void this.queenAssert();if(!this.hasRenderCanvas)return void console.error("Please configure the RenderCanvas object used for rendering when initializing the SDK.");if("undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement&&(0==e.videoWidth||0==e.width))return;const s=this.animojiRenderMediaObjectToTexture(e,t,n);s&&(t&&(this.queenCanvas.width=t),n&&(this.queenCanvas.height=n),this.webgl.drawTexture(s,t,n))}animojiRender(e,t,n,s){if(!this.queenReady)return void this.queenAssert();const r=e.length,a=this.wasmInvoker._malloc(r);this.wasmInvoker.HEAPU8.set(e,a);const i=this.wasmInvoker._malloc(r);this.queenEngine.animojiRender(a,t,n,i),this.renderDataCallback(i,r,t,n,s),this.wasmInvoker._free(a)}animojiRenderWithMediaObject(e,t,n,s){if(!this.queenReady)return void this.queenAssert();let r=this.buildInputTexture(e,t,n),a=this.queenEngine.animojiRenderWithTextureId(r,t,n),i=this.wasmInvoker.GL.textures[a];s(this.webgl.readPixels(i,t,n),t,n)}animojiRenderMediaObjectToTexture(e,t,n){if(!this.queenReady)return this.queenAssert(),null;null!=t&&null!=n||("undefined"!=typeof VideoFrame&&e instanceof VideoFrame?(t=e.codedWidth,n=e.codedHeight):(t=e.width,n=e.height));let s=this.buildInputTexture(e,t,n),r=this.queenEngine.animojiRenderWithTextureId(s,t,n);return this.wasmInvoker.GL.textures[r]}animojiRenderTextureId(e,t,n){if(!this.queenReady)return this.queenAssert(),null;let s=this.queenEngine.animojiRenderWithTextureId(e,t,n);return this.wasmInvoker.GL.textures[s]}animojiResize(e){this.queenEngine.animojiResize(e)}animojiDestroy(){this.queenEngine.animojiDestroy()}getEngine(){return this.queenEngine}getWebglUtil(){return this.webgl}createRenderCanvas(){let e=document.createElement("canvas");return e.id="queen_wasm_canvas_effect_render_1",e.style.display="none",document.body.appendChild(e),e}getWebglContext(){return this.queenCanvas.getContext("webgl2")?this.queenCanvas.getContext("webgl2"):this.queenCanvas.getContext("webgl")}initGLContext(e){const t=this.wasmInvoker.GL.createContext(e,{explicitSwapControl:0,majorVersion:2,minorVersion:0,alpha:0,antialias:0,premultipliedAlpha:0,preserveDrawingBuffer:0,depth:0,stencil:0,powerPreference:"high-performance",failIfMajorPerformanceCaveat:1});this.wasmInvoker.canvas=e,this.wasmInvoker.GL.makeContextCurrent(t);let n=this.getWebglContext();n.disable(n.DEPTH_TEST),n.disable(n.STENCIL_TEST),n.disable(n.BLEND),n.disable(n.DITHER),n.disable(n.POLYGON_OFFSET_FILL),n.disable(n.SAMPLE_COVERAGE),n.disable(n.SCISSOR_TEST)}resetGLContext(){const e=this.getWebglContext();this.wasmInvoker.GL.deleteContext(e),this.initGLContext(this.queenCanvas)}_getInputTexture(e=1,t=1){if(0===this.inputTextureId){const n=this.webgl.createBlankTexture(e,t);this.inputTextureId=this.buildTextureId(n)}return[this.inputTextureId,this.wasmInvoker.GL.textures[this.inputTextureId]]}buildInputTexture(e,t=1,n=1){let[s,r]=this._getInputTexture(t,n);return e instanceof Uint8Array?this.webgl.updateTextureData(r,e,t,n):this.webgl.updateTexture(r,e),s}generateTexture(e,t,n){let s;return s=e instanceof Uint8Array?this.webgl.createBufferTexture(e,t,n):this.webgl.createMediaTexture(e),this.buildTextureId(s)}generateBlankTexture(e=1,t=1){let n=this.webgl.createBlankTexture(e,t);return this.buildTextureId(n)}buildTextureId(e){const t=this.wasmInvoker.GL.getNewId(this.wasmInvoker.GL.textures);return this.wasmInvoker.GL.textures[t]=e,t}getGLTextureById(e){return this.wasmInvoker.GL.textures[e]}drawOutTexture(e,t,n){this.webgl.drawTexture(e,t,n)}queenAssert(){this.queenReady||console.error("Queen Engine initialization failed."),this.authState||console.error("queen license authentication failed.")}assertMessage(e,t){e||console.error(t)}}var te=Object.defineProperty,ne=(e,t,n)=>(((e,t,n)=>{t in e?te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class se extends ee{constructor(){super()}setWasmUrl(e){let t=e||`${x}wasm/advance/`;super.setWasmUrl(t)}getWasmLoaderUrl(e){return e?()=>import("./queen-simd-DQQCU-XB.js"):()=>import("./queen-FlAAeipC.js")}initTensorflow(){return e=this,t=arguments,n=function*(e=i.None){},new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));var e,t,n}segmentInferenceExecute(e,t,n,s){}poseInferenceExecute(e,t,n,s){}}ne(se,"Assets",X),ne(se,"kQueenBeautyType",a),ne(se,"kQueenBeautyParams",o),ne(se,"kBackgroundProcessType",d),ne(se,"kQueenBeautyMakeupType",l),ne(se,"kQueenBeautyFaceShapeType",c),ne(se,"kQueenBeautyBlend",h),ne(se,"kSegmentPerformanceMode",p),ne(se,"kQueenBeautyBodyShapeType",u),ne(se,"kQueenModelShapeType",i);var re=Object.defineProperty,ae=(e,t,n)=>(((e,t,n)=>{t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class ie extends ee{constructor(){super()}setWasmUrl(e){let t=e||`${x}wasm/lite/`;super.setWasmUrl(t)}getWasmLoaderUrl(e){return e?()=>import("./queen-simd-lite-DfCTDs0x.js"):()=>import("./queen-lite-BcW1Sf7f.js")}initTensorflow(){return e=this,t=arguments,n=function*(e=i.None){},new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));var e,t,n}segmentInferenceExecute(e,t,n,s){}poseInferenceExecute(e,t,n,s){}}ae(ie,"kQueenBeautyType",a),ae(ie,"kQueenBeautyParams",o);class oe{constructor(e,t){this.backend=e,this.dataMover=t,this.data=new WeakMap,this.dataIdsCount=0}get(e){return this.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)}set(e,t){this.dataIdsCount++,this.data.set(e,t)}has(e){return this.data.has(e)}delete(e){return this.dataIdsCount--,this.data.delete(e)}numDataIds(){return this.dataIdsCount}}class ue{refCount(e){return le("refCount")}incRef(e){return le("incRef")}timerAvailable(){return!0}time(e){return le("time")}read(e){return le("read")}readSync(e){return le("readSync")}readToGPU(e,t){return le("readToGPU")}numDataIds(){return le("numDataIds")}disposeData(e,t){return le("disposeData")}write(e,t,n){return le("write")}move(e,t,n,s,r){return le("move")}createTensorFromGPUData(e,t,n){return le("createTensorFromGPUData")}memory(){return le("memory")}floatPrecision(){return le("floatPrecision")}epsilon(){return 32===this.floatPrecision()?1e-7:1e-4}dispose(){return le("dispose")}}function le(e){throw new Error(`'${e}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`)}
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2603,7 +2603,7 @@ function(e,t){let n=ii(e,"a","minimum"),s=ii(t,"b","minimum");[n,s]=Ha(n,s),"boo
|
|
|
2603
2603
|
* See the License for the specific language governing permissions and
|
|
2604
2604
|
* limitations under the License.
|
|
2605
2605
|
* =============================================================================
|
|
2606
|
-
*/const Tc=li({rand_:function(e,t,n){Ge(e);const s=be(e);let r=null;if(null==n||"float32"===n)r=new Float32Array(s);else if("int32"===n)r=new Int32Array(s);else{if("bool"!==n)throw new Error(`Unknown data type ${n}`);r=new Uint8Array(s)}for(let e=0;e<s;e++)r[e]=t();return Ja.makeTensor(r,e,n)}});var $c={exports:{}};!function(e,t,n){function s(e){var t=this,n=function(){var e=4022871197,t=function(t){t=String(t);for(var n=0;n<t.length;n++){var s=.02519603282416938*(e+=t.charCodeAt(n));s-=e=s>>>0,e=(s*=e)>>>0,e+=4294967296*(s-=e)}return 2.3283064365386963e-10*(e>>>0)};return t}();t.next=function(){var e=2091639*t.s0+2.3283064365386963e-10*t.c;return t.s0=t.s1,t.s1=t.s2,t.s2=e-(t.c=0|e)},t.c=1,t.s0=n(" "),t.s1=n(" "),t.s2=n(" "),t.s0-=n(e),t.s0<0&&(t.s0+=1),t.s1-=n(e),t.s1<0&&(t.s1+=1),t.s2-=n(e),t.s2<0&&(t.s2+=1),n=null}function r(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function a(e,t){var n=new s(e),a=t&&t.state,i=n.next;return i.int32=function(){return 4294967296*n.next()|0},i.double=function(){return i()+11102230246251565e-32*(2097152*i()|0)},i.quick=i,a&&("object"==typeof a&&r(a,n),i.state=function(){return r(n,{})}),i}t&&t.exports?t.exports=a:
|
|
2606
|
+
*/const Tc=li({rand_:function(e,t,n){Ge(e);const s=be(e);let r=null;if(null==n||"float32"===n)r=new Float32Array(s);else if("int32"===n)r=new Int32Array(s);else{if("bool"!==n)throw new Error(`Unknown data type ${n}`);r=new Uint8Array(s)}for(let e=0;e<s;e++)r[e]=t();return Ja.makeTensor(r,e,n)}});var $c={exports:{}};!function(e,t,n){function s(e){var t=this,n=function(){var e=4022871197,t=function(t){t=String(t);for(var n=0;n<t.length;n++){var s=.02519603282416938*(e+=t.charCodeAt(n));s-=e=s>>>0,e=(s*=e)>>>0,e+=4294967296*(s-=e)}return 2.3283064365386963e-10*(e>>>0)};return t}();t.next=function(){var e=2091639*t.s0+2.3283064365386963e-10*t.c;return t.s0=t.s1,t.s1=t.s2,t.s2=e-(t.c=0|e)},t.c=1,t.s0=n(" "),t.s1=n(" "),t.s2=n(" "),t.s0-=n(e),t.s0<0&&(t.s0+=1),t.s1-=n(e),t.s1<0&&(t.s1+=1),t.s2-=n(e),t.s2<0&&(t.s2+=1),n=null}function r(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function a(e,t){var n=new s(e),a=t&&t.state,i=n.next;return i.int32=function(){return 4294967296*n.next()|0},i.double=function(){return i()+11102230246251565e-32*(2097152*i()|0)},i.quick=i,a&&("object"==typeof a&&r(a,n),i.state=function(){return r(n,{})}),i}t&&t.exports?t.exports=a:this.alea=a}(0,$c);var Rc=$c.exports,Ec={exports:{}};!function(e,t,n){function s(e){var t=this,n="";t.x=0,t.y=0,t.z=0,t.w=0,t.next=function(){var e=t.x^t.x<<11;return t.x=t.y,t.y=t.z,t.z=t.w,t.w^=t.w>>>19^e^e>>>8},e===(0|e)?t.x=e:n+=e;for(var s=0;s<n.length+64;s++)t.x^=0|n.charCodeAt(s),t.next()}function r(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t}function a(e,t){var n=new s(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&("object"==typeof a&&r(a,n),i.state=function(){return r(n,{})}),i}t&&t.exports?t.exports=a:this.xor128=a}(0,Ec);var Ac=Ec.exports,_c={exports:{}};!function(e,t,n){function s(e){var t=this,n="";t.next=function(){var e=t.x^t.x>>>2;return t.x=t.y,t.y=t.z,t.z=t.w,t.w=t.v,(t.d=t.d+362437|0)+(t.v=t.v^t.v<<4^e^e<<1)|0},t.x=0,t.y=0,t.z=0,t.w=0,t.v=0,e===(0|e)?t.x=e:n+=e;for(var s=0;s<n.length+64;s++)t.x^=0|n.charCodeAt(s),s==n.length&&(t.d=t.x<<10^t.x>>>4),t.next()}function r(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t.v=e.v,t.d=e.d,t}function a(e,t){var n=new s(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&("object"==typeof a&&r(a,n),i.state=function(){return r(n,{})}),i}t&&t.exports?t.exports=a:this.xorwow=a}(0,_c);var Fc=_c.exports,Dc={exports:{}};!function(e,t,n){function s(e){var t=this;t.next=function(){var e,n,s=t.x,r=t.i;return e=s[r],n=(e^=e>>>7)^e<<24,n^=(e=s[r+1&7])^e>>>10,n^=(e=s[r+3&7])^e>>>3,n^=(e=s[r+4&7])^e<<7,e=s[r+7&7],n^=(e^=e<<13)^e<<9,s[r]=n,t.i=r+1&7,n},function(e,t){var n,s=[];if(t===(0|t))s[0]=t;else for(t=""+t,n=0;n<t.length;++n)s[7&n]=s[7&n]<<15^t.charCodeAt(n)+s[n+1&7]<<13;for(;s.length<8;)s.push(0);for(n=0;n<8&&0===s[n];++n);for(8==n?s[7]=-1:s[n],e.x=s,e.i=0,n=256;n>0;--n)e.next()}(t,e)}function r(e,t){return t.x=e.x.slice(),t.i=e.i,t}function a(e,t){null==e&&(e=+new Date);var n=new s(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&(a.x&&r(a,n),i.state=function(){return r(n,{})}),i}t&&t.exports?t.exports=a:this.xorshift7=a}(0,Dc);var Mc=Dc.exports,Oc={exports:{}};!function(e,t,n){function s(e){var t=this;t.next=function(){var e,n,s=t.w,r=t.X,a=t.i;return t.w=s=s+1640531527|0,n=r[a+34&127],e=r[a=a+1&127],n^=n<<13,e^=e<<17,n^=n>>>15,e^=e>>>12,n=r[a]=n^e,t.i=a,n+(s^s>>>16)|0},function(e,t){var n,s,r,a,i,o=[],u=128;for(t===(0|t)?(s=t,t=null):(t+="\0",s=0,u=Math.max(u,t.length)),r=0,a=-32;a<u;++a)t&&(s^=t.charCodeAt((a+32)%t.length)),0===a&&(i=s),s^=s<<10,s^=s>>>15,s^=s<<4,s^=s>>>13,a>=0&&(i=i+1640531527|0,r=0==(n=o[127&a]^=s+i)?r+1:0);for(r>=128&&(o[127&(t&&t.length||0)]=-1),r=127,a=512;a>0;--a)s=o[r+34&127],n=o[r=r+1&127],s^=s<<13,n^=n<<17,s^=s>>>15,n^=n>>>12,o[r]=s^n;e.w=i,e.X=o,e.i=r}(t,e)}function r(e,t){return t.i=e.i,t.w=e.w,t.X=e.X.slice(),t}function a(e,t){null==e&&(e=+new Date);var n=new s(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&(a.X&&r(a,n),i.state=function(){return r(n,{})}),i}t&&t.exports?t.exports=a:this.xor4096=a}(0,Oc);var Lc=Oc.exports,Pc={exports:{}};!function(e,t,n){function s(e){var t=this,n="";t.next=function(){var e=t.b,n=t.c,s=t.d,r=t.a;return e=e<<25^e>>>7^n,n=n-s|0,s=s<<24^s>>>8^r,r=r-e|0,t.b=e=e<<20^e>>>12^n,t.c=n=n-s|0,t.d=s<<16^n>>>16^r,t.a=r-e|0},t.a=0,t.b=0,t.c=-1640531527,t.d=1367130551,e===Math.floor(e)?(t.a=e/4294967296|0,t.b=0|e):n+=e;for(var s=0;s<n.length+20;s++)t.b^=0|n.charCodeAt(s),t.next()}function r(e,t){return t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t}function a(e,t){var n=new s(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&("object"==typeof a&&r(a,n),i.state=function(){return r(n,{})}),i}t&&t.exports?t.exports=a:this.tychei=a}(0,Pc);var zc,Bc=Pc.exports,Wc={exports:{}};zc=Wc,function(e,t,n){var s,r=256,a="random",i=n.pow(r,6),o=n.pow(2,52),u=2*o,l=r-1;function c(l,c,g){var y=[],b=f(p((c=1==c?{entropy:!0}:c||{}).entropy?[l,m(t)]:null==l?function(){try{var n;return s&&(n=s.randomBytes)?n=n(r):(n=new Uint8Array(r),(e.crypto||e.msCrypto).getRandomValues(n)),m(n)}catch(n){var a=e.navigator,i=a&&a.plugins;return[+new Date,e,i,e.screen,m(t)]}}():l,3),y),x=new h(y),w=function(){for(var e=x.g(6),t=i,n=0;e<o;)e=(e+n)*r,t*=r,n=x.g(1);for(;e>=u;)e/=2,t/=2,n>>>=1;return(e+n)/t};return w.int32=function(){return 0|x.g(4)},w.quick=function(){return x.g(4)/4294967296},w.double=w,f(m(x.S),t),(c.pass||g||function(e,t,s,r){return r&&(r.S&&d(r,x),e.state=function(){return d(x,{})}),s?(n[a]=e,t):e})(w,b,"global"in c?c.global:this==n,c.state)}function h(e){var t,n=e.length,s=this,a=0,i=s.i=s.j=0,o=s.S=[];for(n||(e=[n++]);a<r;)o[a]=a++;for(a=0;a<r;a++)o[a]=o[i=l&i+e[a%n]+(t=o[a])],o[i]=t;(s.g=function(e){for(var t,n=0,a=s.i,i=s.j,o=s.S;e--;)t=o[a=l&a+1],n=n*r+o[l&(o[a]=o[i=l&i+t])+(o[i]=t)];return s.i=a,s.j=i,n})(r)}function d(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function p(e,t){var n,s=[],r=typeof e;if(t&&"object"==r)for(n in e)try{s.push(p(e[n],t-1))}catch(e){}return s.length?s:"string"==r?e:e+"\0"}function f(e,t){for(var n,s=e+"",r=0;r<s.length;)t[l&r]=l&(n^=19*t[l&r])+s.charCodeAt(r++);return m(t)}function m(e){return String.fromCharCode.apply(0,e)}if(f(n.random(),t),zc.exports){zc.exports=c;try{s=require("crypto")}catch(e){}}else n["seed"+a]=c}("undefined"!=typeof self?self:Sr,[],Math);var Uc=Rc,Vc=Ac,Gc=Fc,Hc=Mc,qc=Lc,jc=Bc,Xc=Wc.exports;Xc.alea=Uc,Xc.xor128=Vc,Xc.xorwow=Gc,Xc.xorshift7=Hc,Xc.xor4096=qc,Xc.tychei=jc;var Kc=Xc;
|
|
2607
2607
|
/**
|
|
2608
2608
|
* @license
|
|
2609
2609
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16026,7 +16026,7 @@ var t;this.scale=null==e.scale?1:e.scale,this.mode=null==e.mode?"fanIn":e.mode,t
|
|
|
16026
16026
|
* https://opensource.org/licenses/MIT.
|
|
16027
16027
|
* =============================================================================
|
|
16028
16028
|
*/
|
|
16029
|
-
function(e,t){if(null==e.dtype||e.dtype===t.dtype)return t;try{return vo(t,e.dtype)}catch(n){throw new HP(`The dtype of the feed (${t.dtype}) can not be cast to the dtype of the key '${e.name}' (${e.dtype}).`)}}(e,t),this.name2Id[e.name]=e.id,null!=n&&(this.id2Mask[e.id]=n),this}addFeed(e){this.add(e.key,e.value)}hasKey(e){return null!=this.id2Value[e.id]}names(){return Object.keys(this.name2Id)}getValue(e){if(e instanceof MB){if(null==this.id2Value[e.id])throw new HP(`Nonexistent key: ${e.name}`);return this.id2Value[e.id]}{const t=this.name2Id[e];if(null==t)throw new HP(`Feed dict has no SymbolicTensor name: ${e}`);return this.id2Value[t]}}getMask(e){if(e instanceof MB){if(null==this.id2Value[e.id])throw new HP(`Nonexistent key: ${e.name}`);return this.id2Mask[e.id]}{const t=this.name2Id[e];if(null==t)throw new HP(`Feed dict has no SymbolicTensor name: ${e}`);return this.id2Mask[t]}}disposeMasks(){null!=this.id2Mask&&xi(this.id2Mask)}}const VB=new XP,GB=new XP;function HB(e,t,n,s){const r=null!=n&&n.training,a=Array.isArray(e),i=a?e:[e],o=i.map((e=>e.name)),u=[],l=t.names();for(const e of o)-1!==l.indexOf(e)?u.push(t.getValue(e)):u.push(null);
|
|
16029
|
+
function(e,t){if(null==e.dtype||e.dtype===t.dtype)return t;try{return vo(t,e.dtype)}catch(n){throw new HP(`The dtype of the feed (${t.dtype}) can not be cast to the dtype of the key '${e.name}' (${e.dtype}).`)}}(e,t),this.name2Id[e.name]=e.id,null!=n&&(this.id2Mask[e.id]=n),this}addFeed(e){this.add(e.key,e.value)}hasKey(e){return null!=this.id2Value[e.id]}names(){return Object.keys(this.name2Id)}getValue(e){if(e instanceof MB){if(null==this.id2Value[e.id])throw new HP(`Nonexistent key: ${e.name}`);return this.id2Value[e.id]}{const t=this.name2Id[e];if(null==t)throw new HP(`Feed dict has no SymbolicTensor name: ${e}`);return this.id2Value[t]}}getMask(e){if(e instanceof MB){if(null==this.id2Value[e.id])throw new HP(`Nonexistent key: ${e.name}`);return this.id2Mask[e.id]}{const t=this.name2Id[e];if(null==t)throw new HP(`Feed dict has no SymbolicTensor name: ${e}`);return this.id2Mask[t]}}disposeMasks(){null!=this.id2Mask&&xi(this.id2Mask)}}const VB=new XP,GB=new XP;function HB(e,t,n,s){const r=null!=n&&n.training,a=Array.isArray(e),i=a?e:[e],o=i.map((e=>e.name)),u=[],l=t.names();for(const e of o)-1!==l.indexOf(e)?u.push(t.getValue(e)):u.push(null);const c=o.join(",")+"|"+t.names().sort().join(",");let h,d=VB.get(c);if(null==d){const e=function(e,t){me(null!=e&&e.length>0,(()=>"Expected at least one fetch, got none"));let n=[],s={};if(1===e.length){const r=jB(e[0],t);n=r.sorted,s=r.recipientMap}else{const r=new Set;for(const a of e){const{sorted:e,recipientMap:i}=jB(a,t);for(const t of e)r.has(t.name)||(n.push(t),r.add(t.name));for(const e in i)null==s[e]&&(s[e]=new Set),i[e].forEach((t=>s[e].add(t)))}}return{sorted:n,recipientCounts:qB(s)}}(i,t);d=e.sorted,h=e.recipientCounts,VB.put(c,d),GB.put(c,h)}h={},r||Object.assign(h,GB.get(c));const p=new UB(t);for(let e=0;e<d.length;++e){const s=d[e],a=s.sourceLayer;if(a instanceof WB)continue;const i=[],l=[],c=[];let f=!1;for(const e of s.inputs){const n=p.getValue(e),s=p.getMask(e);i.push(n),l.push(s),null!=s&&(f=!0),r||(h[e.name]--,0!==h[e.name]||t.hasKey(e)||-1!==o.indexOf(e.name)||n.isDisposed||!0===e.sourceLayer.stateful||c.push(n))}f&&((n=n||{}).mask=l[0]);const m=ZP(a.apply(i,n));let g=null;a.supportsMasking&&(g=a.computeMask(i,l));const y=XB(s),b=Array.isArray(y)?y:[y];for(let e=0;e<b.length;++e){p.hasKey(b[e])||p.add(b[e],m[e],Array.isArray(g)?g[0]:g);const t=o.indexOf(b[e].name);-1!==t&&(u[t]=m[e])}r||xi(c)}return p.disposeMasks(),a?u:u[0]}function qB(e){const t={};for(const n in e)t[n]=e[n].size;return t}function jB(e,t){const n=new Set,s=[],r={};for(const e of t.names())n.add(e);const a=[],i=[];for(a.push(e);a.length>0;){const e=a[a.length-1];if(n.has(e.name)){a.pop();continue}const t=i[i.length-1]===a.length-1;if(0===e.inputs.length||t)a.pop(),s.push(e),n.add(e.name),t&&i.pop();else{i.push(a.length-1);for(const t of e.inputs)null==r[t.name]&&(r[t.name]=new Set),r[t.name].add(e.name),n.has(t.name)||a.push(t)}}return{sorted:s,recipientMap:r}}function XB(e){let t;if(1===e.sourceLayer.inboundNodes.length)t=e.sourceLayer.output;else{let n=null;for(let t=0;t<e.sourceLayer.inboundNodes.length;++t)for(const s of e.sourceLayer.inboundNodes[t].outputTensors)if(s.id===e.id){n=t;break}t=e.sourceLayer.getOutputAt(n)}return t}
|
|
16030
16030
|
/**
|
|
16031
16031
|
* @license
|
|
16032
16032
|
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
@@ -16135,7 +16135,7 @@ const OW=1048576;function LW(e,t,n=!1){if(null==e||"object"!=typeof e||Object.ge
|
|
|
16135
16135
|
* https://opensource.org/licenses/MIT.
|
|
16136
16136
|
* =============================================================================
|
|
16137
16137
|
*/function VW(e,t,n){return("inboundNodes"===e||"outputLayers"===e||"inputLayers"===e)&&0===t&&"string"==typeof n}function GW(e,t){if(null===e)return null;if("string"==typeof e)return tz(e);if("number"==typeof e||"boolean"==typeof e)return e;if(e instanceof Array){const n=[],s=e.length;for(let r=0;r<s;++r){const s=e[r];VW(t,r,s)?n.push(s):n.push(GW(s,t))}return n}{const t={};for(const n of Object.keys(e)){const s=e[n];if("name"===n&&"string"==typeof s)t[n]=s;else{const e=tz(n);t[e]=GW(s,e)}}return t}}function HW(e,t){if(null==e)return null;if("string"==typeof e)return ez(e);if("number"==typeof e||"boolean"==typeof e)return e;if(e instanceof Array){const n=[],s=e.length;for(let r=0;r<s;++r){const s=e[r];VW(t,r,s)?n.push(s):n.push(HW(s,t))}return n}{const t={};for(const n of Object.keys(e)){const s=e[n],r=ez(n);t[r]="name"!==n&&"className"!==n||"string"!=typeof s?HW(s,n):s}return t}}
|
|
16138
|
-
/** @license See the LICENSE file. */const qW="4.
|
|
16138
|
+
/** @license See the LICENSE file. */const qW="4.19.0";
|
|
16139
16139
|
/**
|
|
16140
16140
|
* @license
|
|
16141
16141
|
* Copyright 2018 Google LLC
|
|
@@ -16153,7 +16153,7 @@ const OW=1048576;function LW(e,t,n=!1){if(null==e||"object"!=typeof e||Object.ge
|
|
|
16153
16153
|
* license that can be found in the LICENSE file or at
|
|
16154
16154
|
* https://opensource.org/licenses/MIT.
|
|
16155
16155
|
* =============================================================================
|
|
16156
|
-
*/function XW(e,t){return function(e,t,n){const s=t.length;if(null==e||Array.isArray(e)&&0===e.length)return t.map((e=>null));if(1===s)return Array.isArray(e)&&1===e.length?e:"object"==typeof e&&t[0]in e?[e[t[0]]]:[e];if(Array.isArray(e)){if(e.length!==s)throw new Error(`Provided ${n} is an array of ${e.length} element(s), but the model has ${s} outputs. Make sure a set of weights is provided for each model output.`);return e}if("object"==typeof e&&Object.keys(e).length>0&&"object"==typeof e[Object.keys(e)[0]]){const n=[];return t.forEach((t=>{t in e?n.push(e[t]):n.push(null)})),n}throw new Error(`The model has multiple (${s}) outputs, so ${n} must be either an array with ${s} elements or an object with ${t} keys. Provided ${n} not understood: ${JSON.stringify(e)}`)}(e,t,"classWeight")}async function KW(e,t,n,s){if(null!=
|
|
16156
|
+
*/function XW(e,t){return function(e,t,n){const s=t.length;if(null==e||Array.isArray(e)&&0===e.length)return t.map((e=>null));if(1===s)return Array.isArray(e)&&1===e.length?e:"object"==typeof e&&t[0]in e?[e[t[0]]]:[e];if(Array.isArray(e)){if(e.length!==s)throw new Error(`Provided ${n} is an array of ${e.length} element(s), but the model has ${s} outputs. Make sure a set of weights is provided for each model output.`);return e}if("object"==typeof e&&Object.keys(e).length>0&&"object"==typeof e[Object.keys(e)[0]]){const n=[];return t.forEach((t=>{t in e?n.push(e[t]):n.push(null)})),n}throw new Error(`The model has multiple (${s}) outputs, so ${n} must be either an array with ${s} elements or an object with ${t} keys. Provided ${n} not understood: ${JSON.stringify(e)}`)}(e,t,"classWeight")}async function KW(e,t,n,s){if(null!=n){const t=bi((()=>{if(1===e.shape.length)return Io(e);if(2===e.shape.length){if(e.shape[1]>1){return Mo(e,1)}if(1===e.shape[1])return su(e,[e.shape[0]]);throw new Error(`Encountered unexpected last-dimension size (${e.shape[1]}) during handling of class weights. The size is expected to be >= 1.`)}throw new Error(`Unexpected rank of target (y) tensor (${e.rank}) during handling of class weights. The rank is expected to be 1 or 2.`)})),s=Array.from(await t.data());xi(t);const r=[];return s.forEach((e=>{if(null==n[e])throw new Error(`classWeight must contain all classes in the training data. The class ${e} exists in the data but not in classWeight`);r.push(n[e])})),Ph(r,"float32")}return null}function YW(e,t){return $o(e,t)}
|
|
16157
16157
|
/**
|
|
16158
16158
|
* @license
|
|
16159
16159
|
* Copyright 2018 Google LLC
|
|
@@ -16162,7 +16162,7 @@ const OW=1048576;function LW(e,t,n=!1){if(null==e||"object"!=typeof e||Object.ge
|
|
|
16162
16162
|
* license that can be found in the LICENSE file or at
|
|
16163
16163
|
* https://opensource.org/licenses/MIT.
|
|
16164
16164
|
* =============================================================================
|
|
16165
|
-
*/function QW(e,t){let n,s;const r=t;n=r.xs,s=r.ys,me(null!=n&&null!=s,(()=>`A Dataset iterator for fitDataset() is expected to generate objects of the form \`{xs: xVal, ys: yVal}\`, where the two values may be \`tf.Tensor\`, an array of Tensors, or a map of string to Tensor. The provided Dataset instead generates ${t}`));const a=JW("input",e.inputNames,n),i=JW("output",e.outputNames,s),o=a[0].shape[0];me(a.length===e.inputs.length,(()=>`LayersModel has ${e.inputs.length} inputs, but the dataset provides ${a.length} inputs. (Expected input keys: ${JSON.stringify(e.inputNames)})`)),me(i.length===e.outputs.length,(()=>`LayersModel has ${e.outputs.length} outputs, but the dataset provides ${i.length} outputs. (Expected output keys: ${JSON.stringify(e.outputNames)})`));for(let t=0;t<a.length;t++)me(a[t].shape[0]===o,(()=>`Batch size mismatch: input ${e.inputNames[t]} has ${a[t].shape[0]}; expected ${o} based on input ${e.inputNames[0]}.`));for(let t=0;t<i.length;t++)me(i[t].shape[0]===o,(()=>`Batch size mismatch: output ${e.outputNames[t]} has ${i[t].shape[0]}; expected ${o} based on input ${e.inputNames[0]}.`));return{xs:a,ys:i}}function JW(e,t,n){if(n instanceof _a)return[n];if(Array.isArray(n))return me(n.length===t.length,(()=>`Received an array of ${n.length} Tensors, but expected ${t.length} to match the ${e} keys ${t}.`)),n;{const s=[];for(const r of t){if(null==n[r])throw new HP(`The feature data generated by the dataset lacks the required ${e} key '${r}'.`);s.push(n[r])}return s}}async function ZW(e,t,n){const s=null!=n.batchesPerEpoch;if(me(null!=e.optimizer,(()=>"You must compile a model before training/testing. Use LayersModel.compile(modelCompileConfig).")),me(null!=n,(()=>"For fitDataset(), the 2nd argument (config) is required, but it is not provided in this call.")),me(null!=n.epochs&&n.epochs>0&&Number.isInteger(n.epochs),(()=>`For fitDataset(), config.epochs is expected to be a positive integer, but got ${n.epochs}`)),me(!s||n.batchesPerEpoch>0&&Number.isInteger(n.batchesPerEpoch),(()=>`For fitDataset(), config.batchesPerEpoch is expected to be a positive integer if specified, but got ${n.batchesPerEpoch}`)),me(null==n.validationSplit,(()=>"`validationSplit` is not supported by `fitDataset()`. Use validationData instead.")),e.isTraining)throw new Error("Cannot start training because another fit() call is ongoing.");e.isTraining=!0;try{const r=null!=n.validationData;let a,i;if(r)if(eU(n.validationData))me(null==n.validationBatches||n.validationBatches>0&&Number.isInteger(n.validationBatches),(()=>`For fitDataset() with dataset-based validation, config.validationBatches is expected not to be provided, or to be a positive integer, but got ${n.validationBatches}`));else{const e=function(e){if(3===e.length)throw new qP("Validation with sample weights is not implemented yet.");return{xs:e[0],ys:e[1]}}(n.validationData);a=e.xs,i=e.ys}const o=e.makeTrainFunction(),u=e.getDedupedMetricsNames();let l;l=r?u.slice().concat(u.map((e=>"val_"+e))):u.slice();const c=pW(n.callbacks,n.yieldEvery),h=null==n.verbose?1:n.verbose,{callbackList:d,history:p}=mW(c,h,n.epochs,null,null,function(e,t){let n=null;null!=t.batchesPerEpoch?n=t.batchesPerEpoch:Number.isFinite(e.size)&&(n=e.size);return n}(t,n),null,r,l);d.setModel(e),e.history=p,await d.onTrainBegin(),e.stopTraining_=!1;let f=null==n.initialEpoch?0:n.initialEpoch,m=await t.iterator();for(;f<n.epochs;){const l={};await d.onEpochBegin(f);let c=0,h=0;for(s||(m=await t.iterator());!s||c<n.batchesPerEpoch;){const t=await m.next();if(s&&t.done){console.warn(`You provided \`batchesPerEpoch\` as ${n.batchesPerEpoch}, but your dataset iterator ran out of data after ${c} batches; interrupting training. Make sure that your dataset can generate at least \`batchesPerEpoch * epochs\` batches (in this case, `+n.batchesPerEpoch*n.epochs+" batches). You may need to use the repeat() function when building your dataset.");break}if(null!=t.value){const{xs:s,ys:r}=QW(e,t.value),a={};a.batch=h,a.size=s[0].shape[0],await d.onBatchBegin(h,a);const i=[];if(null!=n.classWeight){const t=XW(n.classWeight,e.outputNames);for(let e=0;e<t.length;++e)i.push(await KW(r[e],
|
|
16165
|
+
*/function QW(e,t){let n,s;const r=t;n=r.xs,s=r.ys,me(null!=n&&null!=s,(()=>`A Dataset iterator for fitDataset() is expected to generate objects of the form \`{xs: xVal, ys: yVal}\`, where the two values may be \`tf.Tensor\`, an array of Tensors, or a map of string to Tensor. The provided Dataset instead generates ${t}`));const a=JW("input",e.inputNames,n),i=JW("output",e.outputNames,s),o=a[0].shape[0];me(a.length===e.inputs.length,(()=>`LayersModel has ${e.inputs.length} inputs, but the dataset provides ${a.length} inputs. (Expected input keys: ${JSON.stringify(e.inputNames)})`)),me(i.length===e.outputs.length,(()=>`LayersModel has ${e.outputs.length} outputs, but the dataset provides ${i.length} outputs. (Expected output keys: ${JSON.stringify(e.outputNames)})`));for(let t=0;t<a.length;t++)me(a[t].shape[0]===o,(()=>`Batch size mismatch: input ${e.inputNames[t]} has ${a[t].shape[0]}; expected ${o} based on input ${e.inputNames[0]}.`));for(let t=0;t<i.length;t++)me(i[t].shape[0]===o,(()=>`Batch size mismatch: output ${e.outputNames[t]} has ${i[t].shape[0]}; expected ${o} based on input ${e.inputNames[0]}.`));return{xs:a,ys:i}}function JW(e,t,n){if(n instanceof _a)return[n];if(Array.isArray(n))return me(n.length===t.length,(()=>`Received an array of ${n.length} Tensors, but expected ${t.length} to match the ${e} keys ${t}.`)),n;{const s=[];for(const r of t){if(null==n[r])throw new HP(`The feature data generated by the dataset lacks the required ${e} key '${r}'.`);s.push(n[r])}return s}}async function ZW(e,t,n){const s=null!=n.batchesPerEpoch;if(me(null!=e.optimizer,(()=>"You must compile a model before training/testing. Use LayersModel.compile(modelCompileConfig).")),me(null!=n,(()=>"For fitDataset(), the 2nd argument (config) is required, but it is not provided in this call.")),me(null!=n.epochs&&n.epochs>0&&Number.isInteger(n.epochs),(()=>`For fitDataset(), config.epochs is expected to be a positive integer, but got ${n.epochs}`)),me(!s||n.batchesPerEpoch>0&&Number.isInteger(n.batchesPerEpoch),(()=>`For fitDataset(), config.batchesPerEpoch is expected to be a positive integer if specified, but got ${n.batchesPerEpoch}`)),me(null==n.validationSplit,(()=>"`validationSplit` is not supported by `fitDataset()`. Use validationData instead.")),e.isTraining)throw new Error("Cannot start training because another fit() call is ongoing.");e.isTraining=!0;try{const r=null!=n.validationData;let a,i;if(r)if(eU(n.validationData))me(null==n.validationBatches||n.validationBatches>0&&Number.isInteger(n.validationBatches),(()=>`For fitDataset() with dataset-based validation, config.validationBatches is expected not to be provided, or to be a positive integer, but got ${n.validationBatches}`));else{const e=function(e){if(3===e.length)throw new qP("Validation with sample weights is not implemented yet.");return{xs:e[0],ys:e[1]}}(n.validationData);a=e.xs,i=e.ys}const o=e.makeTrainFunction(),u=e.getDedupedMetricsNames();let l;l=r?u.slice().concat(u.map((e=>"val_"+e))):u.slice();const c=pW(n.callbacks,n.yieldEvery),h=null==n.verbose?1:n.verbose,{callbackList:d,history:p}=mW(c,h,n.epochs,null,null,function(e,t){let n=null;null!=t.batchesPerEpoch?n=t.batchesPerEpoch:Number.isFinite(e.size)&&(n=e.size);return n}(t,n),null,r,l);d.setModel(e),e.history=p,await d.onTrainBegin(),e.stopTraining_=!1;let f=null==n.initialEpoch?0:n.initialEpoch,m=await t.iterator();for(;f<n.epochs;){const l={};await d.onEpochBegin(f);let c=0,h=0;for(s||(m=await t.iterator());!s||c<n.batchesPerEpoch;){const t=await m.next();if(s&&t.done){console.warn(`You provided \`batchesPerEpoch\` as ${n.batchesPerEpoch}, but your dataset iterator ran out of data after ${c} batches; interrupting training. Make sure that your dataset can generate at least \`batchesPerEpoch * epochs\` batches (in this case, `+n.batchesPerEpoch*n.epochs+" batches). You may need to use the repeat() function when building your dataset.");break}if(null!=t.value){const{xs:s,ys:r}=QW(e,t.value),a={};a.batch=h,a.size=s[0].shape[0],await d.onBatchBegin(h,a);const i=[];if(null!=n.classWeight){const t=XW(n.classWeight,e.outputNames);for(let e=0;e<t.length;++e)i.push(await KW(r[e],0,t[e]))}const l=s.concat(r).concat(i),p=o(l);xi(l);for(let e=0;e<u.length;++e){const t=u[e],n=p[e];a[t]=n,wi(n)}await d.onBatchEnd(h,a),iW(a),h++,c++}if(s?c>=n.batchesPerEpoch:t.done){if(r){let t;t=eU(n.validationData)?ZP(await e.evaluateDataset(n.validationData,{batches:n.validationBatches})):ZP(e.evaluate(a,i,{batchSize:null==n.validationBatchSize?32:n.validationBatchSize,verbose:0}));for(let n=0;n<e.metricsNames.length;++n)l[`val_${e.metricsNames[n]}`]=t[n]}break}if(e.stopTraining_)break}if(await d.onEpochEnd(f,l),f++,e.stopTraining_)break}return await d.onTrainEnd(),await e.history.syncData(),e.history}finally{e.isTraining=!1}}function eU(e){return"function"==typeof e.iterator}
|
|
16166
16166
|
/**
|
|
16167
16167
|
* @license
|
|
16168
16168
|
* Copyright 2018 Google LLC
|
|
@@ -16181,7 +16181,7 @@ function tU(e){me(e>0&&Number.isInteger(e),(()=>`batchSize is required to be a p
|
|
|
16181
16181
|
* license that can be found in the LICENSE file or at
|
|
16182
16182
|
* https://opensource.org/licenses/MIT.
|
|
16183
16183
|
* =============================================================================
|
|
16184
|
-
*/function oU(e){return Array.isArray(e)}function uU(e){return!function(e){return e instanceof _a}(e)&&!oU(e)}function lU(e,t,n,s=!0,r=""){if(null==t||0===t.length){if(null!=e){let t=!1;if(oU(e)&&e.length>0)t=!0;else if(uU(e)){for(const n in e)if(e.hasOwnProperty(n)){t=!0;break}}else t=!0;if(t)throw new HP(`Error when checking model ${r} expected no data, but got ${e}`)}return[]}if(null==e)return t.map((e=>null));let a;if(uU(e)){a=[];for(const n of t){if(null==e[n])throw new HP(`No data provided for "${n}". Need data for each key in: ${t}`);a.push(e[n])}}else if(oU(e)){if(e.length!==t.length)throw new HP(`Error when checking model ${r}: the Array of Tensors that you are passing to your model is not the size the model expected. Expected to see ${t.length} Tensor(s), but instead got the following list of Tensor(s): ${e}`);a=e}else{if(t.length>1)throw new HP(`The model ${r} expects ${t.length} Tensor(s), but only received one Tensor. Found: Tensor with shape ${e.shape}`);a=[e]}if(a=aU(a),null!=n)for(let e=0;e<t.length;++e){if(null==n[e])continue;const i=a[e];if(i.shape.length!==n[e].length)throw new HP(`Error when checking ${r}: expected ${t[e]} to have ${n[e].length} dimension(s). but got array with shape ${i.shape}`);for(let t=0;t<n[e].length;++t){if(0===t&&!s)continue;const a=i.shape[t],o=n[e][t];if(null!=o&&o>=0&&a!==o)throw new HP(`${r} expected a batch of elements where each example has shape [${n[e].slice(1,n[e].length)}] (i.e.,tensor shape [*,${n[e].slice(1,n[e].length)}]) but the ${r} received an input with ${i.shape[0]} examples, each with shape [${i.shape.slice(1,i.shape.length)}] (tensor shape [${i.shape}])`)}}return a}function cU(e,t,n,s=!0,r=""){let a;if(Array.isArray(e)){if(e.length!==t.length)throw new HP(`Error when checking model ${r}: the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see ${t.length} Tensor(s), but instead got ${e.length} Tensors(s).`);a=e}else{if(t.length>1)throw new HP(`The model expects ${t.length} ${r} Tensors, but only received one Tensor. Found: array with shape ${JSON.stringify(e.shape)}.`);a=[e]}if(null!=n)for(let e=0;e<t.length;++e){if(null==n[e])continue;const i=a[e];if(i.shape.length!==n[e].length)throw new HP(`Error when checking ${r}: expected ${t[e]} to have ${n[e].length} dimension(s), but got array with shape ${JSON.stringify(i.shape)}`);for(let a=0;a<n[e].length;++a){if(0===a&&!s)continue;const o=i.shape[a],u=n[e][a];if(null!=u&&u!==o)throw new HP(`Error when checking ${r}: expected ${t[e]} to have shape ${JSON.stringify(n[e])} but got array with shape ${JSON.stringify(i.shape)}.`)}}}class hU extends jW{constructor(e){super(e),this.isTraining=!1}summary(e,t,n=console.log){if(!this.built)throw new HP("This model has never been called, thus its weights have not been created yet. So no summary can be displayed. Build the model first (e.g., by calling it on some test data).");zW(this,e,t,n)}compile(e){if(null==e.loss&&(e.loss=[]),this.loss=e.loss,"string"==typeof e.optimizer)this.optimizer_=function(e){const t={Adagrad:()=>bf.adagrad(.01),Adadelta:()=>bf.adadelta(1,.95,Bz()),Adam:()=>bf.adam(.001,.9,.999,Bz()),Adamax:()=>bf.adamax(.002,.9,.999,Bz(),0),RMSProp:()=>bf.rmsprop(.001,.9,0,Bz()),SGD:()=>bf.sgd(.01)};if(t.adagrad=t.Adagrad,t.adadelta=t.Adadelta,t.adam=t.Adam,t.adamax=t.Adamax,t.rmsprop=t.RMSProp,t.sgd=t.SGD,e in t)return t[e]();throw new HP(`Unknown Optimizer ${e}`)}(e.optimizer),this.isOptimizerOwned=!0;else{if(!(e.optimizer instanceof Np))throw new HP("User-defined optimizer must be an instance of tf.Optimizer.");this.optimizer_=e.optimizer,this.isOptimizerOwned=!1}let t=[];if(Array.isArray(e.loss)||"string"==typeof e.loss||"function"==typeof e.loss)if(Array.isArray(e.loss)){if(e.loss.length!==this.outputs.length)throw new HP(`When passing an Array as loss, it should have one entry per model output. The model has ${this.outputs.length} output(s), but you passed loss=${e.loss}.`);const n=e.loss;t=n.map((e=>NW(e)))}else{const n=NW(e.loss);this.outputs.forEach((e=>{t.push(n)}))}else{e.loss=e.loss;for(const t in e.loss)if(-1===this.outputNames.indexOf(t))throw new HP(`Unknown entry in loss dictionary: "${t}". Only expected the following keys: ${this.outputNames}`);for(const n of this.outputNames)null==e.loss[n]&&console.warn(`Output "${n}" is missing from loss dictionary. We assume this was done on purpose, and we will not be expecting data to be passed to ${n} during training`),t.push(NW(e.loss[n]))}this.lossFunctions=t,this.feedOutputNames=[],this.feedOutputShapes=[],this.feedLossFns=[];for(let e=0;e<this.outputs.length;++e){const t=this.internalOutputShapes[e],n=this.outputNames[e];this.feedOutputNames.push(n),this.feedOutputShapes.push(t),this.feedLossFns.push(this.lossFunctions[e])}const n=[];this.metrics=e.metrics,this.metricsNames=["loss"],this.metricsTensors=[],Rz("loss",(()=>{for(let e=0;e<this.outputs.length;++e){if(-1!==n.indexOf(e))continue;const t=this.lossFunctions[e];this.outputs.length>1&&(this.metricsTensors.push([t,e]),this.metricsNames.push(this.outputNames[e]+"_loss"))}}));const s=function(e,t){if(null==e||Array.isArray(e)&&0===e.length)return t.map((e=>[]));let n;if("string"==typeof e||"function"==typeof e)n=[e];else{if(!Array.isArray(e)&&"object"!=typeof e)throw new TypeError(`Type of metrics argument not understood. Expected an string,function, Array, or Object, found: ${e}`);n=e}if(Array.isArray(n))return t.map((e=>n));{const e=[];for(const s of t){let t=n.hasOwnProperty(s)?n[s]:[];Array.isArray(t)||(t=[t]),e.push(t)}return e}}(e.metrics,this.outputNames),r=(e,t,n)=>{this.outputNames.length>1&&(t=this.outputNames[e]+"_"+t),this.metricsNames.push(t),this.metricsTensors.push([n,e])};Rz("metric",(()=>{for(let e=0;e<this.outputs.length;++e){if(-1!==n.indexOf(e))continue;(t=>{let n,s,a;for(const i of t){if("string"==typeof i&&-1!==["accuracy","acc","crossentropy","ce"].indexOf(i)){const t=this.internalOutputShapes[e];let r;1===t[t.length-1]||this.lossFunctions[e]===IW?-1!==["accuracy","acc"].indexOf(i)?s=TW:-1!==["crossentropy","ce"].indexOf(i)&&(s=RW):this.lossFunctions[e]===vW?-1!==["accuracy","acc"].indexOf(i)?s=EW:-1!==["crossentropy","ce"].indexOf(i)&&(s=_W):-1!==["accuracy","acc"].indexOf(i)?s=$W:-1!==["crossentropy","ce"].indexOf(i)&&(s=AW),-1!==["accuracy","acc"].indexOf(i)?r="acc":-1!==["crossentropy","ce"].indexOf(i)&&(r="ce"),a=s,n=""+r}else{const e=DW(i);a=e,n=""+MW(i)}let t;Rz(n,(()=>{t=a})),r(e,n,t)}})(s[e])}})),this.collectedTrainableWeights=this.trainableWeights}checkTrainableWeightsConsistency(){null!=this.collectedTrainableWeights&&this.trainableWeights.length!==this.collectedTrainableWeights.length&&console.warn("Discrepancy between trainableweights and collected trainable weights. Did you set `model.trainable` without calling `model.compile()` afterwards?")}evaluate(e,t,n={}){const s=null==n.batchSize?32:n.batchSize;tU(s);const r=this.standardizeUserDataXY(e,t,!0,s);try{const e=r[0].concat(r[1]);this.makeTestFunction();const t=this.testFunction;return JP(this.testLoop(t,e,s,n.verbose,n.steps))}finally{iU(r[0],e),iU(r[1],t)}}async evaluateDataset(e,t){return this.makeTestFunction(),async function(e,t,n){const s=null!=(n=n||{}).batches,r=e.testFunction;let a=[];if(n.verbose>0)throw new qP("Verbose mode is not implemented yet.");me(!s||n.batches>0&&Number.isInteger(n.batches),(()=>`Test loop expects \`batches\` to be a positive integer, but received ${JSON.stringify(n.batches)}`));const i="function"==typeof t.next?t:await t.iterator();let o=0,u=0;for(;!s||u<n.batches;){const t=await i.next();if(a=bi((()=>{if(t.value){const{xs:n,ys:s}=QW(e,t.value),i=n.concat(s),l=bi((()=>r(i)));if(xi(i),0===u)for(let e=0;e<l.length;++e)a.push(pl(0));const c=i[0].shape[0];for(let e=0;e<l.length;++e){const t=l[e],n=a[e];a[e]=bi((()=>Co(a[e],$o(c,t)))),u>0&&xi(n)}xi(l),o+=c,++u}return a})),t.done){s&&console.warn(`Your dataset iterator ran out of data during evaluateDataset(). Interrupting evalution. Make sure that your dataset can generate at least \`batches\` batches (in this case, ${n.batches} batches). You may need to use the repeat() function when building your dataset.`);break}}for(let e=0;e<a.length;++e){const t=a[e];a[e]=To(a[e],o),xi(t)}return JP(a)}(this,e,t)}checkNumSamples(e,t,n,s="steps"){let r;if(null!=n){if(r=null,null!=t)throw new HP(`If ${s} is set, batchSize must be null or undefined.Got batchSize = ${t}`)}else{if(null==e)throw new HP(`Either the input data should have a defined shape, or ${s} shoud be specified.`);r=Array.isArray(e)?e[0].shape[0]:e.shape[0]}return r}execute(e,t){if(Array.isArray(t)&&0===t.length)throw new HP("`outputs` is an empty Array, which is not allowed.");const n=Array.isArray(t),s=n?t:[t],r=this.retrieveSymbolicTensors(s),a=new UB;if(e instanceof _a&&(e=[e]),Array.isArray(e)){if(e.length!==this.inputs.length)throw new HP(`The number of inputs provided (${e.length}) does not match the number of inputs of this model (${this.inputs.length}).`);for(let t=0;t<this.inputs.length;++t)a.add(this.inputs[t],e[t])}else for(const t of this.inputs){const n=e[t.name];if(null==n)throw new HP(`No value is provided for the model's input ${t.name}`);a.add(t,n)}const i=HB(r,a);return n?i:i[0]}retrieveSymbolicTensors(e){const t=KP(null,e.length);let n=e.length;for(const s of this.layers){const r=Array.isArray(s.output)?s.output:[s.output],a=r.map((e=>e.name));for(let s=0;s<e.length;++s){const i=a.indexOf(e[s]);if(-1!==i&&(t[s]=r[i],n--),0===n)break}if(0===n)break}if(n>0){const n=[];throw t.forEach(((t,s)=>{null==t&&n.push(e[s])})),new HP(`Cannot find SymbolicTensors for output name(s): ${JSON.stringify(n)}`)}return t}predictLoop(e,t=32,n=!1){return bi((()=>{const s=this.checkNumSamples(e);if(n)throw new qP("Verbose predictLoop() is not implemented yet.");const r=rU(s,t),a=this.outputs.map((e=>[]));for(let t=0;t<r.length;++t){const n=bi((()=>{const n=r[t][0],s=r[t][1],a=nU(e,n,s),i=[];if(Array.isArray(a))for(let e=0;e<a.length;++e)i.push({key:this.inputs[e],value:a[e]});else i.push({key:this.inputs[0],value:a});const o=new UB(i);return HB(this.outputs,o)}));n.forEach(((e,t)=>a[t].push(e)))}return JP(a.map((e=>iu(e,0))))}))}predict(e,t={}){const n=aU(e);cU(n,this.inputNames,this.feedInputShapes,!1);try{const e=null==t.batchSize?32:t.batchSize;return tU(e),this.predictLoop(n,e)}finally{iU(n,e)}}predictOnBatch(e){cU(e,this.inputNames,this.feedInputShapes,!0);const t=(Array.isArray(e)?e[0]:e).shape[0];return this.predictLoop(e,t)}standardizeUserDataXY(e,t,n=!0,s){if(null==this.optimizer_)throw new GP("You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).");const r=[];for(let e=0;e<this.feedOutputShapes.length;++e){const t=this.feedOutputShapes[e];this.feedLossFns[e]===vW?r.push(t.slice(0,t.length-1).concat([1])):r.push(t)}if(function(e,t,n){const s=oz(e.map((e=>e.shape[0])));s.sort();const r=oz(t.map((e=>e.shape[0])));if(r.sort(),s.length>1)throw new HP(`All input Tensors (x) should have the same number of samples. Got array shapes: ${JSON.stringify(e.map((e=>e.shape)))}`);if(r.length>1)throw new HP(`All target Tensors (y) should have the same number of samples. Got array shapes: ${JSON.stringify(t.map((e=>e.shape)))}`);if(s.length>0&&r.length>0&&!we(s,r))throw new HP(`Input Tensors should have the same number of samples as target Tensors. Found ${s[0]} input sample(s) and ${r[0]} target sample(s).`)}(e=lU(e,this.feedInputNames,this.feedInputShapes,!1,"input"),t=lU(t,this.feedOutputNames,r,!1,"target")),function(e,t,n){const s=[bW,IW,kW];for(let r=0;r<e.length;++r){const a=e[r],i=t[r],o=n[r];if(null!=i){if(i===kW&&1===a.shape[a.shape.length-1])throw new HP(`You are passing a target array of shape ${a.shape} while using a loss 'categorical_crossentropy'. 'categorical_crossentropy'expects targets to be binary matrices (1s and 0s) of shape [samples, classes].`);if(-1!==s.indexOf(i)){const e=a.shape.slice(1),t=o.slice(1);for(let n=0;n<e.length;++n){const s=e[n],r=t[n];if(null!=r&&s!==r)throw new HP(`A target Tensor with shape ${a.shape} was passed for an output of shape ${o}, while using a loss function that expects targets to have the same shape as the output.`)}}}}}(t,this.feedLossFns,this.feedOutputShapes),this.stateful&&null!=s&&s>0&&e[0].shape[0]%s!=0)throw new HP(`In a stateful network, you should only pass inputs with a number of samples that is divisible by the batch size ${s}. Found: ${e[0].shape[0]} sample(s).`);return[e,t]}async standardizeUserData(e,t,n,s,r=!0,a){const[i,o]=this.standardizeUserDataXY(e,t,r,a);if(null!=n)throw new Error("sample weight is not supported yet.");let u=null;if(null!=s){const e=XW(s,this.outputNames);u=[];for(let t=0;t<e.length;++t)u.push(await KW(o[t],null,e[t]))}return[i,o,u]}testLoop(e,t,n,s=0,r){return bi((()=>{const a=this.checkNumSamples(t,n,r,"steps"),i=[];if(s>0)throw new qP("Verbose mode is not implemented yet.");if(null!=r)throw new qP("steps mode in testLoop() is not implemented yet");{const s=rU(a,n),r=Ph(Pz(0,a));for(let n=0;n<s.length;++n){const a=s[n][0],o=s[n][1],u=Vz(r,a,o-a),l=sU(t,u),c=e(l);if(0===n)for(let e=0;e<c.length;++e)i.push(pl(0));for(let e=0;e<c.length;++e){const t=c[e];i[e]=Co(i[e],$o(o-a,t))}}for(let e=0;e<i.length;++e)i[e]=To(i[e],a)}return i}))}getDedupedMetricsNames(){const e=this.metricsNames,t=[];for(let n=0;n<e.length;++n){const s=e[n];let r=s;if(QP(e,s)>1){r+=`_${QP(e.slice(0,n),s)}`}t.push(r)}return t}makeTrainFunction(){return e=>{const t=[],n=e.slice(0,this.inputs.length),s=e.slice(this.inputs.length,this.inputs.length+this.outputs.length),r=e.slice(this.inputs.length+this.outputs.length,this.inputs.length+2*this.outputs.length),a=[],i=this.collectedTrainableWeights.map((e=>e.read())),o=this.optimizer_.minimize((()=>{const e=[];for(let t=0;t<this.inputs.length;++t)e.push({key:this.inputs[t],value:n[t]});const i=new UB(e),o=HB(this.outputs,i,{training:!0});let u;for(let e=0;e<this.lossFunctions.length;++e){let n=(0,this.lossFunctions[e])(s[e],o[e]);null!=r[e]&&(n=YW(n,r[e]));const a=nc(n);t.push(a),u=0===e?n:Co(u,n)}for(let e=0;e<this.metricsTensors.length;++e){let n;if(this.outputs.length>1&&e<this.outputs.length)n=t[e];else{const t=this.metricsTensors[e][0],r=this.metricsTensors[e][1];n=nc(t(s[r],o[r]))}wi(n),a.push(n)}return u=nc(u),this.calculateLosses().forEach((e=>{u=Co(u,e)})),u}),!0,i);return[o].concat(a)}}makeTestFunction(){this.testFunction=e=>bi((()=>{const t=[];let n;const s=e.slice(0,this.inputs.length),r=e.slice(this.inputs.length,this.inputs.length+this.outputs.length),a=[];for(let e=0;e<this.inputs.length;++e)a.push({key:this.inputs[e],value:s[e]});const i=new UB(a),o=HB(this.outputs,i);for(let e=0;e<this.lossFunctions.length;++e){const s=this.lossFunctions[e],a=nc(s(r[e],o[e]));n=0===e?a:Co(n,a),t.push(n)}for(let e=0;e<this.metricsTensors.length;++e){const n=this.metricsTensors[e][0],s=this.metricsTensors[e][1],a=nc(n(r[s],o[s]));t.push(a)}return t}))}async fit(e,t,n={}){if(this.isTraining)throw new Error("Cannot start training because another fit() call is ongoing.");let s,r,a,i,o,u,l,c,h;this.isTraining=!0;try{const d=null==n.batchSize?32:n.batchSize;tU(d);const p=!1,f=await this.standardizeUserData(e,t,n.sampleWeight,n.classWeight,p,d);s=f[0],r=f[1],h=f[2];let m,g=!1;if(null!=n.validationData&&n.validationData.length>0){if(g=!0,2!==n.validationData.length)throw 3===n.validationData.length?new qP("validationData including sample weights is not supported yet."):new HP(`When passing validation data, it must contain 2 (valX, valY) or 3 (valX, valY, valSampleWeight) items; ${n.validationData} is invalid.`);o=n.validationData[0],u=n.validationData[1];const e=!0,t=await this.standardizeUserData(o,u,null,null,e,d);l=t[0],c=t[1],m=l.concat(c)}else if(null!=n.validationSplit&&n.validationSplit>0&&n.validationSplit<1){g=!0;const e=Math.floor(s[0].shape[0]*(1-n.validationSplit)),t=s[0].shape[0];l=nU(s,e,t),a=s,s=nU(s,0,e),c=nU(r,e,t),i=r,r=nU(r,0,e),m=l.concat(c)}else null!=n.validationSteps&&(g=!0);const y=s.concat(r).concat(h);this.checkTrainableWeightsConsistency();const b=this.makeTrainFunction(),x=this.getDedupedMetricsNames();let w,k;g?(this.makeTestFunction(),w=this.testFunction,k=x.slice().concat(x.map((e=>"val_"+e)))):(w=null,m=[],k=x.slice());const v=pW(n.callbacks,n.yieldEvery);return await this.fitLoop(b,y,x,d,n.epochs,n.verbose,v,w,m,n.shuffle,k,n.initialEpoch,null,null)}finally{this.isTraining=!1,iU(s,e),iU(r,t),iU(a,e),iU(i,t),iU(l,o),iU(c,u),null!=h&&xi(h)}}async fitLoop(e,t,n,s,r,a,i,o,u,l,c,h,d,p){null==s&&(s=32),null==r&&(r=1),null==l&&(l=!0),null==h&&(h=0);let f=!1;if(null!=o&&null!=u&&(f=!0),null!=p&&(f=!0,null==d))throw new HP("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set.");const m=this.checkNumSamples(t,s,d,"steps_per_epoch");let g;null!=m&&(g=Pz(0,m)),null==a&&(a=1);const{callbackList:y,history:b}=mW(i,a,r,h,m,d,s,f,c);y.setModel(this),this.history=b,await y.onTrainBegin(),this.stopTraining_=!1;for(let a=h;a<r;++a){await y.onEpochBegin(a);const r={};if(null!=d)throw new qP("stepsPerEpoch mode is not implemented yet.");{if("batch"===l)throw new qP("batch shuffling is not implemneted yet");l&&ce(g);const a=Ph(g),i=rU(m,s);for(let l=0;l<i.length;++l){const c={};if(await y.onBatchBegin(l,c),bi((()=>{const h=i[l][0],d=i[l][1],p=Vz(a,h,d-h);c.batch=l,c.size=d-h;const m=sU(t,p),g=e(m);for(let e=0;e<n.length;++e){const t=n[e],s=g[e];c[t]=s,wi(s)}if(l===i.length-1&&f){const e=this.testLoop(o,u,s);for(let t=0;t<n.length;++t){const s=n[t],a=e[t];wi(a),r["val_"+s]=a}}})),await y.onBatchEnd(l,c),iW(c),this.stopTraining_)break}a.dispose()}if(await y.onEpochEnd(a,r),this.stopTraining_)break}return await y.onTrainEnd(),await this.history.syncData(),this.history}async fitDataset(e,t){return ZW(this,e,t)}async trainOnBatch(e,t){const n=await this.standardizeUserData(e,t),s=n[0],r=n[1],a=this.makeTrainFunction()(s.concat(r)),i=[];for(const e of a){const t=await e.data();i.push(t[0])}return xi(a),iU(n[0],e),iU(n[1],t),JP(i)}getNamedWeights(e){const t=[],n=null!=e&&e.trainableOnly,s=n?this.trainableWeights:this.weights,r=this.getWeights(n);for(let e=0;e<s.length;++e)n&&!s[e].trainable||t.push({name:s[e].originalName,tensor:r[e]});return t}set stopTraining(e){this.stopTraining_=e}get stopTraining(){return this.stopTraining_}get optimizer(){return this.optimizer_}set optimizer(e){this.optimizer_!==e&&(this.optimizer_=e,this.isOptimizerOwned=!1)}dispose(){const e=super.dispose();if(0===e.refCountAfterDispose&&null!=this.optimizer&&this.isOptimizerOwned){const t=yi().numTensors;this.optimizer_.dispose(),e.numDisposedVariables+=t-yi().numTensors}return e}getLossIdentifiers(){let e;if("string"==typeof this.loss)e=ez(this.loss);else if(Array.isArray(this.loss)){for(const e of this.loss)if("string"!=typeof e)throw new Error("Serialization of non-string loss is not supported.");e=this.loss.map((e=>ez(e)))}else{const t=Object.keys(this.loss);e={};const n=this.loss;for(const s of t){if("string"!=typeof n[s])throw new Error("Serialization of non-string loss is not supported.");e[s]=ez(n[s])}}return e}getMetricIdentifiers(){if("string"==typeof this.metrics||"function"==typeof this.metrics)return[ez(MW(this.metrics))];if(Array.isArray(this.metrics))return this.metrics.map((e=>ez(MW(e))));{const e={};for(const t in this.metrics)e[t]=ez(MW(this.metrics[t]));return e}}getTrainingConfig(){return{loss:this.getLossIdentifiers(),metrics:this.getMetricIdentifiers(),optimizer_config:{class_name:this.optimizer.getClassName(),config:this.optimizer.getConfig()}}}loadTrainingConfig(e){if(null!=e.weighted_metrics)throw new Error("Loading weight_metrics is not supported yet.");if(null!=e.loss_weights)throw new Error("Loading loss_weights is not supported yet.");if(null!=e.sample_weight_mode)throw new Error("Loading sample_weight_mode is not supported yet.");const t=gW(GW(e.optimizer_config));let n,s;if("string"==typeof e.loss)n=tz(e.loss);else if(Array.isArray(e.loss))n=e.loss.map((e=>tz(e)));else if(null!=e.loss){n={};for(const t in e.loss)n[t]=tz(e.loss[t])}if(Array.isArray(e.metrics))s=e.metrics.map((e=>tz(e)));else if(null!=e.metrics){s={};for(const t in e.metrics)s[t]=tz(e.metrics[t])}this.compile({loss:n,metrics:s,optimizer:t})}async save(e,t){if("string"==typeof e){const t=Gi(e);if(0===t.length)throw new HP(`Cannot find any save handlers for URL '${e}'`);if(t.length>1)throw new HP(`Found more than one (${t.length}) save handlers for URL '${e}'`);e=t[0]}if(null==e.save)throw new HP("LayersModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");const n=await Ni(this.getNamedWeights(t)),s={modelTopology:this.toJSON(null,!1),format:"layers-model",generatedBy:`TensorFlow.js tfjs-layers v${qW}`,convertedBy:null};if(null!=t&&t.includeOptimizer&&null!=this.optimizer){s.trainingConfig=this.getTrainingConfig();const e="optimizer",{data:t,specs:r}=await Ni(await this.optimizer.getWeights(),e);n.specs.push(...r),n.data=Oi([n.data,t])}if(null!=this.userDefinedMetadata){const e=!0;LW(this.userDefinedMetadata,this.name,e),s.userDefinedMetadata=this.userDefinedMetadata}return s.weightData=n.data,s.weightSpecs=n.specs,e.save(s)}setUserDefinedMetadata(e){LW(e,this.name),this.userDefinedMetadata=e}getUserDefinedMetadata(){return this.userDefinedMetadata}}hU.className="Model",Cp(hU);class dU extends hU{}dU.className="Functional",Cp(dU);
|
|
16184
|
+
*/function oU(e){return Array.isArray(e)}function uU(e){return!function(e){return e instanceof _a}(e)&&!oU(e)}function lU(e,t,n,s=!0,r=""){if(null==t||0===t.length){if(null!=e){let t=!1;if(oU(e)&&e.length>0)t=!0;else if(uU(e)){for(const n in e)if(e.hasOwnProperty(n)){t=!0;break}}else t=!0;if(t)throw new HP(`Error when checking model ${r} expected no data, but got ${e}`)}return[]}if(null==e)return t.map((e=>null));let a;if(uU(e)){a=[];for(const n of t){if(null==e[n])throw new HP(`No data provided for "${n}". Need data for each key in: ${t}`);a.push(e[n])}}else if(oU(e)){if(e.length!==t.length)throw new HP(`Error when checking model ${r}: the Array of Tensors that you are passing to your model is not the size the model expected. Expected to see ${t.length} Tensor(s), but instead got the following list of Tensor(s): ${e}`);a=e}else{if(t.length>1)throw new HP(`The model ${r} expects ${t.length} Tensor(s), but only received one Tensor. Found: Tensor with shape ${e.shape}`);a=[e]}if(a=aU(a),null!=n)for(let e=0;e<t.length;++e){if(null==n[e])continue;const i=a[e];if(i.shape.length!==n[e].length)throw new HP(`Error when checking ${r}: expected ${t[e]} to have ${n[e].length} dimension(s). but got array with shape ${i.shape}`);for(let t=0;t<n[e].length;++t){if(0===t&&!s)continue;const a=i.shape[t],o=n[e][t];if(null!=o&&o>=0&&a!==o)throw new HP(`${r} expected a batch of elements where each example has shape [${n[e].slice(1,n[e].length)}] (i.e.,tensor shape [*,${n[e].slice(1,n[e].length)}]) but the ${r} received an input with ${i.shape[0]} examples, each with shape [${i.shape.slice(1,i.shape.length)}] (tensor shape [${i.shape}])`)}}return a}function cU(e,t,n,s=!0,r=""){let a;if(Array.isArray(e)){if(e.length!==t.length)throw new HP(`Error when checking model ${r}: the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see ${t.length} Tensor(s), but instead got ${e.length} Tensors(s).`);a=e}else{if(t.length>1)throw new HP(`The model expects ${t.length} ${r} Tensors, but only received one Tensor. Found: array with shape ${JSON.stringify(e.shape)}.`);a=[e]}if(null!=n)for(let e=0;e<t.length;++e){if(null==n[e])continue;const i=a[e];if(i.shape.length!==n[e].length)throw new HP(`Error when checking ${r}: expected ${t[e]} to have ${n[e].length} dimension(s), but got array with shape ${JSON.stringify(i.shape)}`);for(let a=0;a<n[e].length;++a){if(0===a&&!s)continue;const o=i.shape[a],u=n[e][a];if(null!=u&&u!==o)throw new HP(`Error when checking ${r}: expected ${t[e]} to have shape ${JSON.stringify(n[e])} but got array with shape ${JSON.stringify(i.shape)}.`)}}}class hU extends jW{constructor(e){super(e),this.isTraining=!1}summary(e,t,n=console.log){if(!this.built)throw new HP("This model has never been called, thus its weights have not been created yet. So no summary can be displayed. Build the model first (e.g., by calling it on some test data).");zW(this,e,t,n)}compile(e){if(null==e.loss&&(e.loss=[]),this.loss=e.loss,"string"==typeof e.optimizer)this.optimizer_=function(e){const t={Adagrad:()=>bf.adagrad(.01),Adadelta:()=>bf.adadelta(1,.95,Bz()),Adam:()=>bf.adam(.001,.9,.999,Bz()),Adamax:()=>bf.adamax(.002,.9,.999,Bz(),0),RMSProp:()=>bf.rmsprop(.001,.9,0,Bz()),SGD:()=>bf.sgd(.01)};if(t.adagrad=t.Adagrad,t.adadelta=t.Adadelta,t.adam=t.Adam,t.adamax=t.Adamax,t.rmsprop=t.RMSProp,t.sgd=t.SGD,e in t)return t[e]();throw new HP(`Unknown Optimizer ${e}`)}(e.optimizer),this.isOptimizerOwned=!0;else{if(!(e.optimizer instanceof Np))throw new HP("User-defined optimizer must be an instance of tf.Optimizer.");this.optimizer_=e.optimizer,this.isOptimizerOwned=!1}let t=[];if(Array.isArray(e.loss)||"string"==typeof e.loss||"function"==typeof e.loss)if(Array.isArray(e.loss)){if(e.loss.length!==this.outputs.length)throw new HP(`When passing an Array as loss, it should have one entry per model output. The model has ${this.outputs.length} output(s), but you passed loss=${e.loss}.`);const n=e.loss;t=n.map((e=>NW(e)))}else{const n=NW(e.loss);this.outputs.forEach((e=>{t.push(n)}))}else{e.loss=e.loss;for(const t in e.loss)if(-1===this.outputNames.indexOf(t))throw new HP(`Unknown entry in loss dictionary: "${t}". Only expected the following keys: ${this.outputNames}`);for(const n of this.outputNames)null==e.loss[n]&&console.warn(`Output "${n}" is missing from loss dictionary. We assume this was done on purpose, and we will not be expecting data to be passed to ${n} during training`),t.push(NW(e.loss[n]))}this.lossFunctions=t,this.feedOutputNames=[],this.feedOutputShapes=[],this.feedLossFns=[];for(let e=0;e<this.outputs.length;++e){const t=this.internalOutputShapes[e],n=this.outputNames[e];this.feedOutputNames.push(n),this.feedOutputShapes.push(t),this.feedLossFns.push(this.lossFunctions[e])}const n=[];this.metrics=e.metrics,this.metricsNames=["loss"],this.metricsTensors=[],Rz("loss",(()=>{for(let e=0;e<this.outputs.length;++e){if(-1!==n.indexOf(e))continue;const t=this.lossFunctions[e];this.outputs.length>1&&(this.metricsTensors.push([t,e]),this.metricsNames.push(this.outputNames[e]+"_loss"))}}));const s=function(e,t){if(null==e||Array.isArray(e)&&0===e.length)return t.map((e=>[]));let n;if("string"==typeof e||"function"==typeof e)n=[e];else{if(!Array.isArray(e)&&"object"!=typeof e)throw new TypeError(`Type of metrics argument not understood. Expected an string,function, Array, or Object, found: ${e}`);n=e}if(Array.isArray(n))return t.map((e=>n));{const e=[];for(const s of t){let t=n.hasOwnProperty(s)?n[s]:[];Array.isArray(t)||(t=[t]),e.push(t)}return e}}(e.metrics,this.outputNames),r=(e,t,n)=>{this.outputNames.length>1&&(t=this.outputNames[e]+"_"+t),this.metricsNames.push(t),this.metricsTensors.push([n,e])};Rz("metric",(()=>{for(let e=0;e<this.outputs.length;++e){if(-1!==n.indexOf(e))continue;(t=>{let n,s,a;for(const i of t){if("string"==typeof i&&-1!==["accuracy","acc","crossentropy","ce"].indexOf(i)){const t=this.internalOutputShapes[e];let r;1===t[t.length-1]||this.lossFunctions[e]===IW?-1!==["accuracy","acc"].indexOf(i)?s=TW:-1!==["crossentropy","ce"].indexOf(i)&&(s=RW):this.lossFunctions[e]===vW?-1!==["accuracy","acc"].indexOf(i)?s=EW:-1!==["crossentropy","ce"].indexOf(i)&&(s=_W):-1!==["accuracy","acc"].indexOf(i)?s=$W:-1!==["crossentropy","ce"].indexOf(i)&&(s=AW),-1!==["accuracy","acc"].indexOf(i)?r="acc":-1!==["crossentropy","ce"].indexOf(i)&&(r="ce"),a=s,n=""+r}else{const e=DW(i);a=e,n=""+MW(i)}let t;Rz(n,(()=>{t=a})),r(e,n,t)}})(s[e])}})),this.collectedTrainableWeights=this.trainableWeights}checkTrainableWeightsConsistency(){null!=this.collectedTrainableWeights&&this.trainableWeights.length!==this.collectedTrainableWeights.length&&console.warn("Discrepancy between trainableweights and collected trainable weights. Did you set `model.trainable` without calling `model.compile()` afterwards?")}evaluate(e,t,n={}){const s=null==n.batchSize?32:n.batchSize;tU(s);const r=this.standardizeUserDataXY(e,t,!0,s);try{const e=r[0].concat(r[1]);this.makeTestFunction();const t=this.testFunction;return JP(this.testLoop(t,e,s,n.verbose,n.steps))}finally{iU(r[0],e),iU(r[1],t)}}async evaluateDataset(e,t){return this.makeTestFunction(),async function(e,t,n){const s=null!=(n=n||{}).batches,r=e.testFunction;let a=[];if(n.verbose>0)throw new qP("Verbose mode is not implemented yet.");me(!s||n.batches>0&&Number.isInteger(n.batches),(()=>`Test loop expects \`batches\` to be a positive integer, but received ${JSON.stringify(n.batches)}`));const i="function"==typeof t.next?t:await t.iterator();let o=0,u=0;for(;!s||u<n.batches;){const t=await i.next();if(a=bi((()=>{if(t.value){const{xs:n,ys:s}=QW(e,t.value),i=n.concat(s),l=bi((()=>r(i)));if(xi(i),0===u)for(let e=0;e<l.length;++e)a.push(pl(0));const c=i[0].shape[0];for(let e=0;e<l.length;++e){const t=l[e],n=a[e];a[e]=bi((()=>Co(a[e],$o(c,t)))),u>0&&xi(n)}xi(l),o+=c,++u}return a})),t.done){s&&console.warn(`Your dataset iterator ran out of data during evaluateDataset(). Interrupting evalution. Make sure that your dataset can generate at least \`batches\` batches (in this case, ${n.batches} batches). You may need to use the repeat() function when building your dataset.`);break}}for(let e=0;e<a.length;++e){const t=a[e];a[e]=To(a[e],o),xi(t)}return JP(a)}(this,e,t)}checkNumSamples(e,t,n,s="steps"){let r;if(null!=n){if(r=null,null!=t)throw new HP(`If ${s} is set, batchSize must be null or undefined.Got batchSize = ${t}`)}else{if(null==e)throw new HP(`Either the input data should have a defined shape, or ${s} shoud be specified.`);r=Array.isArray(e)?e[0].shape[0]:e.shape[0]}return r}execute(e,t){if(Array.isArray(t)&&0===t.length)throw new HP("`outputs` is an empty Array, which is not allowed.");const n=Array.isArray(t),s=n?t:[t],r=this.retrieveSymbolicTensors(s),a=new UB;if(e instanceof _a&&(e=[e]),Array.isArray(e)){if(e.length!==this.inputs.length)throw new HP(`The number of inputs provided (${e.length}) does not match the number of inputs of this model (${this.inputs.length}).`);for(let t=0;t<this.inputs.length;++t)a.add(this.inputs[t],e[t])}else for(const t of this.inputs){const n=e[t.name];if(null==n)throw new HP(`No value is provided for the model's input ${t.name}`);a.add(t,n)}const i=HB(r,a);return n?i:i[0]}retrieveSymbolicTensors(e){const t=KP(null,e.length);let n=e.length;for(const s of this.layers){const r=Array.isArray(s.output)?s.output:[s.output],a=r.map((e=>e.name));for(let s=0;s<e.length;++s){const i=a.indexOf(e[s]);if(-1!==i&&(t[s]=r[i],n--),0===n)break}if(0===n)break}if(n>0){const n=[];throw t.forEach(((t,s)=>{null==t&&n.push(e[s])})),new HP(`Cannot find SymbolicTensors for output name(s): ${JSON.stringify(n)}`)}return t}predictLoop(e,t=32,n=!1){return bi((()=>{const s=this.checkNumSamples(e);if(n)throw new qP("Verbose predictLoop() is not implemented yet.");const r=rU(s,t),a=this.outputs.map((e=>[]));for(let t=0;t<r.length;++t){const n=bi((()=>{const n=r[t][0],s=r[t][1],a=nU(e,n,s),i=[];if(Array.isArray(a))for(let e=0;e<a.length;++e)i.push({key:this.inputs[e],value:a[e]});else i.push({key:this.inputs[0],value:a});const o=new UB(i);return HB(this.outputs,o)}));n.forEach(((e,t)=>a[t].push(e)))}return JP(a.map((e=>iu(e,0))))}))}predict(e,t={}){const n=aU(e);cU(n,this.inputNames,this.feedInputShapes,!1);try{const e=null==t.batchSize?32:t.batchSize;return tU(e),this.predictLoop(n,e)}finally{iU(n,e)}}predictOnBatch(e){cU(e,this.inputNames,this.feedInputShapes,!0);const t=(Array.isArray(e)?e[0]:e).shape[0];return this.predictLoop(e,t)}standardizeUserDataXY(e,t,n=!0,s){if(null==this.optimizer_)throw new GP("You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).");const r=[];for(let e=0;e<this.feedOutputShapes.length;++e){const t=this.feedOutputShapes[e];this.feedLossFns[e]===vW?r.push(t.slice(0,t.length-1).concat([1])):r.push(t)}if(function(e,t,n){const s=oz(e.map((e=>e.shape[0])));s.sort();const r=oz(t.map((e=>e.shape[0])));if(r.sort(),s.length>1)throw new HP(`All input Tensors (x) should have the same number of samples. Got array shapes: ${JSON.stringify(e.map((e=>e.shape)))}`);if(r.length>1)throw new HP(`All target Tensors (y) should have the same number of samples. Got array shapes: ${JSON.stringify(t.map((e=>e.shape)))}`);if(s.length>0&&r.length>0&&!we(s,r))throw new HP(`Input Tensors should have the same number of samples as target Tensors. Found ${s[0]} input sample(s) and ${r[0]} target sample(s).`)}(e=lU(e,this.feedInputNames,this.feedInputShapes,!1,"input"),t=lU(t,this.feedOutputNames,r,!1,"target")),function(e,t,n){const s=[bW,IW,kW];for(let r=0;r<e.length;++r){const a=e[r],i=t[r],o=n[r];if(null!=i){if(i===kW&&1===a.shape[a.shape.length-1])throw new HP(`You are passing a target array of shape ${a.shape} while using a loss 'categorical_crossentropy'. 'categorical_crossentropy'expects targets to be binary matrices (1s and 0s) of shape [samples, classes].`);if(-1!==s.indexOf(i)){const e=a.shape.slice(1),t=o.slice(1);for(let n=0;n<e.length;++n){const s=e[n],r=t[n];if(null!=r&&s!==r)throw new HP(`A target Tensor with shape ${a.shape} was passed for an output of shape ${o}, while using a loss function that expects targets to have the same shape as the output.`)}}}}}(t,this.feedLossFns,this.feedOutputShapes),this.stateful&&null!=s&&s>0&&e[0].shape[0]%s!=0)throw new HP(`In a stateful network, you should only pass inputs with a number of samples that is divisible by the batch size ${s}. Found: ${e[0].shape[0]} sample(s).`);return[e,t]}async standardizeUserData(e,t,n,s,r=!0,a){const[i,o]=this.standardizeUserDataXY(e,t,r,a);if(null!=n)throw new Error("sample weight is not supported yet.");let u=null;if(null!=s){const e=XW(s,this.outputNames);u=[];for(let t=0;t<e.length;++t)u.push(await KW(o[t],0,e[t]))}return[i,o,u]}testLoop(e,t,n,s=0,r){return bi((()=>{const a=this.checkNumSamples(t,n,r,"steps"),i=[];if(s>0)throw new qP("Verbose mode is not implemented yet.");if(null!=r)throw new qP("steps mode in testLoop() is not implemented yet");{const s=rU(a,n),r=Ph(Pz(0,a));for(let n=0;n<s.length;++n){const a=s[n][0],o=s[n][1],u=Vz(r,a,o-a),l=sU(t,u),c=e(l);if(0===n)for(let e=0;e<c.length;++e)i.push(pl(0));for(let e=0;e<c.length;++e){const t=c[e];i[e]=Co(i[e],$o(o-a,t))}}for(let e=0;e<i.length;++e)i[e]=To(i[e],a)}return i}))}getDedupedMetricsNames(){const e=this.metricsNames,t=[];for(let n=0;n<e.length;++n){const s=e[n];let r=s;if(QP(e,s)>1){r+=`_${QP(e.slice(0,n),s)}`}t.push(r)}return t}makeTrainFunction(){return e=>{const t=[],n=e.slice(0,this.inputs.length),s=e.slice(this.inputs.length,this.inputs.length+this.outputs.length),r=e.slice(this.inputs.length+this.outputs.length,this.inputs.length+2*this.outputs.length),a=[],i=this.collectedTrainableWeights.map((e=>e.read())),o=this.optimizer_.minimize((()=>{const e=[];for(let t=0;t<this.inputs.length;++t)e.push({key:this.inputs[t],value:n[t]});const i=new UB(e),o=HB(this.outputs,i,{training:!0});let u;for(let e=0;e<this.lossFunctions.length;++e){let n=(0,this.lossFunctions[e])(s[e],o[e]);null!=r[e]&&(n=YW(n,r[e]));const a=nc(n);t.push(a),u=0===e?n:Co(u,n)}for(let e=0;e<this.metricsTensors.length;++e){let n;if(this.outputs.length>1&&e<this.outputs.length)n=t[e];else{const t=this.metricsTensors[e][0],r=this.metricsTensors[e][1];n=nc(t(s[r],o[r]))}wi(n),a.push(n)}return u=nc(u),this.calculateLosses().forEach((e=>{u=Co(u,e)})),u}),!0,i);return[o].concat(a)}}makeTestFunction(){this.testFunction=e=>bi((()=>{const t=[];let n;const s=e.slice(0,this.inputs.length),r=e.slice(this.inputs.length,this.inputs.length+this.outputs.length),a=[];for(let e=0;e<this.inputs.length;++e)a.push({key:this.inputs[e],value:s[e]});const i=new UB(a),o=HB(this.outputs,i);for(let e=0;e<this.lossFunctions.length;++e){const s=this.lossFunctions[e],a=nc(s(r[e],o[e]));n=0===e?a:Co(n,a),t.push(n)}for(let e=0;e<this.metricsTensors.length;++e){const n=this.metricsTensors[e][0],s=this.metricsTensors[e][1],a=nc(n(r[s],o[s]));t.push(a)}return t}))}async fit(e,t,n={}){if(this.isTraining)throw new Error("Cannot start training because another fit() call is ongoing.");let s,r,a,i,o,u,l,c,h;this.isTraining=!0;try{const d=null==n.batchSize?32:n.batchSize;tU(d);const p=!1,f=await this.standardizeUserData(e,t,n.sampleWeight,n.classWeight,p,d);s=f[0],r=f[1],h=f[2];let m,g=!1;if(null!=n.validationData&&n.validationData.length>0){if(g=!0,2!==n.validationData.length)throw 3===n.validationData.length?new qP("validationData including sample weights is not supported yet."):new HP(`When passing validation data, it must contain 2 (valX, valY) or 3 (valX, valY, valSampleWeight) items; ${n.validationData} is invalid.`);o=n.validationData[0],u=n.validationData[1];const e=!0,t=await this.standardizeUserData(o,u,null,null,e,d);l=t[0],c=t[1],m=l.concat(c)}else if(null!=n.validationSplit&&n.validationSplit>0&&n.validationSplit<1){g=!0;const e=Math.floor(s[0].shape[0]*(1-n.validationSplit)),t=s[0].shape[0];l=nU(s,e,t),a=s,s=nU(s,0,e),c=nU(r,e,t),i=r,r=nU(r,0,e),m=l.concat(c)}else null!=n.validationSteps&&(g=!0);const y=s.concat(r).concat(h);this.checkTrainableWeightsConsistency();const b=this.makeTrainFunction(),x=this.getDedupedMetricsNames();let w,k;g?(this.makeTestFunction(),w=this.testFunction,k=x.slice().concat(x.map((e=>"val_"+e)))):(w=null,m=[],k=x.slice());const v=pW(n.callbacks,n.yieldEvery);return await this.fitLoop(b,y,x,d,n.epochs,n.verbose,v,w,m,n.shuffle,k,n.initialEpoch,null,null)}finally{this.isTraining=!1,iU(s,e),iU(r,t),iU(a,e),iU(i,t),iU(l,o),iU(c,u),null!=h&&xi(h)}}async fitLoop(e,t,n,s,r,a,i,o,u,l,c,h,d,p){null==s&&(s=32),null==r&&(r=1),null==l&&(l=!0),null==h&&(h=0);let f=!1;if(null!=o&&null!=u&&(f=!0),null!=p&&(f=!0,null==d))throw new HP("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set.");const m=this.checkNumSamples(t,s,d,"steps_per_epoch");let g;null!=m&&(g=Pz(0,m)),null==a&&(a=1);const{callbackList:y,history:b}=mW(i,a,r,h,m,d,s,f,c);y.setModel(this),this.history=b,await y.onTrainBegin(),this.stopTraining_=!1;for(let a=h;a<r;++a){await y.onEpochBegin(a);const r={};if(null!=d)throw new qP("stepsPerEpoch mode is not implemented yet.");{if("batch"===l)throw new qP("batch shuffling is not implemneted yet");l&&ce(g);const a=Ph(g),i=rU(m,s);for(let l=0;l<i.length;++l){const c={};if(await y.onBatchBegin(l,c),bi((()=>{const h=i[l][0],d=i[l][1],p=Vz(a,h,d-h);c.batch=l,c.size=d-h;const m=sU(t,p),g=e(m);for(let e=0;e<n.length;++e){const t=n[e],s=g[e];c[t]=s,wi(s)}if(l===i.length-1&&f){const e=this.testLoop(o,u,s);for(let t=0;t<n.length;++t){const s=n[t],a=e[t];wi(a),r["val_"+s]=a}}})),await y.onBatchEnd(l,c),iW(c),this.stopTraining_)break}a.dispose()}if(await y.onEpochEnd(a,r),this.stopTraining_)break}return await y.onTrainEnd(),await this.history.syncData(),this.history}async fitDataset(e,t){return ZW(this,e,t)}async trainOnBatch(e,t){const n=await this.standardizeUserData(e,t),s=n[0],r=n[1],a=this.makeTrainFunction()(s.concat(r)),i=[];for(const e of a){const t=await e.data();i.push(t[0])}return xi(a),iU(n[0],e),iU(n[1],t),JP(i)}getNamedWeights(e){const t=[],n=null!=e&&e.trainableOnly,s=n?this.trainableWeights:this.weights,r=this.getWeights(n);for(let e=0;e<s.length;++e)n&&!s[e].trainable||t.push({name:s[e].originalName,tensor:r[e]});return t}set stopTraining(e){this.stopTraining_=e}get stopTraining(){return this.stopTraining_}get optimizer(){return this.optimizer_}set optimizer(e){this.optimizer_!==e&&(this.optimizer_=e,this.isOptimizerOwned=!1)}dispose(){const e=super.dispose();if(0===e.refCountAfterDispose&&null!=this.optimizer&&this.isOptimizerOwned){const t=yi().numTensors;this.optimizer_.dispose(),e.numDisposedVariables+=t-yi().numTensors}return e}getLossIdentifiers(){let e;if("string"==typeof this.loss)e=ez(this.loss);else if(Array.isArray(this.loss)){for(const e of this.loss)if("string"!=typeof e)throw new Error("Serialization of non-string loss is not supported.");e=this.loss.map((e=>ez(e)))}else{const t=Object.keys(this.loss);e={};const n=this.loss;for(const s of t){if("string"!=typeof n[s])throw new Error("Serialization of non-string loss is not supported.");e[s]=ez(n[s])}}return e}getMetricIdentifiers(){if("string"==typeof this.metrics||"function"==typeof this.metrics)return[ez(MW(this.metrics))];if(Array.isArray(this.metrics))return this.metrics.map((e=>ez(MW(e))));{const e={};for(const t in this.metrics)e[t]=ez(MW(this.metrics[t]));return e}}getTrainingConfig(){return{loss:this.getLossIdentifiers(),metrics:this.getMetricIdentifiers(),optimizer_config:{class_name:this.optimizer.getClassName(),config:this.optimizer.getConfig()}}}loadTrainingConfig(e){if(null!=e.weighted_metrics)throw new Error("Loading weight_metrics is not supported yet.");if(null!=e.loss_weights)throw new Error("Loading loss_weights is not supported yet.");if(null!=e.sample_weight_mode)throw new Error("Loading sample_weight_mode is not supported yet.");const t=gW(GW(e.optimizer_config));let n,s;if("string"==typeof e.loss)n=tz(e.loss);else if(Array.isArray(e.loss))n=e.loss.map((e=>tz(e)));else if(null!=e.loss){n={};for(const t in e.loss)n[t]=tz(e.loss[t])}if(Array.isArray(e.metrics))s=e.metrics.map((e=>tz(e)));else if(null!=e.metrics){s={};for(const t in e.metrics)s[t]=tz(e.metrics[t])}this.compile({loss:n,metrics:s,optimizer:t})}async save(e,t){if("string"==typeof e){const t=Gi(e);if(0===t.length)throw new HP(`Cannot find any save handlers for URL '${e}'`);if(t.length>1)throw new HP(`Found more than one (${t.length}) save handlers for URL '${e}'`);e=t[0]}if(null==e.save)throw new HP("LayersModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");const n=await Ni(this.getNamedWeights(t)),s={modelTopology:this.toJSON(null,!1),format:"layers-model",generatedBy:`TensorFlow.js tfjs-layers v${qW}`,convertedBy:null};if(null!=t&&t.includeOptimizer&&null!=this.optimizer){s.trainingConfig=this.getTrainingConfig();const e="optimizer",{data:t,specs:r}=await Ni(await this.optimizer.getWeights(),e);n.specs.push(...r),n.data=Oi([n.data,t])}if(null!=this.userDefinedMetadata){const e=!0;LW(this.userDefinedMetadata,this.name,e),s.userDefinedMetadata=this.userDefinedMetadata}return s.weightData=n.data,s.weightSpecs=n.specs,e.save(s)}setUserDefinedMetadata(e){LW(e,this.name),this.userDefinedMetadata=e}getUserDefinedMetadata(){return this.userDefinedMetadata}}hU.className="Model",Cp(hU);class dU extends hU{}dU.className="Functional",Cp(dU);
|
|
16185
16185
|
/**
|
|
16186
16186
|
* @license
|
|
16187
16187
|
* Copyright 2018 Google LLC
|
|
@@ -16201,7 +16201,7 @@ class pU extends hU{constructor(e){if(super({inputs:[],outputs:[]}),e=e||{},this
|
|
|
16201
16201
|
* https://opensource.org/licenses/MIT.
|
|
16202
16202
|
* =============================================================================
|
|
16203
16203
|
*/
|
|
16204
|
-
let fU=class extends Ip{getConfig(){return{}}};class mU extends fU{apply(e,t=1){return function(e,t=1){if(1!==t)throw new qP(`Support for alpha values other than 1 (${t}) is not implemented yet.`);return Zu(e)}(e,t)}}mU.className="elu",Cp(mU);class gU extends fU{apply(e){return gh(e)}}gU.className="selu",Cp(gU);class yU extends fU{apply(e){return oh(e)}}yU.className="relu",Cp(yU);class bU extends fU{apply(e){return bi((()=>ac(6,oh(e))))}}bU.className="relu6",Cp(bU);class xU extends fU{apply(e){return e}}xU.className="linear",Cp(xU);class wU extends fU{apply(e){return uu(e)}}wU.className="sigmoid",Cp(wU);class kU extends fU{apply(e){return function(e){return bi((()=>{const t=Co(.5,$o(.2,e));return Iu(t,0,1)}))}(e)}}kU.className="hardSigmoid",Cp(kU);class vU extends fU{apply(e){return Wl(e)}}vU.className="softplus",Cp(vU);class IU extends fU{apply(e){return function(e){return bi((()=>To(e,Co(Ro(e),1))))}(e)}}IU.className="softsign",Cp(IU);class SU extends fU{apply(e){return cu(e)}}SU.className="tanh",Cp(SU);let CU=class extends fU{apply(e,t=-1){return Nh(e,t)}};CU.className="softmax",Cp(CU);class NU extends fU{apply(e,t=-1){return Gl(e,t)}}NU.className="logSoftmax",Cp(NU);class TU extends fU{apply(e
|
|
16204
|
+
let fU=class extends Ip{getConfig(){return{}}};class mU extends fU{apply(e,t=1){return function(e,t=1){if(1!==t)throw new qP(`Support for alpha values other than 1 (${t}) is not implemented yet.`);return Zu(e)}(e,t)}}mU.className="elu",Cp(mU);class gU extends fU{apply(e){return gh(e)}}gU.className="selu",Cp(gU);class yU extends fU{apply(e){return oh(e)}}yU.className="relu",Cp(yU);class bU extends fU{apply(e){return bi((()=>ac(6,oh(e))))}}bU.className="relu6",Cp(bU);class xU extends fU{apply(e){return e}}xU.className="linear",Cp(xU);class wU extends fU{apply(e){return uu(e)}}wU.className="sigmoid",Cp(wU);class kU extends fU{apply(e){return function(e){return bi((()=>{const t=Co(.5,$o(.2,e));return Iu(t,0,1)}))}(e)}}kU.className="hardSigmoid",Cp(kU);class vU extends fU{apply(e){return Wl(e)}}vU.className="softplus",Cp(vU);class IU extends fU{apply(e){return function(e){return bi((()=>To(e,Co(Ro(e),1))))}(e)}}IU.className="softsign",Cp(IU);class SU extends fU{apply(e){return cu(e)}}SU.className="tanh",Cp(SU);let CU=class extends fU{apply(e,t=-1){return Nh(e,t)}};CU.className="softmax",Cp(CU);class NU extends fU{apply(e,t=-1){return Gl(e,t)}}NU.className="logSoftmax",Cp(NU);class TU extends fU{apply(e){return bi((()=>bi((()=>{const t=Math.sqrt(2),n=$o(.5,Co(1,tl(To(e,t))));return $o(e,n)}))))}}TU.className="gelu",Cp(TU);class $U extends fU{apply(e){return bi((()=>$o(.5,$o(e,Co(1,cu($o(fl(To(2,Math.PI)),Co(e,$o(.044715,dl(e,3))))))))))}}$U.className="gelu_new",Cp($U);class RU extends fU{apply(e){return bi((()=>$o(e,cu(Wl(e)))))}}RU.className="mish",Cp(RU);class EU extends fU{apply(e,t=1){return bi((()=>$o(uu($o(e,t)),e)))}}function AU(e){return e.getClassName()}function _U(e,t={}){return az(e,Sp.getMap().classNameMap,t,"activation")}function FU(e){if(null==e){const e={className:"linear",config:{}};return _U(e)}if("string"==typeof e){const t={};return t.className=e,t.config={},_U(t)}return e instanceof fU?e:_U(e)}
|
|
16205
16205
|
/**
|
|
16206
16206
|
* @license
|
|
16207
16207
|
* Copyright 2018 Google LLC
|
|
@@ -16210,7 +16210,7 @@ let fU=class extends Ip{getConfig(){return{}}};class mU extends fU{apply(e,t=1){
|
|
|
16210
16210
|
* license that can be found in the LICENSE file or at
|
|
16211
16211
|
* https://opensource.org/licenses/MIT.
|
|
16212
16212
|
* =============================================================================
|
|
16213
|
-
|
|
16213
|
+
*/EU.className="swish",Cp(EU);class DU extends Ip{}class MU extends DU{constructor(e){super(),function(e){if(null!=e&&"object"!=typeof e)throw new Error(`Argument to L1L2 regularizer's constructor is expected to be an object, but received: ${e}`)}(e),this.l1=null==e||null==e.l1?.01:e.l1,this.l2=null==e||null==e.l2?.01:e.l2,this.hasL1=0!==this.l1,this.hasL2=0!==this.l2}apply(e){return bi((()=>{let t=sc([1]);return this.hasL1&&(t=Co(t,gl($o(this.l1,Ro(e))))),this.hasL2&&(t=Co(t,gl($o(this.l2,Jz(e))))),su(t,[])}))}getConfig(){return{l1:this.l1,l2:this.l2}}static fromConfig(e,t){return new e({l1:t.l1,l2:t.l2})}}MU.className="L1L2",Cp(MU);const OU={l1l2:"L1L2"};function LU(e){return sz(e)}function PU(e,t={}){return az(e,Sp.getMap().classNameMap,t,"regularizer")}function zU(e){if(null==e)return null;if("string"==typeof e){return PU({className:e in OU?OU[e]:e,config:{}})}return e instanceof DU?e:PU(e)}
|
|
16214
16214
|
/**
|
|
16215
16215
|
* @license
|
|
16216
16216
|
* Copyright 2018 Google LLC
|
|
@@ -16219,7 +16219,7 @@ let fU=class extends Ip{getConfig(){return{}}};class mU extends fU{apply(e,t=1){
|
|
|
16219
16219
|
* license that can be found in the LICENSE file or at
|
|
16220
16220
|
* https://opensource.org/licenses/MIT.
|
|
16221
16221
|
* =============================================================================
|
|
16222
|
-
*/class
|
|
16222
|
+
*/class BU extends zB{constructor(e){super(null==e?{}:e),this.supportsMasking=!0,null!=e&&(this.maxValue=e.maxValue)}call(e,t){e=TB(e);let n=oh(e);return null!=this.maxValue&&(n=Iu(n,0,this.maxValue)),n}computeOutputShape(e){return e}getConfig(){const e={maxValue:this.maxValue},t=super.getConfig();return Object.assign(e,t),e}}BU.className="ReLU",Cp(BU);class WU extends zB{constructor(e){super(null==e?{}:e),this.DEFAULT_ALPHA=.3,null==e&&(e={}),this.alpha=null==e.alpha?this.DEFAULT_ALPHA:e.alpha}call(e,t){const n=TB(e);return Fl(n,this.alpha)}computeOutputShape(e){return e}getConfig(){const e={alpha:this.alpha},t=super.getConfig();return Object.assign(e,t),e}}WU.className="LeakyReLU",Cp(WU);class UU extends zB{constructor(e){if(super(null==e?{}:e),this.DEFAULT_ALPHA_INITIALIZER="zeros",null==e&&(e={}),this.supportsMasking=!0,this.alphaInitializer=SB(e.alphaInitializer||this.DEFAULT_ALPHA_INITIALIZER),this.alphaRegularizer=zU(e.alphaRegularizer),this.alphaConstraint=rW(e.alphaConstraint),null==e.sharedAxes)this.sharedAxes=null;else if(Array.isArray(e.sharedAxes))this.sharedAxes=e.sharedAxes;else{if("number"!=typeof e.sharedAxes)throw new HP(`Expected sharedAxes to be a number or an array of numbers, but got ${e.sharedAxes}`);this.sharedAxes=[e.sharedAxes]}}build(e){const t=(e=$B(e)).slice(1);if(null!=this.sharedAxes)for(const e of this.sharedAxes)t[e-1]=1;this.alpha=this.addWeight("alpha",t,"float32",this.alphaInitializer,this.alphaRegularizer,!0,this.alphaConstraint);const n={};if(null!=this.sharedAxes)for(let t=1;t<e.length;++t)n[t]=e[t];this.inputSpec=[new DB({ndim:e.length,axes:n})],this.built=!0}call(e,t){return e=TB(e),vc(e,this.alpha.read())}getConfig(){const e={alphaInitializer:IB(this.alphaInitializer),alphaRegularizer:LU(this.alphaRegularizer),alphaConstraint:nW(this.alphaConstraint),sharedAxes:this.sharedAxes},t=super.getConfig();return Object.assign(e,t),e}}UU.className="PReLU",Cp(UU);class VU extends zB{constructor(e){if(super(null==e?{}:e),this.DEFAULT_ALPHA=1,null==e&&(e={}),null!=e.alpha&&e.alpha!==this.DEFAULT_ALPHA)throw new qP(`Non-default alpha value (${e.alpha}) is not supported by the ELU layer yet.`);this.alpha=null==e.alpha?this.DEFAULT_ALPHA:e.alpha}call(e,t){const n=TB(e);return Zu(n)}computeOutputShape(e){return e}getConfig(){const e={alpha:this.alpha},t=super.getConfig();return Object.assign(e,t),e}}VU.className="ELU",Cp(VU);class GU extends zB{constructor(e){super(null==e?{}:e),this.DEFAULT_THETA=1,null==e&&(e={}),this.theta=null==e.theta?this.DEFAULT_THETA:e.theta}call(e,t){const n=TB(e);return $o(n,vo(Tl(n,this.theta),"float32"))}computeOutputShape(e){return e}getConfig(){const e={theta:this.theta},t=super.getConfig();return Object.assign(e,t),e}}GU.className="ThresholdedReLU",Cp(GU);class HU extends zB{constructor(e){super(null==e?{}:e),this.DEFAULT_AXIS=1,null==e&&(e={}),this.softmax=(new CU).apply,this.axis=null==e.axis?this.DEFAULT_AXIS:e.axis}call(e,t){return bi((()=>{let n=TB(e);const s=t.mask;if(null!=s){const e=$o(Vl(rc(n.shape),vo(s,n.dtype)),pl(-1e9));n=Co(n,e)}return this.axis instanceof Array?this.axis.length>1?wl(Vl(n,Hl(n,this.axis,!0))):this.softmax(n,this.axis[0]):this.softmax(n,this.axis)}))}computeOutputShape(e){return e}getConfig(){const e={axis:this.axis},t=super.getConfig();return Object.assign(e,t),e}}
|
|
16223
16223
|
/**
|
|
16224
16224
|
* @license
|
|
16225
16225
|
* Copyright 2018 Google LLC
|
|
@@ -16229,7 +16229,7 @@ let fU=class extends Ip{getConfig(){return{}}};class mU extends fU{apply(e,t=1){
|
|
|
16229
16229
|
* https://opensource.org/licenses/MIT.
|
|
16230
16230
|
* =============================================================================
|
|
16231
16231
|
*/
|
|
16232
|
-
function
|
|
16232
|
+
function qU(e,t,n){if("number"==typeof e)return KP(e,t);if(e.length!==t)throw new HP(`The ${n} argument must be an integer or tuple of ${t} integers. Received: ${e.length} elements.`);for(let s=0;s<t;++s){const r=e[s];if(!Dz(r))throw new HP(`The ${n} argument must be an integer or tuple of ${t} integers. Received: ${JSON.stringify(e)} including a non-integer number ${r}`)}return e}function jU(e,t,n,s,r=1){if(null==e)return e;let a;return a="same"===n?e:e-(t+(t-1)*(r-1))+1,Math.floor((a+s-1)/s)}function XU(e,t,n,s){if(null==e)return null;if("valid"===s)e=e*t+Lz([n-t,0]);else{if("same"!==s)throw new HP(`Unsupport padding mode: ${s}.`);e*=t}return e}
|
|
16233
16233
|
/**
|
|
16234
16234
|
* @license
|
|
16235
16235
|
* Copyright 2018 Google LLC
|
|
@@ -16238,7 +16238,7 @@ function GU(e,t,n){if("number"==typeof e)return KP(e,t);if(e.length!==t)throw ne
|
|
|
16238
16238
|
* license that can be found in the LICENSE file or at
|
|
16239
16239
|
* https://opensource.org/licenses/MIT.
|
|
16240
16240
|
* =============================================================================
|
|
16241
|
-
*/function jU(e,t){return bi((()=>(Sz(t),"channelsFirst"===t?ed(e,[0,2,3,1]):e)))}function XU(e,t){return bi((()=>(Sz(t),"channelsFirst"===t?ed(e,[0,2,3,4,1]):e)))}function KU(e,t,n,s=[1,1],r="valid",a,i,o=null){return bi((()=>{if(null==a&&(a="channelsLast"),Sz(a),3!==e.rank&&4!==e.rank)throw new HP(`conv2dWithBiasActivation expects input to be of rank 3 or 4, but received ${e.rank}.`);if(3!==t.rank&&4!==t.rank)throw new HP(`conv2dWithBiasActivation expects kernel to be of rank 3 or 4, but received ${e.rank}.`);let u=jU(e,a);if("causal"===r)throw new qP("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");return u=fd({x:u,filter:t,strides:s,pad:"same"===r?"same":"valid",dilations:i,dataFormat:"NHWC",bias:n,activation:o}),"channelsFirst"===a&&(u=ed(u,[0,3,1,2])),u}))}VU.className="Softmax",Cp(VU);class YU extends zB{constructor(e,t){if(super(t),this.bias=null,this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_BIAS_INITIALIZER="zeros",YU.verifyArgs(t),this.rank=e,hz(this.rank,"rank"),1!==this.rank&&2!==this.rank&&3!==this.rank)throw new qP(`Convolution layer for rank other than 1, 2, or 3 (${this.rank}) is not implemented yet.`);if(this.kernelSize=GU(t.kernelSize,e,"kernelSize"),this.strides=GU(null==t.strides?1:t.strides,e,"strides"),this.padding=null==t.padding?"valid":t.padding,Cz(this.padding),this.dataFormat=null==t.dataFormat?"channelsLast":t.dataFormat,Sz(this.dataFormat),this.activation=AU(t.activation),this.useBias=null==t.useBias||t.useBias,this.biasInitializer=SB(t.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.biasConstraint=rW(t.biasConstraint),this.biasRegularizer=LU(t.biasRegularizer),this.activityRegularizer=LU(t.activityRegularizer),this.dilationRate=GU(null==t.dilationRate?1:t.dilationRate,e,"dilationRate"),1===this.rank&&Array.isArray(this.dilationRate)&&1!==this.dilationRate.length)throw new HP(`dilationRate must be a number or an array of a single number for 1D convolution, but received ${JSON.stringify(this.dilationRate)}`);if(2===this.rank){if("number"==typeof this.dilationRate)this.dilationRate=[this.dilationRate,this.dilationRate];else if(2!==this.dilationRate.length)throw new HP(`dilationRate must be a number or array of two numbers for 2D convolution, but received ${JSON.stringify(this.dilationRate)}`)}else if(3===this.rank)if("number"==typeof this.dilationRate)this.dilationRate=[this.dilationRate,this.dilationRate,this.dilationRate];else if(3!==this.dilationRate.length)throw new HP(`dilationRate must be a number or array of three numbers for 3D convolution, but received ${JSON.stringify(this.dilationRate)}`)}static verifyArgs(e){if(YP("kernelSize"in e,"required key 'kernelSize' not in config"),"number"!=typeof e.kernelSize&&!cz(e.kernelSize,"number",1,3))throw new HP(`BaseConv expects config.kernelSize to be number or number[] with length 1, 2, or 3, but received ${JSON.stringify(e.kernelSize)}.`)}getConfig(){const e={kernelSize:this.kernelSize,strides:this.strides,padding:this.padding,dataFormat:this.dataFormat,dilationRate:this.dilationRate,activation:RU(this.activation),useBias:this.useBias,biasInitializer:IB(this.biasInitializer),biasRegularizer:MU(this.biasRegularizer),activityRegularizer:MU(this.activityRegularizer),biasConstraint:nW(this.biasConstraint)},t=super.getConfig();return Object.assign(e,t),e}}class QU extends YU{constructor(e,t){super(e,t),this.kernel=null,QU.verifyArgs(t),this.filters=t.filters,hz(this.filters,"filters"),this.kernelInitializer=SB(t.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.kernelConstraint=rW(t.kernelConstraint),this.kernelRegularizer=LU(t.kernelRegularizer)}build(e){e=$B(e);const t="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[t])throw new HP(`The channel dimension of the input should be defined. Found ${e[t]}`);const n=e[t],s=this.kernelSize.concat([n,this.filters]);this.kernel=this.addWeight("kernel",s,null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[{ndim:this.rank+2,axes:{[t]:n}}],this.built=!0}call(e,t){return bi((()=>{let t;e=TB(e);const n=null==this.bias?null:this.bias.read(),s=pz(this.activation.getClassName());if(null!=s&&2===this.rank)t=KU(e,this.kernel.read(),n,this.strides,this.padding,this.dataFormat,this.dilationRate,s);else{if(1===this.rank)t=function(e,t,n,s=1,r="valid",a,i=1){return bi((()=>{if(null==a&&(a="channelsLast"),Sz(a),3!==e.shape.length)throw new HP(`The input of a conv1dWithBias operation should be 3, but is ${e.shape.length} instead.`);if(3!==t.shape.length)throw new HP(`The kernel for a conv1dWithBias operation should be 3, but is ${t.shape.length} instead`);if(null!=n&&1!==n.shape.length)throw new HP(`The bias for a conv1dWithBias operation should be 1, but is ${t.shape.length} instead`);if("channelsFirst"===a&&(e=ed(e,[0,2,1])),"causal"===r)throw new qP("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");let o=Ru(e,t,s,"same"===r?"same":"valid","NWC",i);return null!=n&&(o=eB(o,n)),o}))}(e,this.kernel.read(),n,this.strides[0],this.padding,this.dataFormat,this.dilationRate[0]);else if(2===this.rank)t=KU(e,this.kernel.read(),n,this.strides,this.padding,this.dataFormat,this.dilationRate);else{if(3!==this.rank)throw new qP("convolutions greater than 3D are not implemented yet.");t=function(e,t,n,s=[1,1,1],r="valid",a,i){return bi((()=>{if(null==a&&(a="channelsLast"),Sz(a),4!==e.rank&&5!==e.rank)throw new HP(`conv3dWithBias expects input to be of rank 4 or 5, but received ${e.rank}.`);if(4!==t.rank&&5!==t.rank)throw new HP(`conv3dWithBias expects kernel to be of rank 4 or 5, but received ${e.rank}.`);let o=XU(e,a);if("causal"===r)throw new qP("The support for CAUSAL padding mode in conv3dWithBias is not implemented yet.");return o=_u(o,t,s,"same"===r?"same":"valid","NDHWC",i),null!=n&&(o=eB(o,n)),"channelsFirst"===a&&(o=ed(o,[0,4,1,2,3])),o}))}(e,this.kernel.read(),n,this.strides,this.padding,this.dataFormat,this.dilationRate)}null!=this.activation&&(t=this.activation.apply(t))}return t}))}computeOutputShape(e){e=$B(e);const t=[],n="channelsLast"===this.dataFormat?e.slice(1,e.length-1):e.slice(2);for(let e=0;e<n.length;++e){const s=HU(n[e],this.kernelSize[e],this.padding,this.strides[e],"number"==typeof this.dilationRate?this.dilationRate:this.dilationRate[e]);t.push(s)}let s=[e[0]];return"channelsLast"===this.dataFormat?(s=s.concat(t),s.push(this.filters)):(s.push(this.filters),s=s.concat(t)),s}getConfig(){const e={filters:this.filters,kernelInitializer:IB(this.kernelInitializer),kernelRegularizer:MU(this.kernelRegularizer),kernelConstraint:nW(this.kernelConstraint)},t=super.getConfig();return Object.assign(e,t),e}static verifyArgs(e){if(!("filters"in e)||"number"!=typeof e.filters||e.filters<1)throw new HP(`Convolution layer expected config.filters to be a 'number' > 0 but got ${JSON.stringify(e.filters)}`)}}class JU extends QU{constructor(e){super(2,e),JU.verifyArgs(e)}getConfig(){const e=super.getConfig();return delete e.rank,e}static verifyArgs(e){if("number"!=typeof e.kernelSize&&!cz(e.kernelSize,"number",1,2))throw new HP(`Conv2D expects config.kernelSize to be number or number[] with length 1 or 2, but received ${JSON.stringify(e.kernelSize)}.`)}}JU.className="Conv2D",Cp(JU);class ZU extends QU{constructor(e){super(3,e),ZU.verifyArgs(e)}getConfig(){const e=super.getConfig();return delete e.rank,e}static verifyArgs(e){if("number"!=typeof e.kernelSize&&(!Array.isArray(e.kernelSize)||1!==e.kernelSize.length&&3!==e.kernelSize.length))throw new HP(`Conv3D expects config.kernelSize to be number or [number, number, number], but received ${JSON.stringify(e.kernelSize)}.`)}}ZU.className="Conv3D",Cp(ZU);class eV extends JU{constructor(e){if(super(e),this.inputSpec=[new DB({ndim:4})],"same"!==this.padding&&"valid"!==this.padding)throw new HP(`Conv2DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode ${this.padding}`)}build(e){if(4!==(e=$B(e)).length)throw new HP("Input should have rank 4; Received input shape: "+JSON.stringify(e));const t="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[t])throw new HP("The channel dimension of the inputs should be defined. Found `None`.");const n=e[t],s=this.kernelSize.concat([this.filters,n]);this.kernel=this.addWeight("kernel",s,"float32",this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[new DB({ndim:4,axes:{[t]:n}})],this.built=!0}call(e,t){return bi((()=>{let t=TB(e);if(4!==t.shape.length)throw new HP(`Conv2DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-${t.shape.length}`);const n=t.shape,s=n[0];let r,a;"channelsFirst"===this.dataFormat?(r=2,a=3):(r=1,a=2);const i=n[r],o=n[a],u=this.kernelSize[0],l=this.kernelSize[1],c=this.strides[0],h=this.strides[1],d=[s,qU(i,c,u,this.padding),qU(o,h,l,this.padding),this.filters];"channelsLast"!==this.dataFormat&&(t=ed(t,[0,2,3,1]));let p=Au(t,this.kernel.read(),d,this.strides,this.padding);return"channelsLast"!==this.dataFormat&&(p=ed(p,[0,3,1,2])),null!=this.bias&&(p=eB(p,this.bias.read(),this.dataFormat)),null!=this.activation&&(p=this.activation.apply(p)),p}))}computeOutputShape(e){const t=(e=$B(e)).slice();let n,s,r;"channelsFirst"===this.dataFormat?(n=1,s=2,r=3):(n=3,s=1,r=2);const a=this.kernelSize[0],i=this.kernelSize[1],o=this.strides[0],u=this.strides[1];return t[n]=this.filters,t[s]=qU(t[s],o,a,this.padding),t[r]=qU(t[r],u,i,this.padding),t}getConfig(){const e=super.getConfig();return delete e.dilationRate,e}}eV.className="Conv2DTranspose",Cp(eV);class tV extends ZU{constructor(e){if(super(e),this.inputSpec=[new DB({ndim:5})],"same"!==this.padding&&"valid"!==this.padding)throw new HP(`Conv3DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode ${this.padding}`)}build(e){if(5!==(e=$B(e)).length)throw new HP("Input should have rank 5; Received input shape: "+JSON.stringify(e));const t="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[t])throw new HP("The channel dimension of the inputs should be defined. Found `None`.");const n=e[t],s=this.kernelSize.concat([this.filters,n]);this.kernel=this.addWeight("kernel",s,"float32",this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[new DB({ndim:5,axes:{[t]:n}})],this.built=!0}call(e,t){return bi((()=>{let t=TB(e);if(5!==t.shape.length)throw new HP(`Conv3DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-${t.shape.length}`);const n=t.shape,s=n[0];let r,a,i;"channelsFirst"===this.dataFormat?(i=2,r=3,a=4):(i=1,r=2,a=3);const o=n[i],u=n[r],l=n[a],c=this.kernelSize[0],h=this.kernelSize[1],d=this.kernelSize[2],p=this.strides[0],f=this.strides[1],m=this.strides[2],g=[s,qU(o,p,c,this.padding),qU(u,f,h,this.padding),qU(l,m,d,this.padding),this.filters];"channelsLast"!==this.dataFormat&&(t=ed(t,[0,2,3,4,1]));let y=Du(t,this.kernel.read(),g,this.strides,this.padding);return"channelsLast"!==this.dataFormat&&(y=ed(y,[0,4,1,2,3])),null!==this.bias&&(y=eB(y,this.bias.read(),this.dataFormat)),null!==this.activation&&(y=this.activation.apply(y)),y}))}computeOutputShape(e){const t=(e=$B(e)).slice();let n,s,r,a;"channelsFirst"===this.dataFormat?(n=1,s=2,r=3,a=4):(n=4,s=1,r=2,a=3);const i=this.kernelSize[0],o=this.kernelSize[1],u=this.kernelSize[2],l=this.strides[0],c=this.strides[1],h=this.strides[2];return t[n]=this.filters,t[s]=qU(t[s],l,i,this.padding),t[r]=qU(t[r],c,o,this.padding),t[a]=qU(t[a],h,u,this.padding),t}getConfig(){const e=super.getConfig();return delete e.dilationRate,e}}tV.className="Conv3DTranspose",Cp(tV);class nV extends QU{constructor(e,t){if(super(e,t),this.DEFAULT_DEPTHWISE_INITIALIZER="glorotUniform",this.DEFAULT_POINTWISE_INITIALIZER="glorotUniform",this.depthwiseKernel=null,this.pointwiseKernel=null,null==t.filters)throw new HP("The `filters` configuration field is required by SeparableConv, but is unspecified.");if(null!=t.kernelInitializer||null!=t.kernelRegularizer||null!=t.kernelConstraint)throw new HP("Fields kernelInitializer, kernelRegularizer and kernelConstraint are invalid for SeparableConv2D. Use depthwiseInitializer, depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, pointwiseRegularizer and pointwiseConstraint instead.");if(null!=t.padding&&"same"!==t.padding&&"valid"!==t.padding)throw new HP(`SeparableConv${this.rank}D supports only padding modes: 'same' and 'valid', but received ${JSON.stringify(t.padding)}`);this.depthMultiplier=null==t.depthMultiplier?1:t.depthMultiplier,this.depthwiseInitializer=SB(t.depthwiseInitializer||this.DEFAULT_DEPTHWISE_INITIALIZER),this.depthwiseRegularizer=LU(t.depthwiseRegularizer),this.depthwiseConstraint=rW(t.depthwiseConstraint),this.pointwiseInitializer=SB(t.depthwiseInitializer||this.DEFAULT_POINTWISE_INITIALIZER),this.pointwiseRegularizer=LU(t.pointwiseRegularizer),this.pointwiseConstraint=rW(t.pointwiseConstraint)}build(e){if((e=$B(e)).length<this.rank+2)throw new HP(`Inputs to SeparableConv${this.rank}D should have rank ${this.rank+2}, but received input shape: ${JSON.stringify(e)}`);const t="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[t]||e[t]<0)throw new HP(`The channel dimension of the inputs should be defined, but found ${JSON.stringify(e[t])}`);const n=e[t],s=this.kernelSize.concat([n,this.depthMultiplier]),r=[];for(let e=0;e<this.rank;++e)r.push(1);r.push(n*this.depthMultiplier,this.filters);const a=!0;this.depthwiseKernel=this.addWeight("depthwise_kernel",s,"float32",this.depthwiseInitializer,this.depthwiseRegularizer,a,this.depthwiseConstraint),this.pointwiseKernel=this.addWeight("pointwise_kernel",r,"float32",this.pointwiseInitializer,this.pointwiseRegularizer,a,this.pointwiseConstraint),this.useBias?this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,a,this.biasConstraint):this.bias=null,this.inputSpec=[new DB({ndim:this.rank+2,axes:{[t]:n}})],this.built=!0}call(e,t){return bi((()=>{let t;if(e=TB(e),1===this.rank)throw new qP("1D separable convolution is not implemented yet.");return 2===this.rank&&("channelsFirst"===this.dataFormat&&(e=ed(e,[0,2,3,1])),t=yh(e,this.depthwiseKernel.read(),this.pointwiseKernel.read(),this.strides,this.padding,this.dilationRate,"NHWC")),this.useBias&&(t=eB(t,this.bias.read(),this.dataFormat)),null!=this.activation&&(t=this.activation.apply(t)),"channelsFirst"===this.dataFormat&&(t=ed(t,[0,3,1,2])),t}))}getConfig(){const e=super.getConfig();return delete e.rank,delete e.kernelInitializer,delete e.kernelRegularizer,delete e.kernelConstraint,e.depthwiseInitializer=IB(this.depthwiseInitializer),e.pointwiseInitializer=IB(this.pointwiseInitializer),e.depthwiseRegularizer=MU(this.depthwiseRegularizer),e.pointwiseRegularizer=MU(this.pointwiseRegularizer),e.depthwiseConstraint=nW(this.depthwiseConstraint),e.pointwiseConstraint=nW(this.pointwiseConstraint),e}}nV.className="SeparableConv";class sV extends nV{constructor(e){super(2,e)}}sV.className="SeparableConv2D",Cp(sV);class rV extends QU{constructor(e){super(1,e),rV.verifyArgs(e),this.inputSpec=[{ndim:3}]}getConfig(){const e=super.getConfig();return delete e.rank,delete e.dataFormat,e}static verifyArgs(e){if("number"!=typeof e.kernelSize&&!cz(e.kernelSize,"number",1,1))throw new HP(`Conv1D expects config.kernelSize to be number or number[] with length 1, but received ${JSON.stringify(e.kernelSize)}.`)}}rV.className="Conv1D",Cp(rV);class aV extends zB{constructor(e){super(e),"number"==typeof e.cropping?this.cropping=[[e.cropping,e.cropping],[e.cropping,e.cropping]]:"number"==typeof e.cropping[0]?this.cropping=[[e.cropping[0],e.cropping[0]],[e.cropping[1],e.cropping[1]]]:this.cropping=e.cropping,this.dataFormat=void 0===e.dataFormat?"channelsLast":e.dataFormat,this.inputSpec=[{ndim:4}]}computeOutputShape(e){return"channelsFirst"===this.dataFormat?[e[0],e[1],e[2]-this.cropping[0][0]-this.cropping[0][1],e[3]-this.cropping[1][0]-this.cropping[1][1]]:[e[0],e[1]-this.cropping[0][0]-this.cropping[0][1],e[2]-this.cropping[1][0]-this.cropping[1][1],e[3]]}call(e,t){return bi((()=>{if(e=TB(e),"channelsLast"===this.dataFormat){const t=Hz(e,this.cropping[0][0],e.shape[1]-this.cropping[0][0]-this.cropping[0][1],2);return Hz(t,this.cropping[1][0],e.shape[2]-this.cropping[1][1]-this.cropping[1][0],3)}{const t=Hz(e,this.cropping[0][0],e.shape[2]-this.cropping[0][0]-this.cropping[0][1],3);return Hz(t,this.cropping[1][0],e.shape[3]-this.cropping[1][1]-this.cropping[1][0],4)}}))}getConfig(){const e={cropping:this.cropping,dataFormat:this.dataFormat},t=super.getConfig();return Object.assign(e,t),e}}aV.className="Cropping2D",Cp(aV);class iV extends zB{constructor(e){var t;super(e),this.DEFAULT_SIZE=[2,2],this.inputSpec=[{ndim:4}],this.size=null==e.size?this.DEFAULT_SIZE:e.size,this.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,Sz(this.dataFormat),this.interpolation=null==e.interpolation?"nearest":e.interpolation,t=this.interpolation,lz(xz,"InterpolationFormat",t)}computeOutputShape(e){if("channelsFirst"===this.dataFormat){const t=null==e[2]?null:this.size[0]*e[2],n=null==e[3]?null:this.size[1]*e[3];return[e[0],e[1],t,n]}{const t=null==e[1]?null:this.size[0]*e[1],n=null==e[2]?null:this.size[1]*e[2];return[e[0],t,n,e[3]]}}call(e,t){return bi((()=>{let t=TB(e);const n=t.shape;if("channelsFirst"===this.dataFormat){t=ed(t,[0,2,3,1]);const e=this.size[0]*n[2],s=this.size[1]*n[3],r="nearest"===this.interpolation?gp.resizeNearestNeighbor(t,[e,s]):gp.resizeBilinear(t,[e,s]);return ed(r,[0,3,1,2])}{const e=this.size[0]*n[1],s=this.size[1]*n[2];return"nearest"===this.interpolation?gp.resizeNearestNeighbor(t,[e,s]):gp.resizeBilinear(t,[e,s])}}))}getConfig(){const e={size:this.size,dataFormat:this.dataFormat,interpolation:this.interpolation},t=super.getConfig();return Object.assign(e,t),e}}iV.className="UpSampling2D",Cp(iV);class oV extends YU{constructor(e){super(2,e),this.depthwiseKernel=null,this.depthMultiplier=null==e.depthMultiplier?1:e.depthMultiplier,this.depthwiseInitializer=SB(e.depthwiseInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.depthwiseConstraint=rW(e.depthwiseConstraint),this.depthwiseRegularizer=LU(e.depthwiseRegularizer)}build(e){if((e=$B(e)).length<4)throw new HP(`Inputs to DepthwiseConv2D should have rank 4. Received input shape: ${JSON.stringify(e)}.`);const t="channelsFirst"===this.dataFormat?1:3;if(null==e[t]||e[t]<0)throw new HP(`The channel dimension of the inputs to DepthwiseConv2D should be defined, but is not (${e[t]}).`);const n=e[t],s=[this.kernelSize[0],this.kernelSize[1],n,this.depthMultiplier];this.depthwiseKernel=this.addWeight("depthwise_kernel",s,null,this.depthwiseInitializer,this.depthwiseRegularizer,!0,this.depthwiseConstraint),this.useBias?this.bias=this.addWeight("bias",[n*this.depthMultiplier],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0}call(e,t){return bi((()=>{let t=
|
|
16241
|
+
*/function KU(e,t){return bi((()=>(Sz(t),"channelsFirst"===t?ed(e,[0,2,3,1]):e)))}function YU(e,t){return bi((()=>(Sz(t),"channelsFirst"===t?ed(e,[0,2,3,4,1]):e)))}function QU(e,t,n,s=[1,1],r="valid",a,i,o=null){return bi((()=>{if(null==a&&(a="channelsLast"),Sz(a),3!==e.rank&&4!==e.rank)throw new HP(`conv2dWithBiasActivation expects input to be of rank 3 or 4, but received ${e.rank}.`);if(3!==t.rank&&4!==t.rank)throw new HP(`conv2dWithBiasActivation expects kernel to be of rank 3 or 4, but received ${e.rank}.`);let u=KU(e,a);if("causal"===r)throw new qP("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");return u=fd({x:u,filter:t,strides:s,pad:"same"===r?"same":"valid",dilations:i,dataFormat:"NHWC",bias:n,activation:o}),"channelsFirst"===a&&(u=ed(u,[0,3,1,2])),u}))}HU.className="Softmax",Cp(HU);class JU extends zB{constructor(e,t){if(super(t),this.bias=null,this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_BIAS_INITIALIZER="zeros",JU.verifyArgs(t),this.rank=e,hz(this.rank,"rank"),1!==this.rank&&2!==this.rank&&3!==this.rank)throw new qP(`Convolution layer for rank other than 1, 2, or 3 (${this.rank}) is not implemented yet.`);if(this.kernelSize=qU(t.kernelSize,e,"kernelSize"),this.strides=qU(null==t.strides?1:t.strides,e,"strides"),this.padding=null==t.padding?"valid":t.padding,Cz(this.padding),this.dataFormat=null==t.dataFormat?"channelsLast":t.dataFormat,Sz(this.dataFormat),this.activation=FU(t.activation),this.useBias=null==t.useBias||t.useBias,this.biasInitializer=SB(t.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.biasConstraint=rW(t.biasConstraint),this.biasRegularizer=zU(t.biasRegularizer),this.activityRegularizer=zU(t.activityRegularizer),this.dilationRate=qU(null==t.dilationRate?1:t.dilationRate,e,"dilationRate"),1===this.rank&&Array.isArray(this.dilationRate)&&1!==this.dilationRate.length)throw new HP(`dilationRate must be a number or an array of a single number for 1D convolution, but received ${JSON.stringify(this.dilationRate)}`);if(2===this.rank){if("number"==typeof this.dilationRate)this.dilationRate=[this.dilationRate,this.dilationRate];else if(2!==this.dilationRate.length)throw new HP(`dilationRate must be a number or array of two numbers for 2D convolution, but received ${JSON.stringify(this.dilationRate)}`)}else if(3===this.rank)if("number"==typeof this.dilationRate)this.dilationRate=[this.dilationRate,this.dilationRate,this.dilationRate];else if(3!==this.dilationRate.length)throw new HP(`dilationRate must be a number or array of three numbers for 3D convolution, but received ${JSON.stringify(this.dilationRate)}`)}static verifyArgs(e){if(YP("kernelSize"in e,"required key 'kernelSize' not in config"),"number"!=typeof e.kernelSize&&!cz(e.kernelSize,"number",1,3))throw new HP(`BaseConv expects config.kernelSize to be number or number[] with length 1, 2, or 3, but received ${JSON.stringify(e.kernelSize)}.`)}getConfig(){const e={kernelSize:this.kernelSize,strides:this.strides,padding:this.padding,dataFormat:this.dataFormat,dilationRate:this.dilationRate,activation:AU(this.activation),useBias:this.useBias,biasInitializer:IB(this.biasInitializer),biasRegularizer:LU(this.biasRegularizer),activityRegularizer:LU(this.activityRegularizer),biasConstraint:nW(this.biasConstraint)},t=super.getConfig();return Object.assign(e,t),e}}class ZU extends JU{constructor(e,t){super(e,t),this.kernel=null,ZU.verifyArgs(t),this.filters=t.filters,hz(this.filters,"filters"),this.kernelInitializer=SB(t.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.kernelConstraint=rW(t.kernelConstraint),this.kernelRegularizer=zU(t.kernelRegularizer)}build(e){e=$B(e);const t="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[t])throw new HP(`The channel dimension of the input should be defined. Found ${e[t]}`);const n=e[t],s=this.kernelSize.concat([n,this.filters]);this.kernel=this.addWeight("kernel",s,null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[{ndim:this.rank+2,axes:{[t]:n}}],this.built=!0}call(e,t){return bi((()=>{let t;e=TB(e);const n=null==this.bias?null:this.bias.read(),s=pz(this.activation.getClassName());if(null!=s&&2===this.rank)t=QU(e,this.kernel.read(),n,this.strides,this.padding,this.dataFormat,this.dilationRate,s);else{if(1===this.rank)t=function(e,t,n,s=1,r="valid",a,i=1){return bi((()=>{if(null==a&&(a="channelsLast"),Sz(a),3!==e.shape.length)throw new HP(`The input of a conv1dWithBias operation should be 3, but is ${e.shape.length} instead.`);if(3!==t.shape.length)throw new HP(`The kernel for a conv1dWithBias operation should be 3, but is ${t.shape.length} instead`);if(null!=n&&1!==n.shape.length)throw new HP(`The bias for a conv1dWithBias operation should be 1, but is ${n.shape.length} instead`);if("channelsFirst"===a&&(e=ed(e,[0,2,1])),"causal"===r)throw new qP("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");let o=Ru(e,t,s,"same"===r?"same":"valid","NWC",i);return null!=n&&(o=eB(o,n)),o}))}(e,this.kernel.read(),n,this.strides[0],this.padding,this.dataFormat,this.dilationRate[0]);else if(2===this.rank)t=QU(e,this.kernel.read(),n,this.strides,this.padding,this.dataFormat,this.dilationRate);else{if(3!==this.rank)throw new qP("convolutions greater than 3D are not implemented yet.");t=function(e,t,n,s=[1,1,1],r="valid",a,i){return bi((()=>{if(null==a&&(a="channelsLast"),Sz(a),4!==e.rank&&5!==e.rank)throw new HP(`conv3dWithBias expects input to be of rank 4 or 5, but received ${e.rank}.`);if(4!==t.rank&&5!==t.rank)throw new HP(`conv3dWithBias expects kernel to be of rank 4 or 5, but received ${e.rank}.`);let o=YU(e,a);if("causal"===r)throw new qP("The support for CAUSAL padding mode in conv3dWithBias is not implemented yet.");return o=_u(o,t,s,"same"===r?"same":"valid","NDHWC",i),null!=n&&(o=eB(o,n)),"channelsFirst"===a&&(o=ed(o,[0,4,1,2,3])),o}))}(e,this.kernel.read(),n,this.strides,this.padding,this.dataFormat,this.dilationRate)}null!=this.activation&&(t=this.activation.apply(t))}return t}))}computeOutputShape(e){e=$B(e);const t=[],n="channelsLast"===this.dataFormat?e.slice(1,e.length-1):e.slice(2);for(let e=0;e<n.length;++e){const s=jU(n[e],this.kernelSize[e],this.padding,this.strides[e],"number"==typeof this.dilationRate?this.dilationRate:this.dilationRate[e]);t.push(s)}let s=[e[0]];return"channelsLast"===this.dataFormat?(s=s.concat(t),s.push(this.filters)):(s.push(this.filters),s=s.concat(t)),s}getConfig(){const e={filters:this.filters,kernelInitializer:IB(this.kernelInitializer),kernelRegularizer:LU(this.kernelRegularizer),kernelConstraint:nW(this.kernelConstraint)},t=super.getConfig();return Object.assign(e,t),e}static verifyArgs(e){if(!("filters"in e)||"number"!=typeof e.filters||e.filters<1)throw new HP(`Convolution layer expected config.filters to be a 'number' > 0 but got ${JSON.stringify(e.filters)}`)}}class eV extends ZU{constructor(e){super(2,e),eV.verifyArgs(e)}getConfig(){const e=super.getConfig();return delete e.rank,e}static verifyArgs(e){if("number"!=typeof e.kernelSize&&!cz(e.kernelSize,"number",1,2))throw new HP(`Conv2D expects config.kernelSize to be number or number[] with length 1 or 2, but received ${JSON.stringify(e.kernelSize)}.`)}}eV.className="Conv2D",Cp(eV);class tV extends ZU{constructor(e){super(3,e),tV.verifyArgs(e)}getConfig(){const e=super.getConfig();return delete e.rank,e}static verifyArgs(e){if("number"!=typeof e.kernelSize&&(!Array.isArray(e.kernelSize)||1!==e.kernelSize.length&&3!==e.kernelSize.length))throw new HP(`Conv3D expects config.kernelSize to be number or [number, number, number], but received ${JSON.stringify(e.kernelSize)}.`)}}tV.className="Conv3D",Cp(tV);class nV extends eV{constructor(e){if(super(e),this.inputSpec=[new DB({ndim:4})],"same"!==this.padding&&"valid"!==this.padding)throw new HP(`Conv2DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode ${this.padding}`)}build(e){if(4!==(e=$B(e)).length)throw new HP("Input should have rank 4; Received input shape: "+JSON.stringify(e));const t="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[t])throw new HP("The channel dimension of the inputs should be defined. Found `None`.");const n=e[t],s=this.kernelSize.concat([this.filters,n]);this.kernel=this.addWeight("kernel",s,"float32",this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[new DB({ndim:4,axes:{[t]:n}})],this.built=!0}call(e,t){return bi((()=>{let t=TB(e);if(4!==t.shape.length)throw new HP(`Conv2DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-${t.shape.length}`);const n=t.shape,s=n[0];let r,a;"channelsFirst"===this.dataFormat?(r=2,a=3):(r=1,a=2);const i=n[r],o=n[a],u=this.kernelSize[0],l=this.kernelSize[1],c=this.strides[0],h=this.strides[1],d=[s,XU(i,c,u,this.padding),XU(o,h,l,this.padding),this.filters];"channelsLast"!==this.dataFormat&&(t=ed(t,[0,2,3,1]));let p=Au(t,this.kernel.read(),d,this.strides,this.padding);return"channelsLast"!==this.dataFormat&&(p=ed(p,[0,3,1,2])),null!=this.bias&&(p=eB(p,this.bias.read(),this.dataFormat)),null!=this.activation&&(p=this.activation.apply(p)),p}))}computeOutputShape(e){const t=(e=$B(e)).slice();let n,s,r;"channelsFirst"===this.dataFormat?(n=1,s=2,r=3):(n=3,s=1,r=2);const a=this.kernelSize[0],i=this.kernelSize[1],o=this.strides[0],u=this.strides[1];return t[n]=this.filters,t[s]=XU(t[s],o,a,this.padding),t[r]=XU(t[r],u,i,this.padding),t}getConfig(){const e=super.getConfig();return delete e.dilationRate,e}}nV.className="Conv2DTranspose",Cp(nV);class sV extends tV{constructor(e){if(super(e),this.inputSpec=[new DB({ndim:5})],"same"!==this.padding&&"valid"!==this.padding)throw new HP(`Conv3DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode ${this.padding}`)}build(e){if(5!==(e=$B(e)).length)throw new HP("Input should have rank 5; Received input shape: "+JSON.stringify(e));const t="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[t])throw new HP("The channel dimension of the inputs should be defined. Found `None`.");const n=e[t],s=this.kernelSize.concat([this.filters,n]);this.kernel=this.addWeight("kernel",s,"float32",this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[new DB({ndim:5,axes:{[t]:n}})],this.built=!0}call(e,t){return bi((()=>{let t=TB(e);if(5!==t.shape.length)throw new HP(`Conv3DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-${t.shape.length}`);const n=t.shape,s=n[0];let r,a,i;"channelsFirst"===this.dataFormat?(i=2,r=3,a=4):(i=1,r=2,a=3);const o=n[i],u=n[r],l=n[a],c=this.kernelSize[0],h=this.kernelSize[1],d=this.kernelSize[2],p=this.strides[0],f=this.strides[1],m=this.strides[2],g=[s,XU(o,p,c,this.padding),XU(u,f,h,this.padding),XU(l,m,d,this.padding),this.filters];"channelsLast"!==this.dataFormat&&(t=ed(t,[0,2,3,4,1]));let y=Du(t,this.kernel.read(),g,this.strides,this.padding);return"channelsLast"!==this.dataFormat&&(y=ed(y,[0,4,1,2,3])),null!==this.bias&&(y=eB(y,this.bias.read(),this.dataFormat)),null!==this.activation&&(y=this.activation.apply(y)),y}))}computeOutputShape(e){const t=(e=$B(e)).slice();let n,s,r,a;"channelsFirst"===this.dataFormat?(n=1,s=2,r=3,a=4):(n=4,s=1,r=2,a=3);const i=this.kernelSize[0],o=this.kernelSize[1],u=this.kernelSize[2],l=this.strides[0],c=this.strides[1],h=this.strides[2];return t[n]=this.filters,t[s]=XU(t[s],l,i,this.padding),t[r]=XU(t[r],c,o,this.padding),t[a]=XU(t[a],h,u,this.padding),t}getConfig(){const e=super.getConfig();return delete e.dilationRate,e}}sV.className="Conv3DTranspose",Cp(sV);class rV extends ZU{constructor(e,t){if(super(e,t),this.DEFAULT_DEPTHWISE_INITIALIZER="glorotUniform",this.DEFAULT_POINTWISE_INITIALIZER="glorotUniform",this.depthwiseKernel=null,this.pointwiseKernel=null,null==t.filters)throw new HP("The `filters` configuration field is required by SeparableConv, but is unspecified.");if(null!=t.kernelInitializer||null!=t.kernelRegularizer||null!=t.kernelConstraint)throw new HP("Fields kernelInitializer, kernelRegularizer and kernelConstraint are invalid for SeparableConv2D. Use depthwiseInitializer, depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, pointwiseRegularizer and pointwiseConstraint instead.");if(null!=t.padding&&"same"!==t.padding&&"valid"!==t.padding)throw new HP(`SeparableConv${this.rank}D supports only padding modes: 'same' and 'valid', but received ${JSON.stringify(t.padding)}`);this.depthMultiplier=null==t.depthMultiplier?1:t.depthMultiplier,this.depthwiseInitializer=SB(t.depthwiseInitializer||this.DEFAULT_DEPTHWISE_INITIALIZER),this.depthwiseRegularizer=zU(t.depthwiseRegularizer),this.depthwiseConstraint=rW(t.depthwiseConstraint),this.pointwiseInitializer=SB(t.depthwiseInitializer||this.DEFAULT_POINTWISE_INITIALIZER),this.pointwiseRegularizer=zU(t.pointwiseRegularizer),this.pointwiseConstraint=rW(t.pointwiseConstraint)}build(e){if((e=$B(e)).length<this.rank+2)throw new HP(`Inputs to SeparableConv${this.rank}D should have rank ${this.rank+2}, but received input shape: ${JSON.stringify(e)}`);const t="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[t]||e[t]<0)throw new HP(`The channel dimension of the inputs should be defined, but found ${JSON.stringify(e[t])}`);const n=e[t],s=this.kernelSize.concat([n,this.depthMultiplier]),r=[];for(let e=0;e<this.rank;++e)r.push(1);r.push(n*this.depthMultiplier,this.filters);const a=!0;this.depthwiseKernel=this.addWeight("depthwise_kernel",s,"float32",this.depthwiseInitializer,this.depthwiseRegularizer,a,this.depthwiseConstraint),this.pointwiseKernel=this.addWeight("pointwise_kernel",r,"float32",this.pointwiseInitializer,this.pointwiseRegularizer,a,this.pointwiseConstraint),this.useBias?this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,a,this.biasConstraint):this.bias=null,this.inputSpec=[new DB({ndim:this.rank+2,axes:{[t]:n}})],this.built=!0}call(e,t){return bi((()=>{let t;if(e=TB(e),1===this.rank)throw new qP("1D separable convolution is not implemented yet.");return 2===this.rank&&("channelsFirst"===this.dataFormat&&(e=ed(e,[0,2,3,1])),t=yh(e,this.depthwiseKernel.read(),this.pointwiseKernel.read(),this.strides,this.padding,this.dilationRate,"NHWC")),this.useBias&&(t=eB(t,this.bias.read(),this.dataFormat)),null!=this.activation&&(t=this.activation.apply(t)),"channelsFirst"===this.dataFormat&&(t=ed(t,[0,3,1,2])),t}))}getConfig(){const e=super.getConfig();return delete e.rank,delete e.kernelInitializer,delete e.kernelRegularizer,delete e.kernelConstraint,e.depthwiseInitializer=IB(this.depthwiseInitializer),e.pointwiseInitializer=IB(this.pointwiseInitializer),e.depthwiseRegularizer=LU(this.depthwiseRegularizer),e.pointwiseRegularizer=LU(this.pointwiseRegularizer),e.depthwiseConstraint=nW(this.depthwiseConstraint),e.pointwiseConstraint=nW(this.pointwiseConstraint),e}}rV.className="SeparableConv";class aV extends rV{constructor(e){super(2,e)}}aV.className="SeparableConv2D",Cp(aV);class iV extends ZU{constructor(e){super(1,e),iV.verifyArgs(e),this.inputSpec=[{ndim:3}]}getConfig(){const e=super.getConfig();return delete e.rank,delete e.dataFormat,e}static verifyArgs(e){if("number"!=typeof e.kernelSize&&!cz(e.kernelSize,"number",1,1))throw new HP(`Conv1D expects config.kernelSize to be number or number[] with length 1, but received ${JSON.stringify(e.kernelSize)}.`)}}iV.className="Conv1D",Cp(iV);class oV extends zB{constructor(e){super(e),"number"==typeof e.cropping?this.cropping=[[e.cropping,e.cropping],[e.cropping,e.cropping]]:"number"==typeof e.cropping[0]?this.cropping=[[e.cropping[0],e.cropping[0]],[e.cropping[1],e.cropping[1]]]:this.cropping=e.cropping,this.dataFormat=void 0===e.dataFormat?"channelsLast":e.dataFormat,this.inputSpec=[{ndim:4}]}computeOutputShape(e){return"channelsFirst"===this.dataFormat?[e[0],e[1],e[2]-this.cropping[0][0]-this.cropping[0][1],e[3]-this.cropping[1][0]-this.cropping[1][1]]:[e[0],e[1]-this.cropping[0][0]-this.cropping[0][1],e[2]-this.cropping[1][0]-this.cropping[1][1],e[3]]}call(e,t){return bi((()=>{if(e=TB(e),"channelsLast"===this.dataFormat){const t=Hz(e,this.cropping[0][0],e.shape[1]-this.cropping[0][0]-this.cropping[0][1],2);return Hz(t,this.cropping[1][0],e.shape[2]-this.cropping[1][1]-this.cropping[1][0],3)}{const t=Hz(e,this.cropping[0][0],e.shape[2]-this.cropping[0][0]-this.cropping[0][1],3);return Hz(t,this.cropping[1][0],e.shape[3]-this.cropping[1][1]-this.cropping[1][0],4)}}))}getConfig(){const e={cropping:this.cropping,dataFormat:this.dataFormat},t=super.getConfig();return Object.assign(e,t),e}}oV.className="Cropping2D",Cp(oV);class uV extends zB{constructor(e){var t;super(e),this.DEFAULT_SIZE=[2,2],this.inputSpec=[{ndim:4}],this.size=null==e.size?this.DEFAULT_SIZE:e.size,this.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,Sz(this.dataFormat),this.interpolation=null==e.interpolation?"nearest":e.interpolation,t=this.interpolation,lz(xz,"InterpolationFormat",t)}computeOutputShape(e){if("channelsFirst"===this.dataFormat){const t=null==e[2]?null:this.size[0]*e[2],n=null==e[3]?null:this.size[1]*e[3];return[e[0],e[1],t,n]}{const t=null==e[1]?null:this.size[0]*e[1],n=null==e[2]?null:this.size[1]*e[2];return[e[0],t,n,e[3]]}}call(e,t){return bi((()=>{let t=TB(e);const n=t.shape;if("channelsFirst"===this.dataFormat){t=ed(t,[0,2,3,1]);const e=this.size[0]*n[2],s=this.size[1]*n[3],r="nearest"===this.interpolation?gp.resizeNearestNeighbor(t,[e,s]):gp.resizeBilinear(t,[e,s]);return ed(r,[0,3,1,2])}{const e=this.size[0]*n[1],s=this.size[1]*n[2];return"nearest"===this.interpolation?gp.resizeNearestNeighbor(t,[e,s]):gp.resizeBilinear(t,[e,s])}}))}getConfig(){const e={size:this.size,dataFormat:this.dataFormat,interpolation:this.interpolation},t=super.getConfig();return Object.assign(e,t),e}}uV.className="UpSampling2D",Cp(uV);class lV extends JU{constructor(e){super(2,e),this.depthwiseKernel=null,this.depthMultiplier=null==e.depthMultiplier?1:e.depthMultiplier,this.depthwiseInitializer=SB(e.depthwiseInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.depthwiseConstraint=rW(e.depthwiseConstraint),this.depthwiseRegularizer=zU(e.depthwiseRegularizer)}build(e){if((e=$B(e)).length<4)throw new HP(`Inputs to DepthwiseConv2D should have rank 4. Received input shape: ${JSON.stringify(e)}.`);const t="channelsFirst"===this.dataFormat?1:3;if(null==e[t]||e[t]<0)throw new HP(`The channel dimension of the inputs to DepthwiseConv2D should be defined, but is not (${e[t]}).`);const n=e[t],s=[this.kernelSize[0],this.kernelSize[1],n,this.depthMultiplier];this.depthwiseKernel=this.addWeight("depthwise_kernel",s,null,this.depthwiseInitializer,this.depthwiseRegularizer,!0,this.depthwiseConstraint),this.useBias?this.bias=this.addWeight("bias",[n*this.depthMultiplier],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0}call(e,t){return bi((()=>{let t=
|
|
16242
16242
|
/**
|
|
16243
16243
|
* @license
|
|
16244
16244
|
* Copyright 2018 Google LLC
|
|
@@ -16248,7 +16248,7 @@ function GU(e,t,n){if("number"==typeof e)return KP(e,t);if(e.length!==t)throw ne
|
|
|
16248
16248
|
* https://opensource.org/licenses/MIT.
|
|
16249
16249
|
* =============================================================================
|
|
16250
16250
|
*/
|
|
16251
|
-
function(e,t,n=[1,1],s="valid",r,a){return bi((()=>{null==r&&(r="channelsLast"),Sz(r);let i=
|
|
16251
|
+
function(e,t,n=[1,1],s="valid",r,a){return bi((()=>{null==r&&(r="channelsLast"),Sz(r);let i=KU(e,r);if(4!==e.rank)throw new HP(`Input for depthwiseConv2d is required to be 4-D, but is instead ${e.rank}-D`);if(4!==t.rank)throw new HP(`depthwiseKernel is required to be 4-D, but is instead ${t.rank}-D`);return i=Wu(i,t,n,"same"===s?"same":"valid","NHWC",a),"channelsFirst"===r&&(i=ed(i,[0,3,1,2])),i}))}(e=TB(e),this.depthwiseKernel.read(),this.strides,this.padding,this.dataFormat,null);return this.useBias&&(t=eB(t,this.bias.read(),this.dataFormat)),null!=this.activation&&(t=this.activation.apply(t)),t}))}computeOutputShape(e){e=$B(e);const t="channelsFirst"===this.dataFormat?e[2]:e[1],n="channelsFirst"===this.dataFormat?e[3]:e[2],s="channelsFirst"===this.dataFormat?e[1]*this.depthMultiplier:e[3]*this.depthMultiplier,r=jU(t,this.kernelSize[0],this.padding,this.strides[0]),a=jU(n,this.kernelSize[1],this.padding,this.strides[1]);return"channelsFirst"===this.dataFormat?[e[0],s,r,a]:[e[0],r,a,s]}getConfig(){const e=super.getConfig();return e.depthMultiplier=this.depthMultiplier,e.depthwiseInitializer=IB(this.depthwiseInitializer),e.depthwiseRegularizer=LU(this.depthwiseRegularizer),e.depthwiseConstraint=nW(this.depthwiseRegularizer),e}}
|
|
16252
16252
|
/**
|
|
16253
16253
|
* @license
|
|
16254
16254
|
* Copyright 2018 Google LLC
|
|
@@ -16258,7 +16258,7 @@ function(e,t,n=[1,1],s="valid",r,a){return bi((()=>{null==r&&(r="channelsLast"),
|
|
|
16258
16258
|
* https://opensource.org/licenses/MIT.
|
|
16259
16259
|
* =============================================================================
|
|
16260
16260
|
*/
|
|
16261
|
-
function uV(e,t,n,s){if(Array.isArray(e)){if(null!=t||null!=n)throw new HP("When inputs is an array, neither initialState or constants should be provided");null!=s&&(n=e.slice(e.length-s,e.length),e=e.slice(0,e.length-s)),e.length>1&&(t=e.slice(1,e.length)),e=e[0]}function r(e){return null==e||Array.isArray(e)?e:[e]}return{inputs:e,initialState:t=r(t),constants:n=r(n)}}function lV(e,t,n,s=!1,r,a,i=!1,o=!1){return bi((()=>{const u=t.shape.length;if(u<3)throw new HP(`Input should be at least 3D, but is ${u}D.`);const l=[1,0].concat(Pz(2,u));if(t=ed(t,l),null!=a)throw new qP("The rnn() functoin of the deeplearn.js backend does not support constants yet.");i&&console.warn("Backend rnn(): the unroll = true option is not applicable to the imperative deeplearn.js backend."),null!=r&&((r=vo(vo(r,"bool"),"float32")).rank===u-1&&(r=kl(r,-1)),r=ed(r,l)),s&&(t=lh(t,0),null!=r&&(r=lh(r,0)));const c=[];let h,d=n;const p=t.shape[0],f=Kh(t);let m,g;null!=r&&(m=Kh(r));for(let t=0;t<p;++t){const n=f[t],s=bi((()=>e(n,d)));if(null==r)h=s[0],d=s[1];else{const e=bi((()=>{const e=m[t],n=Vl(pc(e),e),r=Co($o(s[0],e),$o(d[0],n)),a=d.map(((t,r)=>Co($o(s[1][r],e),$o(t,n))));return{output:r,newStates:a}}));h=e.output,d=e.newStates}o&&c.push(h)}if(o){g=Dh(c,1)}return[h,g,d]}))}oV.className="DepthwiseConv2D",Cp(oV);class cV extends zB{constructor(e){let t;if(super(e),null==e.cell)throw new HP("cell property is missing for the constructor of RNN.");if(t=Array.isArray(e.cell)?new bV({cells:e.cell}):e.cell,null==t.stateSize)throw new HP("The RNN cell should have an attribute `stateSize` (tuple of integers, one integer per RNN state).");this.cell=t,this.returnSequences=null!=e.returnSequences&&e.returnSequences,this.returnState=null!=e.returnState&&e.returnState,this.goBackwards=null!=e.goBackwards&&e.goBackwards,this._stateful=null!=e.stateful&&e.stateful,this.unroll=null!=e.unroll&&e.unroll,this.supportsMasking=!0,this.inputSpec=[new DB({ndim:3})],this.stateSpec=null,this.states_=null,this.numConstants=null,this.keptStates=[]}getStates(){if(null==this.states_){return Pz(0,Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1).map((e=>null))}return this.states_}setStates(e){this.states_=e}computeOutputShape(e){CB(e)&&(e=e[0]);let t=this.cell.stateSize;Array.isArray(t)||(t=[t]);const n=t[0];let s;if(s=this.returnSequences?[e[0],e[1],n]:[e[0],n],this.returnState){const n=[];for(const s of t)n.push([e[0],s]);return[s].concat(n)}return s}computeMask(e,t){return bi((()=>{Array.isArray(t)&&(t=t[0]);const e=this.returnSequences?t:null;if(this.returnState){const t=this.states.map((e=>null));return[e].concat(t)}return e}))}get states(){if(null==this.states_){const e=Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1,t=[];for(let n=0;n<e;++n)t.push(null);return t}return this.states_}set states(e){this.states_=e}build(e){if(null!=this.numConstants)throw new qP("Constants support is not implemented in RNN yet.");CB(e)&&(e=e[0]);const t=this.stateful?e[0]:null,n=e.slice(2);this.inputSpec[0]=new DB({shape:[t,null,...n]});const s=[e[0]].concat(e.slice(2));let r;if(this.cell.build(s),r=Array.isArray(this.cell.stateSize)?this.cell.stateSize:[this.cell.stateSize],null!=this.stateSpec){if(!we(this.stateSpec.map((e=>e.shape[e.shape.length-1])),r))throw new HP(`An initialState was passed that is not compatible with cell.stateSize. Received stateSpec=${this.stateSpec}; However cell.stateSize is ${this.cell.stateSize}`)}else this.stateSpec=r.map((e=>new DB({shape:[null,e]})));this.stateful&&this.resetStates()}resetStates(e,t=!1){bi((()=>{if(!this.stateful)throw new VP("Cannot call resetStates() on an RNN Layer that is not stateful.");const n=this.inputSpec[0].shape[0];if(null==n)throw new HP("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");if(null==this.states_)Array.isArray(this.cell.stateSize)?this.states_=this.cell.stateSize.map((e=>sc([n,e]))):this.states_=[sc([n,this.cell.stateSize])];else if(null==e)xi(this.states_),null!=this.keptStates&&(xi(this.keptStates),this.keptStates=[]),Array.isArray(this.cell.stateSize)?this.states_=this.cell.stateSize.map((e=>sc([n,e]))):this.states_[0]=sc([n,this.cell.stateSize]);else{if(Array.isArray(e)||(e=[e]),e.length!==this.states_.length)throw new HP(`Layer ${this.name} expects ${this.states_.length} state(s), but it received ${e.length} state value(s). Input received: ${e}`);!0===t?this.keptStates.push(this.states_.slice()):xi(this.states_);for(let t=0;t<this.states_.length;++t){const s=e[t],r=Array.isArray(this.cell.stateSize)?this.cell.stateSize[t]:this.cell.stateSize,a=[n,r];if(!we(s.shape,a))throw new HP(`State ${t} is incompatible with layer ${this.name}: expected shape=${a}, received shape=${s.shape}`);this.states_[t]=s}}this.states_=this.states_.map((e=>wi(e.clone())))}))}apply(e,t){let n=null==t?null:t.initialState,s=null==t?null:t.constants;null==t&&(t={});const r=uV(e,n,s,this.numConstants);e=r.inputs,n=r.initialState,s=r.constants;let a=[],i=[];if(null!=n){t.initialState=n,a=a.concat(n),this.stateSpec=[];for(const e of n)this.stateSpec.push(new DB({shape:e.shape}));i=i.concat(this.stateSpec)}null!=s&&(t.constants=s,a=a.concat(s),this.numConstants=s.length);if(a[0]instanceof MB){const n=[e].concat(a),s=this.inputSpec.concat(i),r=this.inputSpec;this.inputSpec=s;const o=super.apply(n,t);return this.inputSpec=r,o}return super.apply(e,t)}call(e,t){return bi((()=>{const n=null==t?null:t.mask,s=null==t?null:t.training;let r=null==t?null:t.initialState;e=TB(e),null==r&&(r=this.stateful?this.states_:this.getInitialState(e));const a=Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1;if(r.length!==a)throw new HP(`RNN Layer has ${a} state(s) but was passed ${r.length} initial state(s).`);this.unroll&&console.warn("Ignoring unroll = true for RNN layer, due to imperative backend.");const i={training:s},o=lV(((e,t)=>{const n=this.cell.call([e].concat(t),i);return[n[0],n.slice(1)]}),e,r,this.goBackwards,n,null,this.unroll,this.returnSequences),u=o[0],l=o[1],c=o[2];this.stateful&&this.resetStates(c,s);const h=this.returnSequences?l:u;return this.returnState?[h].concat(c):h}))}getInitialState(e){return bi((()=>{let t=sc(e.shape);return t=gl(t,[1,2]),t=Uz(t),Array.isArray(this.cell.stateSize)?this.cell.stateSize.map((e=>e>1?Xz(t,[1,e]):t)):this.cell.stateSize>1?[Xz(t,[1,this.cell.stateSize])]:[t]}))}get trainableWeights(){return this.trainable?this.cell.trainableWeights:[]}get nonTrainableWeights(){return this.trainable?this.cell.nonTrainableWeights:this.cell.weights}setFastWeightInitDuringBuild(e){super.setFastWeightInitDuringBuild(e),null!=this.cell&&this.cell.setFastWeightInitDuringBuild(e)}getConfig(){const e=super.getConfig(),t={returnSequences:this.returnSequences,returnState:this.returnState,goBackwards:this.goBackwards,stateful:this.stateful,unroll:this.unroll};null!=this.numConstants&&(t.numConstants=this.numConstants);const n=this.cell.getConfig();return this.getClassName()===cV.className&&(t.cell={className:this.cell.getClassName(),config:n}),Object.assign(Object.assign(Object.assign({},n),e),t)}static fromConfig(e,t,n={}){const s=gW(t.cell,n);return new e(Object.assign(t,{cell:s}))}}cV.className="RNN",Cp(cV);class hV extends zB{}class dV extends hV{constructor(e){super(e),this.DEFAULT_ACTIVATION="tanh",this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_RECURRENT_INITIALIZER="orthogonal",this.DEFAULT_BIAS_INITIALIZER="zeros",this.units=e.units,hz(this.units,"units"),this.activation=AU(null==e.activation?this.DEFAULT_ACTIVATION:e.activation),this.useBias=null==e.useBias||e.useBias,this.kernelInitializer=SB(e.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.recurrentInitializer=SB(e.recurrentInitializer||this.DEFAULT_RECURRENT_INITIALIZER),this.biasInitializer=SB(e.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.kernelRegularizer=LU(e.kernelRegularizer),this.recurrentRegularizer=LU(e.recurrentRegularizer),this.biasRegularizer=LU(e.biasRegularizer),this.kernelConstraint=rW(e.kernelConstraint),this.recurrentConstraint=rW(e.recurrentConstraint),this.biasConstraint=rW(e.biasConstraint),this.dropout=Oz([1,Lz([0,null==e.dropout?0:e.dropout])]),this.recurrentDropout=Oz([1,Lz([0,null==e.recurrentDropout?0:e.recurrentDropout])]),this.dropoutFunc=e.dropoutFunc,this.stateSize=this.units,this.dropoutMask=null,this.recurrentDropoutMask=null}build(e){e=$B(e),this.kernel=this.addWeight("kernel",[e[e.length-1],this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0}call(e,t){return bi((()=>{if(2!==e.length)throw new HP(`SimpleRNNCell expects 2 input Tensors, got ${e.length}.`);let n=e[1];e=e[0];const s=null!=t.training&&t.training;let r;0<this.dropout&&this.dropout<1&&null==this.dropoutMask&&(this.dropoutMask=xV({ones:()=>pc(e),rate:this.dropout,training:s,dropoutFunc:this.dropoutFunc})),0<this.recurrentDropout&&this.recurrentDropout<1&&null==this.recurrentDropoutMask&&(this.recurrentDropoutMask=xV({ones:()=>pc(n),rate:this.recurrentDropout,training:s,dropoutFunc:this.dropoutFunc}));const a=this.dropoutMask,i=this.recurrentDropoutMask;r=Yz(null!=a?$o(e,a):e,this.kernel.read()),null!=this.bias&&(r=eB(r,this.bias.read())),null!=i&&(n=$o(n,i));let o=Co(r,Yz(n,this.recurrentKernel.read()));return null!=this.activation&&(o=this.activation.apply(o)),[o,o]}))}getConfig(){const e=super.getConfig(),t={units:this.units,activation:RU(this.activation),useBias:this.useBias,kernelInitializer:IB(this.kernelInitializer),recurrentInitializer:IB(this.recurrentInitializer),biasInitializer:IB(this.biasInitializer),kernelRegularizer:MU(this.kernelRegularizer),recurrentRegularizer:MU(this.recurrentRegularizer),biasRegularizer:MU(this.biasRegularizer),activityRegularizer:MU(this.activityRegularizer),kernelConstraint:nW(this.kernelConstraint),recurrentConstraint:nW(this.recurrentConstraint),biasConstraint:nW(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout};return Object.assign(Object.assign({},e),t)}}dV.className="SimpleRNNCell",Cp(dV);class pV extends cV{constructor(e){e.cell=new dV(e),super(e)}call(e,t){return bi((()=>{null!=this.cell.dropoutMask&&(xi(this.cell.dropoutMask),this.cell.dropoutMask=null),null!=this.cell.recurrentDropoutMask&&(xi(this.cell.recurrentDropoutMask),this.cell.recurrentDropoutMask=null);const n=null==t?null:t.mask,s=null==t?null:t.training,r=null==t?null:t.initialState;return super.call(e,{mask:n,training:s,initialState:r})}))}static fromConfig(e,t){return new e(t)}}pV.className="SimpleRNN",Cp(pV);class fV extends hV{constructor(e){if(super(e),this.DEFAULT_ACTIVATION="tanh",this.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_RECURRENT_INITIALIZER="orthogonal",this.DEFAULT_BIAS_INITIALIZER="zeros",e.resetAfter)throw new HP("GRUCell does not support reset_after parameter set to true.");this.units=e.units,hz(this.units,"units"),this.activation=AU(void 0===e.activation?this.DEFAULT_ACTIVATION:e.activation),this.recurrentActivation=AU(void 0===e.recurrentActivation?this.DEFAULT_RECURRENT_ACTIVATION:e.recurrentActivation),this.useBias=null==e.useBias||e.useBias,this.kernelInitializer=SB(e.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.recurrentInitializer=SB(e.recurrentInitializer||this.DEFAULT_RECURRENT_INITIALIZER),this.biasInitializer=SB(e.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.kernelRegularizer=LU(e.kernelRegularizer),this.recurrentRegularizer=LU(e.recurrentRegularizer),this.biasRegularizer=LU(e.biasRegularizer),this.kernelConstraint=rW(e.kernelConstraint),this.recurrentConstraint=rW(e.recurrentConstraint),this.biasConstraint=rW(e.biasConstraint),this.dropout=Oz([1,Lz([0,null==e.dropout?0:e.dropout])]),this.recurrentDropout=Oz([1,Lz([0,null==e.recurrentDropout?0:e.recurrentDropout])]),this.dropoutFunc=e.dropoutFunc,this.implementation=e.implementation,this.stateSize=this.units,this.dropoutMask=null,this.recurrentDropoutMask=null}build(e){const t=(e=$B(e))[e.length-1];this.kernel=this.addWeight("kernel",[t,3*this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,3*this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[3*this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0}call(e,t){return bi((()=>{if(2!==e.length)throw new HP(`GRUCell expects 2 input Tensors (inputs, h, c), got ${e.length}.`);const n=null!=t.training&&t.training;let s=e[1];e=e[0],0<this.dropout&&this.dropout<1&&null==this.dropoutMask&&(this.dropoutMask=xV({ones:()=>pc(e),rate:this.dropout,training:n,count:3,dropoutFunc:this.dropoutFunc})),0<this.recurrentDropout&&this.recurrentDropout<1&&null==this.recurrentDropoutMask&&(this.recurrentDropoutMask=xV({ones:()=>pc(s),rate:this.recurrentDropout,training:n,count:3,dropoutFunc:this.dropoutFunc}));const r=this.dropoutMask,a=this.recurrentDropoutMask;let i,o,u;0<this.dropout&&this.dropout<1&&(e=$o(e,r[0]));let l=Yz(e,this.kernel.read());this.useBias&&(l=eB(l,this.bias.read())),0<this.recurrentDropout&&this.recurrentDropout<1&&(s=$o(s,a[0]));const c=this.recurrentKernel.read(),[h,d]=Eh(c,[2*this.units,this.units],c.rank-1),p=Yz(s,h),[f,m,g]=Eh(l,3,l.rank-1),[y,b]=Eh(p,2,p.rank-1);i=this.recurrentActivation.apply(Co(f,y)),o=this.recurrentActivation.apply(Co(m,b));const x=Yz($o(o,s),d);u=this.activation.apply(Co(g,x));const w=Co($o(i,s),$o(Co(1,Bl(i)),u));return[w,w]}))}getConfig(){const e=super.getConfig(),t={units:this.units,activation:RU(this.activation),recurrentActivation:RU(this.recurrentActivation),useBias:this.useBias,kernelInitializer:IB(this.kernelInitializer),recurrentInitializer:IB(this.recurrentInitializer),biasInitializer:IB(this.biasInitializer),kernelRegularizer:MU(this.kernelRegularizer),recurrentRegularizer:MU(this.recurrentRegularizer),biasRegularizer:MU(this.biasRegularizer),activityRegularizer:MU(this.activityRegularizer),kernelConstraint:nW(this.kernelConstraint),recurrentConstraint:nW(this.recurrentConstraint),biasConstraint:nW(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation,resetAfter:!1};return Object.assign(Object.assign({},e),t)}}fV.className="GRUCell",Cp(fV);class mV extends cV{constructor(e){0===e.implementation&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),e.cell=new fV(e),super(e)}call(e,t){return bi((()=>{null!=this.cell.dropoutMask&&(xi(this.cell.dropoutMask),this.cell.dropoutMask=null),null!=this.cell.recurrentDropoutMask&&(xi(this.cell.recurrentDropoutMask),this.cell.recurrentDropoutMask=null);const n=null==t?null:t.mask,s=null==t?null:t.training,r=null==t?null:t.initialState;return super.call(e,{mask:n,training:s,initialState:r})}))}static fromConfig(e,t){return 0===t.implmentation&&(t.implementation=1),new e(t)}}mV.className="GRU",Cp(mV);class gV extends hV{constructor(e){super(e),this.DEFAULT_ACTIVATION="tanh",this.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_RECURRENT_INITIALIZER="orthogonal",this.DEFAULT_BIAS_INITIALIZER="zeros",this.units=e.units,hz(this.units,"units"),this.activation=AU(void 0===e.activation?this.DEFAULT_ACTIVATION:e.activation),this.recurrentActivation=AU(void 0===e.recurrentActivation?this.DEFAULT_RECURRENT_ACTIVATION:e.recurrentActivation),this.useBias=null==e.useBias||e.useBias,this.kernelInitializer=SB(e.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.recurrentInitializer=SB(e.recurrentInitializer||this.DEFAULT_RECURRENT_INITIALIZER),this.biasInitializer=SB(e.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.unitForgetBias=e.unitForgetBias,this.kernelRegularizer=LU(e.kernelRegularizer),this.recurrentRegularizer=LU(e.recurrentRegularizer),this.biasRegularizer=LU(e.biasRegularizer),this.kernelConstraint=rW(e.kernelConstraint),this.recurrentConstraint=rW(e.recurrentConstraint),this.biasConstraint=rW(e.biasConstraint),this.dropout=Oz([1,Lz([0,null==e.dropout?0:e.dropout])]),this.recurrentDropout=Oz([1,Lz([0,null==e.recurrentDropout?0:e.recurrentDropout])]),this.dropoutFunc=e.dropoutFunc,this.implementation=e.implementation,this.stateSize=[this.units,this.units],this.dropoutMask=null,this.recurrentDropoutMask=null}build(e){var t;const n=(e=$B(e))[e.length-1];let s;if(this.kernel=this.addWeight("kernel",[n,4*this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,4*this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias){if(this.unitForgetBias){const e=this.biasInitializer,n=this.units;s=new((t=class extends aB{apply(t,s){const r=e.apply([n]),a=(new oB).apply([n]),i=e.apply([2*n]);return jz(jz(r,a),i)}}).className="CustomInit",t)}else s=this.biasInitializer;this.bias=this.addWeight("bias",[4*this.units],null,s,this.biasRegularizer,!0,this.biasConstraint)}else this.bias=null;this.built=!0}call(e,t){return bi((()=>{const n=null!=t.training&&t.training;if(3!==e.length)throw new HP(`LSTMCell expects 3 input Tensors (inputs, h, c), got ${e.length}.`);let s=e[1];const r=e[2];e=e[0],0<this.dropout&&this.dropout<1&&null==this.dropoutMask&&(this.dropoutMask=xV({ones:()=>pc(e),rate:this.dropout,training:n,count:4,dropoutFunc:this.dropoutFunc})),0<this.recurrentDropout&&this.recurrentDropout<1&&null==this.recurrentDropoutMask&&(this.recurrentDropoutMask=xV({ones:()=>pc(s),rate:this.recurrentDropout,training:n,count:4,dropoutFunc:this.dropoutFunc}));const a=this.dropoutMask,i=this.recurrentDropoutMask;let o,u,l,c;0<this.dropout&&this.dropout<1&&(e=$o(e,a[0]));let h=Yz(e,this.kernel.read());0<this.recurrentDropout&&this.recurrentDropout<1&&(s=$o(s,i[0])),h=Co(h,Yz(s,this.recurrentKernel.read())),this.useBias&&(h=eB(h,this.bias.read()));const[d,p,f,m]=Eh(h,4,h.rank-1);o=this.recurrentActivation.apply(d),u=this.recurrentActivation.apply(p),l=Co($o(u,r),$o(o,this.activation.apply(f))),c=this.recurrentActivation.apply(m);const g=$o(c,this.activation.apply(l));return[g,g,l]}))}getConfig(){const e=super.getConfig(),t={units:this.units,activation:RU(this.activation),recurrentActivation:RU(this.recurrentActivation),useBias:this.useBias,kernelInitializer:IB(this.kernelInitializer),recurrentInitializer:IB(this.recurrentInitializer),biasInitializer:IB(this.biasInitializer),unitForgetBias:this.unitForgetBias,kernelRegularizer:MU(this.kernelRegularizer),recurrentRegularizer:MU(this.recurrentRegularizer),biasRegularizer:MU(this.biasRegularizer),activityRegularizer:MU(this.activityRegularizer),kernelConstraint:nW(this.kernelConstraint),recurrentConstraint:nW(this.recurrentConstraint),biasConstraint:nW(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation};return Object.assign(Object.assign({},e),t)}}gV.className="LSTMCell",Cp(gV);class yV extends cV{constructor(e){0===e.implementation&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),e.cell=new gV(e),super(e)}call(e,t){return bi((()=>{null!=this.cell.dropoutMask&&(xi(this.cell.dropoutMask),this.cell.dropoutMask=null),null!=this.cell.recurrentDropoutMask&&(xi(this.cell.recurrentDropoutMask),this.cell.recurrentDropoutMask=null);const n=null==t?null:t.mask,s=null==t?null:t.training,r=null==t?null:t.initialState;return super.call(e,{mask:n,training:s,initialState:r})}))}static fromConfig(e,t){return 0===t.implmentation&&(t.implementation=1),new e(t)}}yV.className="LSTM",Cp(yV);class bV extends hV{constructor(e){super(e),this.cells=e.cells}get stateSize(){const e=[];for(const t of this.cells.slice().reverse())Array.isArray(t.stateSize)?e.push(...t.stateSize):e.push(t.stateSize);return e}call(e,t){return bi((()=>{let n=e.slice(1);const s=[];for(const e of this.cells.slice().reverse())Array.isArray(e.stateSize)?s.push(n.splice(0,e.stateSize.length)):s.push(n.splice(0,1));s.reverse();const r=[];let a;for(let i=0;i<this.cells.length;++i){const o=this.cells[i];n=s[i],a=0===i?[e[0]].concat(n):[a[0]].concat(n),a=o.call(a,t),r.push(a.slice(1))}n=[];for(const e of r.slice().reverse())n.push(...e);return[a[0]].concat(n)}))}build(e){let t;CB(e)&&(e=e[0]),this.cells.forEach(((n,s)=>{Rz(`RNNCell_${s}`,(()=>{n.build(e),t=Array.isArray(n.stateSize)?n.stateSize[0]:n.stateSize,e=[e[0],t]}))})),this.built=!0}getConfig(){const e=super.getConfig(),t={cells:this.cells.map((e=>({className:e.getClassName(),config:e.getConfig()})))};return Object.assign(Object.assign({},e),t)}static fromConfig(e,t,n={}){const s=[];for(const e of t.cells)s.push(gW(e,n));return new e({cells:s})}get trainableWeights(){if(!this.trainable)return[];const e=[];for(const t of this.cells)e.push(...t.trainableWeights);return e}get nonTrainableWeights(){const e=[];for(const t of this.cells)e.push(...t.nonTrainableWeights);if(!this.trainable){const t=[];for(const e of this.cells)t.push(...e.trainableWeights);return t.concat(e)}return e}getWeights(){const e=[];for(const t of this.cells)e.push(...t.weights);return _B(e)}setWeights(e){const t=[];for(const n of this.cells){const s=n.weights.length,r=e.splice(s);for(let e=0;e<n.weights.length;++e)t.push([n.weights[e],r[e]])}FB(t)}}function xV(e){const{ones:t,rate:n,training:s=!1,count:r=1,dropoutFunc:a}=e,i=()=>null!=a?a(t(),n):tB(t(),n),o=()=>nB(i,t,s);if(!r||r<=1)return wi(o().clone());return Array(r).fill(void 0).map(o).map((e=>wi(e.clone())))}
|
|
16261
|
+
function cV(e,t,n,s){if(Array.isArray(e)){if(null!=t||null!=n)throw new HP("When inputs is an array, neither initialState or constants should be provided");null!=s&&(n=e.slice(e.length-s,e.length),e=e.slice(0,e.length-s)),e.length>1&&(t=e.slice(1,e.length)),e=e[0]}function r(e){return null==e||Array.isArray(e)?e:[e]}return{inputs:e,initialState:t=r(t),constants:n=r(n)}}function hV(e,t,n,s=!1,r,a,i=!1,o=!1){return bi((()=>{const a=t.shape.length;if(a<3)throw new HP(`Input should be at least 3D, but is ${a}D.`);const u=[1,0].concat(Pz(2,a));t=ed(t,u),i&&console.warn("Backend rnn(): the unroll = true option is not applicable to the imperative deeplearn.js backend."),null!=r&&((r=vo(vo(r,"bool"),"float32")).rank===a-1&&(r=kl(r,-1)),r=ed(r,u)),s&&(t=lh(t,0),null!=r&&(r=lh(r,0)));const l=[];let c,h=n;const d=t.shape[0],p=Kh(t);let f,m;null!=r&&(f=Kh(r));for(let t=0;t<d;++t){const n=p[t],s=bi((()=>e(n,h)));if(null==r)c=s[0],h=s[1];else{const e=bi((()=>{const e=f[t],n=Vl(pc(e),e),r=Co($o(s[0],e),$o(h[0],n)),a=h.map(((t,r)=>Co($o(s[1][r],e),$o(t,n))));return{output:r,newStates:a}}));c=e.output,h=e.newStates}o&&l.push(c)}if(o){m=Dh(l,1)}return[c,m,h]}))}lV.className="DepthwiseConv2D",Cp(lV);class dV extends zB{constructor(e){let t;if(super(e),null==e.cell)throw new HP("cell property is missing for the constructor of RNN.");if(t=Array.isArray(e.cell)?new wV({cells:e.cell}):e.cell,null==t.stateSize)throw new HP("The RNN cell should have an attribute `stateSize` (tuple of integers, one integer per RNN state).");this.cell=t,this.returnSequences=null!=e.returnSequences&&e.returnSequences,this.returnState=null!=e.returnState&&e.returnState,this.goBackwards=null!=e.goBackwards&&e.goBackwards,this._stateful=null!=e.stateful&&e.stateful,this.unroll=null!=e.unroll&&e.unroll,this.supportsMasking=!0,this.inputSpec=[new DB({ndim:3})],this.stateSpec=null,this.states_=null,this.numConstants=null,this.keptStates=[]}getStates(){if(null==this.states_){return Pz(0,Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1).map((e=>null))}return this.states_}setStates(e){this.states_=e}computeOutputShape(e){CB(e)&&(e=e[0]);let t=this.cell.stateSize;Array.isArray(t)||(t=[t]);const n=t[0];let s;if(s=this.returnSequences?[e[0],e[1],n]:[e[0],n],this.returnState){const n=[];for(const s of t)n.push([e[0],s]);return[s].concat(n)}return s}computeMask(e,t){return bi((()=>{Array.isArray(t)&&(t=t[0]);const e=this.returnSequences?t:null;if(this.returnState){const t=this.states.map((e=>null));return[e].concat(t)}return e}))}get states(){if(null==this.states_){const e=Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1,t=[];for(let n=0;n<e;++n)t.push(null);return t}return this.states_}set states(e){this.states_=e}build(e){if(null!=this.numConstants)throw new qP("Constants support is not implemented in RNN yet.");CB(e)&&(e=e[0]);const t=this.stateful?e[0]:null,n=e.slice(2);this.inputSpec[0]=new DB({shape:[t,null,...n]});const s=[e[0]].concat(e.slice(2));let r;if(this.cell.build(s),r=Array.isArray(this.cell.stateSize)?this.cell.stateSize:[this.cell.stateSize],null!=this.stateSpec){if(!we(this.stateSpec.map((e=>e.shape[e.shape.length-1])),r))throw new HP(`An initialState was passed that is not compatible with cell.stateSize. Received stateSpec=${this.stateSpec}; However cell.stateSize is ${this.cell.stateSize}`)}else this.stateSpec=r.map((e=>new DB({shape:[null,e]})));this.stateful&&this.resetStates()}resetStates(e,t=!1){bi((()=>{if(!this.stateful)throw new VP("Cannot call resetStates() on an RNN Layer that is not stateful.");const n=this.inputSpec[0].shape[0];if(null==n)throw new HP("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");if(null==this.states_)Array.isArray(this.cell.stateSize)?this.states_=this.cell.stateSize.map((e=>sc([n,e]))):this.states_=[sc([n,this.cell.stateSize])];else if(null==e)xi(this.states_),null!=this.keptStates&&(xi(this.keptStates),this.keptStates=[]),Array.isArray(this.cell.stateSize)?this.states_=this.cell.stateSize.map((e=>sc([n,e]))):this.states_[0]=sc([n,this.cell.stateSize]);else{if(Array.isArray(e)||(e=[e]),e.length!==this.states_.length)throw new HP(`Layer ${this.name} expects ${this.states_.length} state(s), but it received ${e.length} state value(s). Input received: ${e}`);!0===t?this.keptStates.push(this.states_.slice()):xi(this.states_);for(let t=0;t<this.states_.length;++t){const s=e[t],r=Array.isArray(this.cell.stateSize)?this.cell.stateSize[t]:this.cell.stateSize,a=[n,r];if(!we(s.shape,a))throw new HP(`State ${t} is incompatible with layer ${this.name}: expected shape=${a}, received shape=${s.shape}`);this.states_[t]=s}}this.states_=this.states_.map((e=>wi(e.clone())))}))}apply(e,t){let n=null==t?null:t.initialState,s=null==t?null:t.constants;null==t&&(t={});const r=cV(e,n,s,this.numConstants);e=r.inputs,n=r.initialState,s=r.constants;let a=[],i=[];if(null!=n){t.initialState=n,a=a.concat(n),this.stateSpec=[];for(const e of n)this.stateSpec.push(new DB({shape:e.shape}));i=i.concat(this.stateSpec)}null!=s&&(t.constants=s,a=a.concat(s),this.numConstants=s.length);if(a[0]instanceof MB){const n=[e].concat(a),s=this.inputSpec.concat(i),r=this.inputSpec;this.inputSpec=s;const o=super.apply(n,t);return this.inputSpec=r,o}return super.apply(e,t)}call(e,t){return bi((()=>{const n=null==t?null:t.mask,s=null==t?null:t.training;let r=null==t?null:t.initialState;e=TB(e),null==r&&(r=this.stateful?this.states_:this.getInitialState(e));const a=Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1;if(r.length!==a)throw new HP(`RNN Layer has ${a} state(s) but was passed ${r.length} initial state(s).`);this.unroll&&console.warn("Ignoring unroll = true for RNN layer, due to imperative backend.");const i={training:s},o=hV(((e,t)=>{const n=this.cell.call([e].concat(t),i);return[n[0],n.slice(1)]}),e,r,this.goBackwards,n,0,this.unroll,this.returnSequences),u=o[0],l=o[1],c=o[2];this.stateful&&this.resetStates(c,s);const h=this.returnSequences?l:u;return this.returnState?[h].concat(c):h}))}getInitialState(e){return bi((()=>{let t=sc(e.shape);return t=gl(t,[1,2]),t=Uz(t),Array.isArray(this.cell.stateSize)?this.cell.stateSize.map((e=>e>1?Xz(t,[1,e]):t)):this.cell.stateSize>1?[Xz(t,[1,this.cell.stateSize])]:[t]}))}get trainableWeights(){return this.trainable?this.cell.trainableWeights:[]}get nonTrainableWeights(){return this.trainable?this.cell.nonTrainableWeights:this.cell.weights}setFastWeightInitDuringBuild(e){super.setFastWeightInitDuringBuild(e),null!=this.cell&&this.cell.setFastWeightInitDuringBuild(e)}getConfig(){const e=super.getConfig(),t={returnSequences:this.returnSequences,returnState:this.returnState,goBackwards:this.goBackwards,stateful:this.stateful,unroll:this.unroll};null!=this.numConstants&&(t.numConstants=this.numConstants);const n=this.cell.getConfig();return this.getClassName()===dV.className&&(t.cell={className:this.cell.getClassName(),config:n}),Object.assign(Object.assign(Object.assign({},n),e),t)}static fromConfig(e,t,n={}){const s=gW(t.cell,n);return new e(Object.assign(t,{cell:s}))}}dV.className="RNN",Cp(dV);class pV extends zB{}class fV extends pV{constructor(e){super(e),this.DEFAULT_ACTIVATION="tanh",this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_RECURRENT_INITIALIZER="orthogonal",this.DEFAULT_BIAS_INITIALIZER="zeros",this.units=e.units,hz(this.units,"units"),this.activation=FU(null==e.activation?this.DEFAULT_ACTIVATION:e.activation),this.useBias=null==e.useBias||e.useBias,this.kernelInitializer=SB(e.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.recurrentInitializer=SB(e.recurrentInitializer||this.DEFAULT_RECURRENT_INITIALIZER),this.biasInitializer=SB(e.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.kernelRegularizer=zU(e.kernelRegularizer),this.recurrentRegularizer=zU(e.recurrentRegularizer),this.biasRegularizer=zU(e.biasRegularizer),this.kernelConstraint=rW(e.kernelConstraint),this.recurrentConstraint=rW(e.recurrentConstraint),this.biasConstraint=rW(e.biasConstraint),this.dropout=Oz([1,Lz([0,null==e.dropout?0:e.dropout])]),this.recurrentDropout=Oz([1,Lz([0,null==e.recurrentDropout?0:e.recurrentDropout])]),this.dropoutFunc=e.dropoutFunc,this.stateSize=this.units,this.dropoutMask=null,this.recurrentDropoutMask=null}build(e){e=$B(e),this.kernel=this.addWeight("kernel",[e[e.length-1],this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0}call(e,t){return bi((()=>{if(2!==e.length)throw new HP(`SimpleRNNCell expects 2 input Tensors, got ${e.length}.`);let n=e[1];e=e[0];const s=null!=t.training&&t.training;let r;0<this.dropout&&this.dropout<1&&null==this.dropoutMask&&(this.dropoutMask=kV({ones:()=>pc(e),rate:this.dropout,training:s,dropoutFunc:this.dropoutFunc})),0<this.recurrentDropout&&this.recurrentDropout<1&&null==this.recurrentDropoutMask&&(this.recurrentDropoutMask=kV({ones:()=>pc(n),rate:this.recurrentDropout,training:s,dropoutFunc:this.dropoutFunc}));const a=this.dropoutMask,i=this.recurrentDropoutMask;r=Yz(null!=a?$o(e,a):e,this.kernel.read()),null!=this.bias&&(r=eB(r,this.bias.read())),null!=i&&(n=$o(n,i));let o=Co(r,Yz(n,this.recurrentKernel.read()));return null!=this.activation&&(o=this.activation.apply(o)),[o,o]}))}getConfig(){const e=super.getConfig(),t={units:this.units,activation:AU(this.activation),useBias:this.useBias,kernelInitializer:IB(this.kernelInitializer),recurrentInitializer:IB(this.recurrentInitializer),biasInitializer:IB(this.biasInitializer),kernelRegularizer:LU(this.kernelRegularizer),recurrentRegularizer:LU(this.recurrentRegularizer),biasRegularizer:LU(this.biasRegularizer),activityRegularizer:LU(this.activityRegularizer),kernelConstraint:nW(this.kernelConstraint),recurrentConstraint:nW(this.recurrentConstraint),biasConstraint:nW(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout};return Object.assign(Object.assign({},e),t)}}fV.className="SimpleRNNCell",Cp(fV);class mV extends dV{constructor(e){e.cell=new fV(e),super(e)}call(e,t){return bi((()=>{null!=this.cell.dropoutMask&&(xi(this.cell.dropoutMask),this.cell.dropoutMask=null),null!=this.cell.recurrentDropoutMask&&(xi(this.cell.recurrentDropoutMask),this.cell.recurrentDropoutMask=null);const n=null==t?null:t.mask,s=null==t?null:t.training,r=null==t?null:t.initialState;return super.call(e,{mask:n,training:s,initialState:r})}))}static fromConfig(e,t){return new e(t)}}mV.className="SimpleRNN",Cp(mV);class gV extends pV{constructor(e){if(super(e),this.DEFAULT_ACTIVATION="tanh",this.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_RECURRENT_INITIALIZER="orthogonal",this.DEFAULT_BIAS_INITIALIZER="zeros",e.resetAfter)throw new HP("GRUCell does not support reset_after parameter set to true.");this.units=e.units,hz(this.units,"units"),this.activation=FU(void 0===e.activation?this.DEFAULT_ACTIVATION:e.activation),this.recurrentActivation=FU(void 0===e.recurrentActivation?this.DEFAULT_RECURRENT_ACTIVATION:e.recurrentActivation),this.useBias=null==e.useBias||e.useBias,this.kernelInitializer=SB(e.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.recurrentInitializer=SB(e.recurrentInitializer||this.DEFAULT_RECURRENT_INITIALIZER),this.biasInitializer=SB(e.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.kernelRegularizer=zU(e.kernelRegularizer),this.recurrentRegularizer=zU(e.recurrentRegularizer),this.biasRegularizer=zU(e.biasRegularizer),this.kernelConstraint=rW(e.kernelConstraint),this.recurrentConstraint=rW(e.recurrentConstraint),this.biasConstraint=rW(e.biasConstraint),this.dropout=Oz([1,Lz([0,null==e.dropout?0:e.dropout])]),this.recurrentDropout=Oz([1,Lz([0,null==e.recurrentDropout?0:e.recurrentDropout])]),this.dropoutFunc=e.dropoutFunc,this.implementation=e.implementation,this.stateSize=this.units,this.dropoutMask=null,this.recurrentDropoutMask=null}build(e){const t=(e=$B(e))[e.length-1];this.kernel=this.addWeight("kernel",[t,3*this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,3*this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[3*this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0}call(e,t){return bi((()=>{if(2!==e.length)throw new HP(`GRUCell expects 2 input Tensors (inputs, h, c), got ${e.length}.`);const n=null!=t.training&&t.training;let s=e[1];e=e[0],0<this.dropout&&this.dropout<1&&null==this.dropoutMask&&(this.dropoutMask=kV({ones:()=>pc(e),rate:this.dropout,training:n,count:3,dropoutFunc:this.dropoutFunc})),0<this.recurrentDropout&&this.recurrentDropout<1&&null==this.recurrentDropoutMask&&(this.recurrentDropoutMask=kV({ones:()=>pc(s),rate:this.recurrentDropout,training:n,count:3,dropoutFunc:this.dropoutFunc}));const r=this.dropoutMask,a=this.recurrentDropoutMask;let i,o,u;0<this.dropout&&this.dropout<1&&(e=$o(e,r[0]));let l=Yz(e,this.kernel.read());this.useBias&&(l=eB(l,this.bias.read())),0<this.recurrentDropout&&this.recurrentDropout<1&&(s=$o(s,a[0]));const c=this.recurrentKernel.read(),[h,d]=Eh(c,[2*this.units,this.units],c.rank-1),p=Yz(s,h),[f,m,g]=Eh(l,3,l.rank-1),[y,b]=Eh(p,2,p.rank-1);i=this.recurrentActivation.apply(Co(f,y)),o=this.recurrentActivation.apply(Co(m,b));const x=Yz($o(o,s),d);u=this.activation.apply(Co(g,x));const w=Co($o(i,s),$o(Co(1,Bl(i)),u));return[w,w]}))}getConfig(){const e=super.getConfig(),t={units:this.units,activation:AU(this.activation),recurrentActivation:AU(this.recurrentActivation),useBias:this.useBias,kernelInitializer:IB(this.kernelInitializer),recurrentInitializer:IB(this.recurrentInitializer),biasInitializer:IB(this.biasInitializer),kernelRegularizer:LU(this.kernelRegularizer),recurrentRegularizer:LU(this.recurrentRegularizer),biasRegularizer:LU(this.biasRegularizer),activityRegularizer:LU(this.activityRegularizer),kernelConstraint:nW(this.kernelConstraint),recurrentConstraint:nW(this.recurrentConstraint),biasConstraint:nW(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation,resetAfter:!1};return Object.assign(Object.assign({},e),t)}}gV.className="GRUCell",Cp(gV);class yV extends dV{constructor(e){0===e.implementation&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),e.cell=new gV(e),super(e)}call(e,t){return bi((()=>{null!=this.cell.dropoutMask&&(xi(this.cell.dropoutMask),this.cell.dropoutMask=null),null!=this.cell.recurrentDropoutMask&&(xi(this.cell.recurrentDropoutMask),this.cell.recurrentDropoutMask=null);const n=null==t?null:t.mask,s=null==t?null:t.training,r=null==t?null:t.initialState;return super.call(e,{mask:n,training:s,initialState:r})}))}static fromConfig(e,t){return 0===t.implmentation&&(t.implementation=1),new e(t)}}yV.className="GRU",Cp(yV);class bV extends pV{constructor(e){super(e),this.DEFAULT_ACTIVATION="tanh",this.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_RECURRENT_INITIALIZER="orthogonal",this.DEFAULT_BIAS_INITIALIZER="zeros",this.units=e.units,hz(this.units,"units"),this.activation=FU(void 0===e.activation?this.DEFAULT_ACTIVATION:e.activation),this.recurrentActivation=FU(void 0===e.recurrentActivation?this.DEFAULT_RECURRENT_ACTIVATION:e.recurrentActivation),this.useBias=null==e.useBias||e.useBias,this.kernelInitializer=SB(e.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.recurrentInitializer=SB(e.recurrentInitializer||this.DEFAULT_RECURRENT_INITIALIZER),this.biasInitializer=SB(e.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.unitForgetBias=e.unitForgetBias,this.kernelRegularizer=zU(e.kernelRegularizer),this.recurrentRegularizer=zU(e.recurrentRegularizer),this.biasRegularizer=zU(e.biasRegularizer),this.kernelConstraint=rW(e.kernelConstraint),this.recurrentConstraint=rW(e.recurrentConstraint),this.biasConstraint=rW(e.biasConstraint),this.dropout=Oz([1,Lz([0,null==e.dropout?0:e.dropout])]),this.recurrentDropout=Oz([1,Lz([0,null==e.recurrentDropout?0:e.recurrentDropout])]),this.dropoutFunc=e.dropoutFunc,this.implementation=e.implementation,this.stateSize=[this.units,this.units],this.dropoutMask=null,this.recurrentDropoutMask=null}build(e){var t;const n=(e=$B(e))[e.length-1];let s;if(this.kernel=this.addWeight("kernel",[n,4*this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,4*this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias){if(this.unitForgetBias){const e=this.biasInitializer,n=this.units;s=new((t=class extends aB{apply(t,s){const r=e.apply([n]),a=(new oB).apply([n]),i=e.apply([2*n]);return jz(jz(r,a),i)}}).className="CustomInit",t)}else s=this.biasInitializer;this.bias=this.addWeight("bias",[4*this.units],null,s,this.biasRegularizer,!0,this.biasConstraint)}else this.bias=null;this.built=!0}call(e,t){return bi((()=>{const n=null!=t.training&&t.training;if(3!==e.length)throw new HP(`LSTMCell expects 3 input Tensors (inputs, h, c), got ${e.length}.`);let s=e[1];const r=e[2];e=e[0],0<this.dropout&&this.dropout<1&&null==this.dropoutMask&&(this.dropoutMask=kV({ones:()=>pc(e),rate:this.dropout,training:n,count:4,dropoutFunc:this.dropoutFunc})),0<this.recurrentDropout&&this.recurrentDropout<1&&null==this.recurrentDropoutMask&&(this.recurrentDropoutMask=kV({ones:()=>pc(s),rate:this.recurrentDropout,training:n,count:4,dropoutFunc:this.dropoutFunc}));const a=this.dropoutMask,i=this.recurrentDropoutMask;let o,u,l,c;0<this.dropout&&this.dropout<1&&(e=$o(e,a[0]));let h=Yz(e,this.kernel.read());0<this.recurrentDropout&&this.recurrentDropout<1&&(s=$o(s,i[0])),h=Co(h,Yz(s,this.recurrentKernel.read())),this.useBias&&(h=eB(h,this.bias.read()));const[d,p,f,m]=Eh(h,4,h.rank-1);o=this.recurrentActivation.apply(d),u=this.recurrentActivation.apply(p),l=Co($o(u,r),$o(o,this.activation.apply(f))),c=this.recurrentActivation.apply(m);const g=$o(c,this.activation.apply(l));return[g,g,l]}))}getConfig(){const e=super.getConfig(),t={units:this.units,activation:AU(this.activation),recurrentActivation:AU(this.recurrentActivation),useBias:this.useBias,kernelInitializer:IB(this.kernelInitializer),recurrentInitializer:IB(this.recurrentInitializer),biasInitializer:IB(this.biasInitializer),unitForgetBias:this.unitForgetBias,kernelRegularizer:LU(this.kernelRegularizer),recurrentRegularizer:LU(this.recurrentRegularizer),biasRegularizer:LU(this.biasRegularizer),activityRegularizer:LU(this.activityRegularizer),kernelConstraint:nW(this.kernelConstraint),recurrentConstraint:nW(this.recurrentConstraint),biasConstraint:nW(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation};return Object.assign(Object.assign({},e),t)}}bV.className="LSTMCell",Cp(bV);class xV extends dV{constructor(e){0===e.implementation&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),e.cell=new bV(e),super(e)}call(e,t){return bi((()=>{null!=this.cell.dropoutMask&&(xi(this.cell.dropoutMask),this.cell.dropoutMask=null),null!=this.cell.recurrentDropoutMask&&(xi(this.cell.recurrentDropoutMask),this.cell.recurrentDropoutMask=null);const n=null==t?null:t.mask,s=null==t?null:t.training,r=null==t?null:t.initialState;return super.call(e,{mask:n,training:s,initialState:r})}))}static fromConfig(e,t){return 0===t.implmentation&&(t.implementation=1),new e(t)}}xV.className="LSTM",Cp(xV);class wV extends pV{constructor(e){super(e),this.cells=e.cells}get stateSize(){const e=[];for(const t of this.cells.slice().reverse())Array.isArray(t.stateSize)?e.push(...t.stateSize):e.push(t.stateSize);return e}call(e,t){return bi((()=>{let n=e.slice(1);const s=[];for(const e of this.cells.slice().reverse())Array.isArray(e.stateSize)?s.push(n.splice(0,e.stateSize.length)):s.push(n.splice(0,1));s.reverse();const r=[];let a;for(let i=0;i<this.cells.length;++i){const o=this.cells[i];n=s[i],a=0===i?[e[0]].concat(n):[a[0]].concat(n),a=o.call(a,t),r.push(a.slice(1))}n=[];for(const e of r.slice().reverse())n.push(...e);return[a[0]].concat(n)}))}build(e){let t;CB(e)&&(e=e[0]),this.cells.forEach(((n,s)=>{Rz(`RNNCell_${s}`,(()=>{n.build(e),t=Array.isArray(n.stateSize)?n.stateSize[0]:n.stateSize,e=[e[0],t]}))})),this.built=!0}getConfig(){const e=super.getConfig(),t={cells:this.cells.map((e=>({className:e.getClassName(),config:e.getConfig()})))};return Object.assign(Object.assign({},e),t)}static fromConfig(e,t,n={}){const s=[];for(const e of t.cells)s.push(gW(e,n));return new e({cells:s})}get trainableWeights(){if(!this.trainable)return[];const e=[];for(const t of this.cells)e.push(...t.trainableWeights);return e}get nonTrainableWeights(){const e=[];for(const t of this.cells)e.push(...t.nonTrainableWeights);if(!this.trainable){const t=[];for(const e of this.cells)t.push(...e.trainableWeights);return t.concat(e)}return e}getWeights(){const e=[];for(const t of this.cells)e.push(...t.weights);return _B(e)}setWeights(e){const t=[];for(const n of this.cells){const s=n.weights.length,r=e.splice(s);for(let e=0;e<n.weights.length;++e)t.push([n.weights[e],r[e]])}FB(t)}}function kV(e){const{ones:t,rate:n,training:s=!1,count:r=1,dropoutFunc:a}=e,i=()=>null!=a?a(t(),n):tB(t(),n),o=()=>nB(i,t,s);if(!r||r<=1)return wi(o().clone());return Array(r).fill(void 0).map(o).map((e=>wi(e.clone())))}
|
|
16262
16262
|
/**
|
|
16263
16263
|
* @license
|
|
16264
16264
|
* Copyright 2020 Google LLC
|
|
@@ -16267,7 +16267,7 @@ function uV(e,t,n,s){if(Array.isArray(e)){if(null!=t||null!=n)throw new HP("When
|
|
|
16267
16267
|
* license that can be found in the LICENSE file or at
|
|
16268
16268
|
* https://opensource.org/licenses/MIT.
|
|
16269
16269
|
* =============================================================================
|
|
16270
|
-
*/
|
|
16270
|
+
*/wV.className="StackedRNNCells",Cp(wV);var vV=function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(n[s[r]]=e[s[r]])}return n};class IV extends dV{constructor(e){if(e.unroll)throw new qP("Unrolling is not possible with convolutional RNNs.");if(Array.isArray(e.cell))throw new qP("It is not possible at the moment to stack convolutional cells.");super(e),this.inputSpec=[new DB({ndim:5})]}call(e,t){return bi((()=>{if(null!=this.cell.dropoutMask&&(xi(this.cell.dropoutMask),this.cell.dropoutMask=null),null!=this.cell.recurrentDropoutMask&&(xi(this.cell.recurrentDropoutMask),this.cell.recurrentDropoutMask=null),t&&t.constants)throw new HP("ConvRNN2D cell does not support constants");const n=null==t?null:t.mask,s=null==t?null:t.training,r=null==t?null:t.initialState;return super.call(e,{mask:n,training:s,initialState:r})}))}computeOutputShape(e){let t=this.computeSingleOutputShape(e);return this.returnSequences||(t=[t[0],...t.slice(2)]),this.returnState&&(t=[t,...Array(2).fill([e[0],...t.slice(-3)])]),t}getInitialState(e){return bi((()=>{const{stateSize:t}=this.cell,n=e.shape,s=this.computeSingleOutputShape(n),r=sc([s[0],...s.slice(2)]);return Array.isArray(t)?Array(t.length).fill(r):[r]}))}resetStates(e,t=!1){bi((()=>{if(!this.stateful)throw new VP("Cannot call resetStates() on an RNN Layer that is not stateful.");const n=this.inputSpec[0].shape,s=this.computeSingleOutputShape(n),r=[s[0],...s.slice(2)];if(null==n[0])throw new HP("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");if(null==this.getStates())Array.isArray(this.cell.stateSize)?this.states_=this.cell.stateSize.map((()=>sc(r))):this.states_=[sc(r)];else if(null==e)xi(this.states_),null!=this.keptStates&&(xi(this.keptStates),this.keptStates=[]),Array.isArray(this.cell.stateSize)?this.states_=this.cell.stateSize.map((()=>sc(r))):this.states_[0]=sc(r);else{if(Array.isArray(e)||(e=[e]),e.length!==this.states_.length)throw new HP(`Layer ${this.name} expects ${this.states_.length} state(s), but it received ${e.length} state value(s). Input received: ${e}`);t?this.keptStates.push(this.states_.slice()):xi(this.states_);for(let t=0;t<this.states_.length;++t){const n=e[t],s=r;if(!we(n.shape,s))throw new HP(`State ${t} is incompatible with layer ${this.name}: expected shape=${s}, received shape=${n.shape}`);this.states_[t]=n}}this.states_=this.states_.map((e=>wi(e.clone())))}))}computeSingleOutputShape(e){const{dataFormat:t,filters:n,kernelSize:s,padding:r,strides:a,dilationRate:i}=this.cell,o="channelsFirst"===t,u=e[o?3:2],l=e[o?4:3],c=jU(u,s[0],r,a[0],i[0]),h=jU(l,s[1],r,a[1],i[1]);return[...e.slice(0,2),...o?[n,c,h]:[c,h,n]]}}IV.className="ConvRNN2D";class SV extends bV{constructor(e){const{filters:t,kernelSize:n,strides:s,padding:r,dataFormat:a,dilationRate:i}=e;super(Object.assign(Object.assign({},e),{units:t})),this.filters=t,hz(this.filters,"filters"),this.kernelSize=qU(n,2,"kernelSize"),this.kernelSize.forEach((e=>hz(e,"kernelSize"))),this.strides=qU(s||1,2,"strides"),this.strides.forEach((e=>hz(e,"strides"))),this.padding=r||"valid",Cz(this.padding),this.dataFormat=a||"channelsLast",Sz(this.dataFormat),this.dilationRate=qU(i||1,2,"dilationRate"),this.dilationRate.forEach((e=>hz(e,"dilationRate")))}build(e){var t;e=$B(e);const n="channelsFirst"===this.dataFormat?1:e.length-1;if(null==e[n])throw new HP(`The channel dimension of the input should be defined. Found ${e[n]}`);const s=e[n],r=this.kernelSize.concat([s,4*this.filters]);this.kernel=this.addWeight("kernel",r,null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint);const a=this.kernelSize.concat([this.filters,4*this.filters]);if(this.recurrentKernel=this.addWeight("recurrent_kernel",a,null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias){let e;if(this.unitForgetBias){const n=this.biasInitializer,s=this.filters;e=new((t=class extends aB{apply(e,t){return qz([n.apply([s]),rc([s]),n.apply([2*s])])}}).className="CustomInit",t)}else e=this.biasInitializer;this.bias=this.addWeight("bias",[4*this.filters],null,e,this.biasRegularizer,!0,this.biasConstraint)}this.built=!0}call(e,t){return bi((()=>{if(3!==e.length)throw new HP(`ConvLSTM2DCell expects 3 input Tensors (inputs, h, c), got ${e.length}.`);const n=t.training||!1,s=e[0],r=e[1],a=e[2];0<this.dropout&&this.dropout<1&&null==this.dropoutMask&&(this.dropoutMask=kV({ones:()=>pc(s),rate:this.dropout,training:n,count:4,dropoutFunc:this.dropoutFunc}));const i=this.dropoutMask,o=(e,t,n)=>t&&t[n]?$o(t[n],e):e;let u=o(s,i,0),l=o(s,i,1),c=o(s,i,2),h=o(s,i,3);0<this.recurrentDropout&&this.recurrentDropout<1&&null==this.recurrentDropoutMask&&(this.recurrentDropoutMask=kV({ones:()=>pc(r),rate:this.recurrentDropout,training:n,count:4,dropoutFunc:this.dropoutFunc}));const d=this.recurrentDropoutMask;let p=o(r,d,0),f=o(r,d,1),m=o(r,d,2),g=o(r,d,3);const[y,b,x,w]=Eh(this.kernel.read(),4,3),[k,v,I,S]=this.useBias?Eh(this.bias.read(),4):[null,null,null,null];u=this.inputConv(u,y,k,this.padding),l=this.inputConv(l,b,v,this.padding),c=this.inputConv(c,x,I,this.padding),h=this.inputConv(h,w,S,this.padding);const[C,N,T,$]=Eh(this.recurrentKernel.read(),4,3);p=this.recurrentConv(p,C),f=this.recurrentConv(f,N),m=this.recurrentConv(m,T),g=this.recurrentConv(g,$);const R=this.recurrentActivation.apply(Co(u,p)),E=this.recurrentActivation.apply(Co(l,f)),A=Co($o(E,a),$o(R,this.activation.apply(Co(c,m)))),_=$o(this.recurrentActivation.apply(Co(h,g)),this.activation.apply(A));return[_,_,A]}))}getConfig(){const e=super.getConfig(),t=vV(e,["units"]),n={filters:this.filters,kernelSize:this.kernelSize,padding:this.padding,dataFormat:this.dataFormat,dilationRate:this.dilationRate,strides:this.strides};return Object.assign(Object.assign({},t),n)}inputConv(e,t,n,s){const r=$u(e,t,this.strides,s||"valid","channelsFirst"===this.dataFormat?"NCHW":"NHWC",this.dilationRate);return n?eB(r,n,this.dataFormat):r}recurrentConv(e,t){return $u(e,t,1,"same","channelsFirst"===this.dataFormat?"NCHW":"NHWC")}}SV.className="ConvLSTM2DCell",Cp(SV);class CV extends IV{constructor(e){const t=new SV(e);super(Object.assign(Object.assign({},e),{cell:t}))}static fromConfig(e,t){return new e(t)}}CV.className="ConvLSTM2D",Cp(CV);
|
|
16271
16271
|
/**
|
|
16272
16272
|
* @license
|
|
16273
16273
|
* Copyright 2018 Google LLC
|
|
@@ -16277,7 +16277,7 @@ function uV(e,t,n,s){if(Array.isArray(e)){if(null!=t||null!=n)throw new HP("When
|
|
|
16277
16277
|
* https://opensource.org/licenses/MIT.
|
|
16278
16278
|
* =============================================================================
|
|
16279
16279
|
*/
|
|
16280
|
-
class
|
|
16280
|
+
class NV extends zB{constructor(e){super(e),this.rate=Math.max(Math.min(e.rate,1),0),this.noiseShape=e.noiseShape,this.seed=e.seed,this.supportsMasking=!0}getNoiseShape(e){if(null==this.noiseShape)return this.noiseShape;const t=e.shape,n=[];for(let e=0;e<this.noiseShape.length;++e)n.push(null==this.noiseShape[e]?t[e]:this.noiseShape[e]);return n}call(e,t){return bi((()=>{this.invokeCallHook(e,t);const n=TB(e);if(0<this.rate&&this.rate<1){const e=null!=t.training&&t.training,s=this.getNoiseShape(n);return nB((()=>tB(n,this.rate,s,this.seed)),(()=>n),e)}return e}))}getConfig(){const e={rate:this.rate,noiseShape:this.noiseShape,seed:this.seed},t=super.getConfig();return Object.assign(e,t),e}dispose(){return super.dispose()}}NV.className="Dropout",Cp(NV);class TV extends NV{constructor(e){super(e),this.inputSpec=[{ndim:3}]}getNoiseShape(e){const t=e.shape;return[t[0],1,t[2]]}}TV.className="SpatialDropout1D",Cp(TV);class $V extends zB{constructor(e){if(super(e),this.activation=null,this.useBias=!0,this.kernel=null,this.bias=null,this.DEFAULT_KERNEL_INITIALIZER="glorotNormal",this.DEFAULT_BIAS_INITIALIZER="zeros",null==e.batchInputShape&&null==e.inputShape&&null!=e.inputDim){let t=null;null!=e.batchSize&&(t=e.batchSize),this.batchInputShape=[t,e.inputDim]}this.units=e.units,hz(this.units,"units"),this.activation=FU(e.activation),null!=e.useBias&&(this.useBias=e.useBias),this.kernelInitializer=SB(e.kernelInitializer||this.DEFAULT_KERNEL_INITIALIZER),this.biasInitializer=SB(e.biasInitializer||this.DEFAULT_BIAS_INITIALIZER),this.kernelConstraint=rW(e.kernelConstraint),this.biasConstraint=rW(e.biasConstraint),this.kernelRegularizer=zU(e.kernelRegularizer),this.biasRegularizer=zU(e.biasRegularizer),this.activityRegularizer=zU(e.activityRegularizer),this.supportsMasking=!0,this.inputSpec=[{minNDim:2}]}build(e){const t=(e=$B(e))[e.length-1];null==this.kernel&&(this.kernel=this.addWeight("kernel",[t,this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint))),this.inputSpec=[{minNDim:2,axes:{[-1]:t}}],this.built=!0}computeOutputShape(e){const t=(e=$B(e)).slice();return t[t.length-1]=this.units,t}call(e,t){return bi((()=>{this.invokeCallHook(e,t);const n=TB(e),s=pz(this.activation.getClassName());let r;return null!=s?r=Yz(n,this.kernel.read(),s,this.bias?this.bias.read():null):(r=Yz(n,this.kernel.read()),null!=this.bias&&(r=eB(r,this.bias.read())),null!=this.activation&&(r=this.activation.apply(r))),r}))}getConfig(){const e={units:this.units,activation:AU(this.activation),useBias:this.useBias,kernelInitializer:IB(this.kernelInitializer),biasInitializer:IB(this.biasInitializer),kernelRegularizer:LU(this.kernelRegularizer),biasRegularizer:LU(this.biasRegularizer),activityRegularizer:LU(this.activityRegularizer),kernelConstraint:nW(this.kernelConstraint),biasConstraint:nW(this.biasConstraint)},t=super.getConfig();return Object.assign(e,t),e}}$V.className="Dense",Cp($V);class RV extends zB{constructor(e){super(e=e||{}),this.inputSpec=[{minNDim:3}],this.dataFormat=e.dataFormat}computeOutputShape(e){e=$B(e);for(const t of e.slice(1))if(null==t)throw new HP(`The shape of the input to "Flatten" is not fully defined (got ${e.slice(1)}). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.`);return[e[0],Mz(e,1)]}call(e,t){return bi((()=>{this.invokeCallHook(e,t);let n=TB(e);if("channelsFirst"===this.dataFormat&&n.rank>1){const e=[0];for(let t=2;t<n.rank;++t)e.push(t);e.push(1),n=ed(n,e)}return function(e){if(e.rank<=1)throw new HP(`batchFlatten requires a minimum rank of 2. Got rank: ${e.rank}.`);const t=[e.shape[0],Mz(e.shape,1)];return su(e,t)}(n)}))}getConfig(){const e={};null!=this.dataFormat&&(e.dataFormat=this.dataFormat);const t=super.getConfig();return Object.assign(e,t),e}}RV.className="Flatten",Cp(RV);class EV extends zB{constructor(e){super(e),this.supportsMasking=!0,this.activation=FU(e.activation)}call(e,t){return bi((()=>{this.invokeCallHook(e,t);const n=TB(e);return this.activation.apply(n)}))}getConfig(){const e={activation:AU(this.activation)},t=super.getConfig();return Object.assign(e,t),e}}EV.className="Activation",Cp(EV);class AV extends zB{constructor(e){super(e),this.n=e.n,this.inputSpec=[{ndim:2}]}computeOutputShape(e){return[e[0],this.n,e[1]]}call(e,t){return bi((()=>function(e,t){return bi((()=>{if(2!==e.shape.length)throw new HP(`repeat() expects a rank-2 tensor, but received a rank-${e.shape.length} tensor.`);return Xz(Uz(e,1),[1,t,1])}))}(e=TB(e),this.n)))}getConfig(){const e={n:this.n},t=super.getConfig();return Object.assign(e,t),e}}AV.className="RepeatVector",Cp(AV);class _V extends zB{constructor(e){super(e),this.targetShape=e.targetShape;for(let e=0;e<this.targetShape.length;++e)this.isUnknown(this.targetShape[e])&&(this.targetShape[e]=null)}isUnknown(e){return e<0||null==e}fixUnknownDimension(e,t){const n="Total size of new array must be unchanged.",s=t.slice();let r=1,a=null;for(let e=0;e<s.length;++e){const t=s[e];if(this.isUnknown(t)){if(null!==a)throw new HP("Can only specifiy one unknown dimension.");a=e}else r*=t}const i=Mz(e);if(null!==a){if(0===r||i%r!=0)throw new HP(n);s[a]=i/r}else if(i!==r)throw new HP(n);return s}computeOutputShape(e){let t=!1;for(let n=0;n<e.length;++n)if(this.isUnknown(e[n])){t=!0;break}return t?e.slice(0,1).concat(this.targetShape):e.slice(0,1).concat(this.fixUnknownDimension(e.slice(1),this.targetShape))}call(e,t){return bi((()=>{this.invokeCallHook(e,t);const n=TB(e),s=n.shape,r=s.slice(0,1).concat(this.fixUnknownDimension(s.slice(1),this.targetShape));return su(n,r)}))}getConfig(){const e={targetShape:this.targetShape},t=super.getConfig();return Object.assign(e,t),e}}_V.className="Reshape",Cp(_V);class FV extends zB{constructor(e){if(super(e),null==e.dims)throw new Error("Required configuration field `dims` is missing during Permute constructor call.");if(!Array.isArray(e.dims))throw new Error(`Permute constructor requires \`dims\` to be an Array, but received ${e.dims} instead.`);const t=Pz(1,e.dims.length+1);if(!we(e.dims.slice().sort(),t))throw new Error("Invalid permutation `dims`: "+JSON.stringify(e.dims)+" `dims` must contain consecutive integers starting from 1.");this.dims=e.dims,this.dimsIncludingBatch=[0].concat(this.dims),this.inputSpec=[new DB({ndim:this.dims.length+1})]}computeOutputShape(e){const t=(e=$B(e)).slice();return this.dims.forEach(((n,s)=>{t[s+1]=e[n]})),t}call(e,t){return ed(TB(e),this.dimsIncludingBatch)}getConfig(){const e={dims:this.dims},t=super.getConfig();return Object.assign(e,t),e}}FV.className="Permute",Cp(FV);class DV extends zB{constructor(e){super(null==e?{}:e),this.supportsMasking=!0,this.maskValue=null!=e?null==e.maskValue?0:e.maskValue:0}computeOutputShape(e){return e}getConfig(){const e=super.getConfig(),t={maskValue:this.maskValue};return Object.assign(t,e),t}computeMask(e,t){const n=TB(e);return Do(hc(n,this.maskValue),-1)}call(e,t){return bi((()=>{this.invokeCallHook(e,t);const n=TB(e),s=Do(hc(n,this.maskValue),-1,!0);return $o(n,vo(s,n.dtype))}))}}DV.className="Masking",Cp(DV);
|
|
16281
16281
|
/**
|
|
16282
16282
|
* @license
|
|
16283
16283
|
* Copyright 2018 Google LLC
|
|
@@ -16287,7 +16287,7 @@ class SV extends zB{constructor(e){super(e),this.rate=Math.max(Math.min(e.rate,1
|
|
|
16287
16287
|
* https://opensource.org/licenses/MIT.
|
|
16288
16288
|
* =============================================================================
|
|
16289
16289
|
*/
|
|
16290
|
-
class
|
|
16290
|
+
class MV extends zB{constructor(e){if(super(e),this.embeddings=null,this.DEFAULT_EMBEDDINGS_INITIALIZER="randomUniform",null==e.batchInputShape&&null==e.inputShape){let t=null;null!=e.batchSize&&(t=e.batchSize),null==e.inputLength?this.batchInputShape=[t,null]:this.batchInputShape=[t].concat(ZP(e.inputLength))}this.inputDim=e.inputDim,hz(this.inputDim,"inputDim"),this.outputDim=e.outputDim,hz(this.outputDim,"outputDim"),this.embeddingsInitializer=SB(e.embeddingsInitializer||this.DEFAULT_EMBEDDINGS_INITIALIZER),this.embeddingsRegularizer=zU(e.embeddingsRegularizer),this.activityRegularizer=zU(e.activityRegularizer),this.embeddingsConstraint=rW(e.embeddingsConstraint),this.maskZero=e.maskZero,this.supportsMasking=e.maskZero,this.inputLength=e.inputLength}build(e){this.embeddings=this.addWeight("embeddings",[this.inputDim,this.outputDim],this.dtype,this.embeddingsInitializer,this.embeddingsRegularizer,!0,this.embeddingsConstraint),this.built=!0}warnOnIncompatibleInputShape(e){}computeMask(e,t){return bi((()=>this.maskZero?(e=TB(e),hc(e,Ku(e))):null))}computeOutputShape(e){if(e=$B(e),null==this.inputLength)return[...e,this.outputDim];const t=ZP(this.inputLength);if(t.length!==e.length-1)throw new HP(`"inputLength" is ${this.inputLength}, but received input shape has shape ${e}`);{let n=0;for(let s=0;s<t.length;++s){const r=t[s],a=e[s+1];if(null!=r&&null!=a&&r!==a)throw new HP(`"inputLength" is ${this.inputLength}, but received input shape has shape ${e}`);null==r&&(t[n]=a),n++}}return[e[0],...t,this.outputDim]}call(e,t){return bi((()=>{this.invokeCallHook(e,t);let n=TB(e);"int32"!==n.dtype&&(n=Wz(n,"int32"));const s=Qz(this.embeddings.read(),su(n,[n.size]));return su(s,$B(this.computeOutputShape(n.shape)))}))}getConfig(){const e={inputDim:this.inputDim,outputDim:this.outputDim,embeddingsInitializer:IB(this.embeddingsInitializer),embeddingsRegularizer:LU(this.embeddingsRegularizer),activityRegularizer:LU(this.activityRegularizer),embeddingsConstraint:nW(this.embeddingsConstraint),maskZero:this.maskZero,inputLength:this.inputLength},t=super.getConfig();return Object.assign(e,t),e}}MV.className="Embedding",Cp(MV);
|
|
16291
16291
|
/**
|
|
16292
16292
|
* @license
|
|
16293
16293
|
* Copyright 2018 Google LLC
|
|
@@ -16297,7 +16297,7 @@ class FV extends zB{constructor(e){if(super(e),this.embeddings=null,this.DEFAULT
|
|
|
16297
16297
|
* https://opensource.org/licenses/MIT.
|
|
16298
16298
|
* =============================================================================
|
|
16299
16299
|
*/
|
|
16300
|
-
class
|
|
16300
|
+
class OV extends zB{constructor(e){super(e||{}),this.supportsMasking=!0}mergeFunction(e){throw new qP}computeElementwiseOpOutputShape(e,t){if(null==e||null==t)return null;if(e.length<t.length)return this.computeElementwiseOpOutputShape(t,e);if(0===t.length)return e;const n=e.slice(0,e.length-t.length);for(let s=0;s<t.length;++s){const r=e[e.length-t.length+s],a=t[s];if(null==r||null==a||r<0||a<0)n.push(null);else if(1===r)n.push(a);else if(1===a)n.push(r);else{if(r!==a)throw new HP("Operands could not be broadcast together with shapes "+JSON.stringify(e)+" "+JSON.stringify(t));n.push(r)}}return n}build(e){if(Array.isArray(e)&&!Array.isArray(e[0])&&(e=[$B(e)]),e.length<2)throw new HP(`A merge layer should be called on an Array of at least 2 inputs. Got ${e.length} input(s).`);let t=[];for(const n of e)null!=n&&null!==n[0]&&t.push(n[0]);if(t=oz(t),t.length>1)throw new HP(`Can not merge tensors with different batch sizes. Got tensors with shapes: ${JSON.stringify(e)}.`);let n=null==e[0]?null:e[0].slice(1);for(let t=1;t<e.length;++t){const s=null==e[t]?null:e[t].slice(1);n=this.computeElementwiseOpOutputShape(n,s)}const s=e.map((e=>e.length));-1===e.indexOf(null)&&1===oz(s).length?this.reshapeRequired=!1:this.reshapeRequired=!0}call(e,t){return bi((()=>{if(this.reshapeRequired){const t=[],n=e.map((e=>e.rank));if(-1===n.indexOf(null)){const s=Lz(n);for(let n of e){const e=n.rank;for(let t=0;t<s-e;++t)n=Uz(n,1);t.push(n)}return this.mergeFunction(t)}{let n=!1;for(const s of e){const e=s.rank;if(null==e){const e=s.shape,r=e[0],a=e.slice(1).concat([r]);let i=su(s,[r].concat(Mz(e.slice(1))));i=ed(i,[1,0]),i=su(i,a),t.push(i),n=!0}else if(e>1){const r=Pz(1,e).concat([0]);t.push(ed(s,r)),n=!0}else t.push(s)}let s=this.mergeFunction(t);const r=s.rank;if(n)if(null==r){const e=s.shape,t=e[e.length-1],n=[t].concat(e.slice(0,e.length-1));s=su(ed(su(s,[-1,t]),[1,0]),n)}else if(r>1){const e=[r-1].concat(Pz(0,r-1));s=ed(s,e)}return s}}return this.mergeFunction(e)}))}computeOutputShape(e){let t;t=null==e[0]?null:e[0].slice(1);for(let n=1;n<e.length;++n){const s=null==e[n]?null:e[n].slice(1);t=this.computeElementwiseOpOutputShape(t,s)}let n=[];for(const t of e)null!=t&&null!==t[0]&&n.push(t[0]);return n=oz(n),t=1===n.length?n.concat(t):[null].concat(t),t}computeMask(e,t){return bi((()=>{if(null==t)return null;if(!Array.isArray(t))throw new HP("`mask` should be an Array");if(!Array.isArray(e))throw new HP("`inputs` should be an Array");if(t.length!==e.length)throw new HP(`The Array 'inputs' and 'mask' are expected to have the same length, but have different lengths (${e.length} vs ${t.length})`);if(t.every((e=>null==e)))return null;t=t.map((e=>null==e?e:kl(e,0)));let n=t[0];for(let e=1;e<t.length-1;++e)n=ql(n,t[e]);return n}))}}class LV extends OV{constructor(e){super(e)}mergeFunction(e){return bi((()=>{let t=e[0].clone();for(let n=1;n<e.length;++n)t=Co(t,e[n]);return t}))}}LV.className="Add",Cp(LV);class PV extends OV{constructor(e){super(e)}mergeFunction(e){return bi((()=>{let t=e[0].clone();for(let n=1;n<e.length;++n)t=$o(t,e[n]);return t}))}}PV.className="Multiply",Cp(PV);class zV extends OV{constructor(e){super(e)}mergeFunction(e){return bi((()=>{let t=e[0].clone();for(let n=1;n<e.length;++n)t=Co(t,e[n]);return $o(1/e.length,t)}))}}zV.className="Average",Cp(zV);class BV extends OV{constructor(e){super(e)}mergeFunction(e){return bi((()=>{let t=e[0];for(let n=1;n<e.length;++n)t=tc(t,e[n]);return t}))}}BV.className="Maximum",Cp(BV);class WV extends OV{constructor(e){super(e)}mergeFunction(e){return bi((()=>{let t=e[0];for(let n=1;n<e.length;++n)t=ac(t,e[n]);return t}))}}WV.className="Minimum",Cp(WV);class UV extends OV{constructor(e){super(e),this.DEFAULT_AXIS=-1,null==e&&(e={}),this.axis=null==e.axis?this.DEFAULT_AXIS:e.axis,this.supportsMasking=!0,this.reshapeRequired=!1}build(e){if(!Array.isArray(e)||!Array.isArray(e[0])||1===e.length)throw new HP("A `Concatenate` layer should be called on a list of at least 2 inputs");let t=!0;for(const n of e)if(null!=n){t=!1;break}if(t)return;const n=[];for(let t=0;t<e.length;++t){const s=e[t].slice();s.splice(this.axis,1);let r=!1;for(const e of n)if(we(e,s)){r=!0;break}r||n.push(s)}if(n.length>1)throw new HP("A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got input shapes: "+JSON.stringify(e))}mergeFunction(e){return bi((()=>qz(e,this.axis)))}computeOutputShape(e){if(!Array.isArray(e)||!Array.isArray(e[0]))throw new HP("A `Concatenate` layer should be called on a list of inputs.");const t=e,n=t[0].slice(),s=this.axis<0?n.length+this.axis:this.axis;for(const e of t.slice(1)){if(null==n[s]||null==e[s]){n[s]=null;break}n[s]+=e[s]}return n}computeMask(e,t){if(null==t)return null;if(!Array.isArray(t))throw new HP("`mask` should be an array for Concatenate");if(!Array.isArray(e))throw new HP("`inputs` should be an array for Concatenate");if(t.length!==e.length)throw new HP(`Mismatch in the length of mask (${t.length}) and the legnth of inputs (${e.length})`);return bi((()=>{let n=!0;if(t.forEach((e=>{null==e||(n=!1)})),n)return null;const s=[];for(let n=0;n<e.length;++n)null==t[n]?s.push(vo(pc(e[n]),"bool")):t[n].rank<e[n].rank?s.push(kl(t[n],-1)):s.push(t[n]);const r=iu(s,this.axis);return Fo(r,-1,!1)}))}getConfig(){const e={axis:this.axis},t=super.getConfig();return Object.assign(e,t),e}}function VV(e,t){for(;e<0;)e+=t;return e}UV.className="Concatenate",Cp(UV);class GV extends OV{constructor(e){super(e),this.axes=e.axes,this.normalize=null!=e.normalize&&e.normalize,this.supportsMasking=!0,this.reshapeRequired=!1}build(e){me(Array.isArray(e)&&2===e.length&&Array.isArray(e[0])&&Array.isArray(e[1]),(()=>"A `Dot` layer should be called on a list of exactly 2 inputs."));const t=e[0],n=e[1];if(t.length>3||n.length>3)throw new qP("Dot layer does not support tensors of 4D or higher rank yet.");const s=this.interpretAxes(t,n);if(t[s[0]]!==n[s[1]])throw new HP(`Dimension incompatibility: ${t[s[0]]} !== ${n[s[1]]}`)}mergeFunction(e){if(2!==e.length)throw new HP(`A \`Dot\` layer must be called on exactly 2 inputs, but received ${e.length} input(s).`);let t,n=e[0],s=e[1];return t=Array.isArray(this.axes)?this.axes.map(((t,n)=>VV(t,e[n].shape.length))):[VV(this.axes,n.shape.length),VV(this.axes,s.shape.length)],this.normalize&&(n=yW(n,t[0]),s=yW(s,t[1])),function(e,t,n){if(e.shape.length>3||t.shape.length>3)throw new qP("batchDot is not implemented for tensors of 4D or higher rank yet");if(me(e.shape.length>=2,(()=>`batchDot requires the rank of x to be >= 2, but got ${e.shape.length}`)),me(e.shape.length>=2,(()=>`batchDot requires the rank of y to be >= 2, but got ${t.shape.length}`)),"number"==typeof n&&(n=[n,n]),"complex64"===e.dtype||"complex64"===t.dtype)throw new qP("batchDot is not implemented for complex64-type Tensors yet.");const s=e.shape.length,r=t.shape.length;null==n&&(n=[s-1,r-2]);const a=n;return bi((()=>{let n,i;if(s>r){n=s-r;const e=[];for(let t=0;t<n;++t)e.push(1);t=su(t,t.shape.concat(e))}else if(r>s){n=r-s;const t=[];for(let e=0;e<n;++e)t.push(1);e=su(e,e.shape.concat(t))}else n=0;if(2===e.shape.length&&2===t.shape.length)i=a[0]===a[1]?gl($o(e,t),a[0]):gl($o(ed(e,[1,0]),t),a[1]);else{const n=a[0]!==e.shape.length-1,s=a[1]===t.shape.length-1;i=ou(e,t,n,s)}if(n>0){let e;e=s>r?s+r-3:s-1;const t=[];for(let s=e;s<e+n;++s)t.push(s);i=Fh(i,t)}return 1===i.shape.length&&(i=kl(i,1)),i}))}(n,s,t)}interpretAxes(e,t){let n;return n=Array.isArray(this.axes)?this.axes:[VV(this.axes,e.length),VV(this.axes,t.length)],n}computeOutputShape(e){me(Array.isArray(e)&&2===e.length&&Array.isArray(e[0])&&Array.isArray(e[1]),(()=>"A `Dot` layer should be called on a list of exactly 2 inputs."));const t=e[0].slice(),n=e[1].slice();if(t.length>3||n.length>3)throw new qP("Dot layer does not support tensors of 4D or higher rank yet.");const s=this.interpretAxes(t,n);t.splice(s[0],1),n.splice(s[1],1),n.splice(0,1);const r=t.concat(n);return 1===r.length&&r.push(1),r}computeMask(e,t){return null}getConfig(){const e={axes:this.axes,normalize:this.normalize},t=super.getConfig();return Object.assign(e,t),e}}GV.className="Dot",Cp(GV);
|
|
16301
16301
|
/**
|
|
16302
16302
|
* @license
|
|
16303
16303
|
* Copyright 2018 Google LLC
|
|
@@ -16307,7 +16307,7 @@ class DV extends zB{constructor(e){super(e||{}),this.supportsMasking=!0}mergeFun
|
|
|
16307
16307
|
* https://opensource.org/licenses/MIT.
|
|
16308
16308
|
* =============================================================================
|
|
16309
16309
|
*/
|
|
16310
|
-
class
|
|
16310
|
+
class HV extends zB{constructor(e){super(e),this.supportsMasking=!0,this.stddev=e.stddev}computeOutputShape(e){return e}getConfig(){const e=super.getConfig(),t={stddev:this.stddev};return Object.assign(t,e),t}call(e,t){return bi((()=>{this.invokeCallHook(e,t);const n=TB(e);return nB((()=>Co(Kz(n.shape,0,this.stddev),n)),(()=>n),t.training||!1)}))}}HV.className="GaussianNoise",Cp(HV);class qV extends zB{constructor(e){super(e),this.supportsMasking=!0,this.rate=e.rate}computeOutputShape(e){return e}getConfig(){const e=super.getConfig(),t={rate:this.rate};return Object.assign(t,e),t}call(e,t){return bi((()=>{this.invokeCallHook(e,t);const n=TB(e);if(this.rate>0&&this.rate<1){return nB((()=>{const e=Math.sqrt(this.rate/(1-this.rate));return $o(n,Kz(n.shape,1,e))}),(()=>n),t.training||!1)}return n}))}}qV.className="GaussianDropout",Cp(qV);class jV extends zB{constructor(e){super(e),this.supportsMasking=!0,this.rate=e.rate,this.noiseShape=e.noiseShape}_getNoiseShape(e){return this.noiseShape||TB(e).shape}computeOutputShape(e){return e}getConfig(){const e=super.getConfig(),t={rate:this.rate};return Object.assign(t,e),t}call(e,t){return bi((()=>{if(this.rate<1&&this.rate>0){const n=this._getNoiseShape(e),s=()=>{const t=TB(e),s=-1.7580993408473766;let r=$l(nh(n),this.rate);r=Wz(r,"float32");const a=((1-this.rate)*(1+this.rate*s**2))**-.5,i=-a*s*this.rate,o=Co($o(t,r),$o(Co(r,-1),s));return Co($o(o,a),i)};return nB(s,(()=>TB(e)),t.training||!1)}return e}))}}
|
|
16311
16311
|
/**
|
|
16312
16312
|
* @license
|
|
16313
16313
|
* Copyright 2018 Google LLC
|
|
@@ -16317,7 +16317,7 @@ class VV extends zB{constructor(e){super(e),this.supportsMasking=!0,this.stddev=
|
|
|
16317
16317
|
* https://opensource.org/licenses/MIT.
|
|
16318
16318
|
* =============================================================================
|
|
16319
16319
|
*/
|
|
16320
|
-
function
|
|
16320
|
+
function XV(e,t,n,s,r,a=.001){let i;if(2===e.rank)i=fu(e,t,n,s,r,a);else if(3===e.rank)i=mu(e,t,n,s,r,a);else{if(4!==e.rank)throw new qP(`batchNormalization is not implemented for array of rank ${e.rank} yet`);i=gu(e,t,n,s,r,a)}return i}function KV(e,t,n,s,r=.001){return we(s.slice().sort(),Pz(0,e.rank-1))?function(e,t,n,s,r=.001){return bi((()=>{const a=uc(e,s),i=a.mean,o=a.variance;return[XV(e,i,o,n,t,r),i,o]}))}(e,t,n,s,r):function(e,t,n,s,r=.001){return bi((()=>{const a=uc(e,s),i=a.mean,o=a.variance,u=[];for(const t of Pz(0,e.rank))-1!==s.indexOf(t)?u.push(1):u.push(e.shape[t]);const l=su(i,u),c=su(o,u),h=null==t?null:su(t,u),d=null==n?null:su(n,u);return[XV(e,l,c,d,h,r),i,o]}))}(e,t,n,s,r)}jV.className="AlphaDropout",Cp(jV);class YV extends zB{constructor(e){null==e&&(e={}),super(e),this.supportsMasking=!0,this.axis=null==e.axis?-1:e.axis,this.momentum=null==e.momentum?.99:e.momentum,this.epsilon=null==e.epsilon?.001:e.epsilon,this.center=null==e.center||e.center,this.scale=null==e.scale||e.scale,this.betaInitializer=SB(e.betaInitializer||"zeros"),this.gammaInitializer=SB(e.gammaInitializer||"ones"),this.movingMeanInitializer=SB(e.movingMeanInitializer||"zeros"),this.movingVarianceInitializer=SB(e.movingVarianceInitializer||"ones"),this.betaConstraint=rW(e.betaConstraint),this.gammaConstraint=rW(e.gammaConstraint),this.betaRegularizer=zU(e.betaRegularizer),this.gammaRegularizer=zU(e.gammaRegularizer)}build(e){e=$B(e);const t=this.axis>=0?this.axis:this.axis+e.length,n=e[t];if(null==n)throw new HP(`Axis ${t} of input tensor should have a defined dimension but the layer received an input with shape ${JSON.stringify(e)}.`);this.inputSpec=[new DB({ndim:e.length,axes:{[t]:n}})];const s=[n];this.scale&&(this.gamma=this.addWeight("gamma",s,null,this.gammaInitializer,this.gammaRegularizer,!0,this.gammaConstraint)),this.center&&(this.beta=this.addWeight("beta",s,null,this.betaInitializer,this.betaRegularizer,!0,this.betaConstraint)),this.movingMean=this.addWeight("moving_mean",s,null,this.movingMeanInitializer,null,!1),this.movingVariance=this.addWeight("moving_variance",s,null,this.movingVarianceInitializer,null,!1),this.built=!0}call(e,t){return bi((()=>{const n=null!=t.training&&t.training,s=TB(e),r=s.shape,a=r.length,i=Pz(0,a),o=this.axis>=0?this.axis:this.axis+a;i.splice(o,1);const u=KP(1,a);u[o]=r[o];const l=i.slice();l.sort();const c=!we(l,Pz(0,a).slice(0,a-1));if(!n)return(()=>{if(c){const e=su(this.movingMean.read(),u),t=su(this.movingVariance.read(),u),n=this.center?su(this.beta.read(),u):null,r=this.scale?su(this.gamma.read(),u):null;return XV(s,e,t,n,r,this.epsilon)}return XV(s,this.movingMean.read(),this.movingVariance.read(),null==this.beta?null:this.beta.read(),null==this.gamma?null:this.gamma.read(),this.epsilon)})();const[h,d,p]=KV(s,this.gamma.read(),this.beta.read(),i,this.epsilon),f=(e,t,n)=>{bi((()=>{const s=1-n,r=e.read(),a=$o(Vl(r,t),s);e.write(Vl(r,a))}))};return(()=>{f(this.movingMean,d,this.momentum),f(this.movingVariance,p,this.momentum)})(),h}))}getConfig(){const e={axis:this.axis,momentum:this.momentum,epsilon:this.epsilon,center:this.center,scale:this.scale,betaInitializer:IB(this.betaInitializer),gammaInitializer:IB(this.gammaInitializer),movingMeanInitializer:IB(this.movingMeanInitializer),movingVarianceInitializer:IB(this.movingVarianceInitializer),betaRegularizer:LU(this.betaRegularizer),gammaRegularizer:LU(this.gammaRegularizer),betaConstraint:nW(this.betaConstraint),gammaConstraint:nW(this.gammaConstraint)},t=super.getConfig();return Object.assign(e,t),e}}YV.className="BatchNormalization",Cp(YV);class QV extends zB{constructor(e){if(null==e&&(e={}),super(e),this.axis=null==e.axis?-1:e.axis,"number"==typeof this.axis){if(!Number.isInteger(this.axis))throw new Error(`Expected axis to be an integer, but received ${this.axis}`)}else{if(!Array.isArray(this.axis))throw new Error(`Expected axis to be an integer or an array of integers, but received ${JSON.stringify(this.axis)}`);for(const e of this.axis)if(!Number.isInteger(e))throw new Error(`Expected axis to be an array of integers, but received ${JSON.stringify(this.axis)}`)}this.epsilon=null==e.epsilon?.001:e.epsilon,this.center=null==e.center||e.center,this.scale=null==e.scale||e.scale,this.betaInitializer=SB(e.betaInitializer||"zeros"),this.gammaInitializer=SB(e.gammaInitializer||"ones"),this.betaRegularizer=zU(e.betaRegularizer),this.gammaRegularizer=zU(e.gammaRegularizer),this.supportsMasking=!0}build(e){const t=(e=$B(e)).length;"number"==typeof this.axis&&(this.axis=[this.axis]);for(let e=0;e<this.axis.length;++e)this.axis[e]<0&&(this.axis[e]+=t);for(const e of this.axis)if(e<0||e>=t)throw new Error(`Invalid axis: ${e}`);if(this.axis.length!==oz(this.axis).length)throw new Error(`Found duplicate axes in: ${this.axis}`);const n=this.axis.map((t=>e[t])),s=!0;this.scale?this.gamma=this.addWeight("gamma",n,"float32",this.gammaInitializer,this.gammaRegularizer,s):this.gamma=null,this.center?this.beta=this.addWeight("beta",n,"float32",this.betaInitializer,this.betaRegularizer,s):this.beta=null,this.built=!0}call(e,t){const n=TB(e),s=n.shape,r=s.length;return bi((()=>{let{mean:e,variance:t}=uc(n,this.axis,!0);const a=KP(1,r);for(const e of this.axis)a[e]=s[e];const i=e=>null!=e&&e.shape.length!==r?su(e,a):e;let o=this.scale?i(this.gamma.read()):null,u=this.center?i(this.beta.read()):null;const l=[],c=[];for(let e=0;e<r;++e)-1!==this.axis.indexOf(e)?(l.push(s[e]),c.push(1)):(l.push(1),c.push(s[e]));return e=Il(e,l),t=Il(t,l),null!=o&&(o=Il(o,c)),null!=u&&(u=Il(u,c)),XV(n,e,t,u,o,this.epsilon)}))}getConfig(){const e={axis:this.axis,epsilon:this.epsilon,center:this.center,scale:this.scale,betaInitializer:IB(this.betaInitializer),gammaInitializer:IB(this.gammaInitializer),betaRegularizer:LU(this.betaRegularizer),gammaRegularizer:LU(this.gammaRegularizer)},t=super.getConfig();return Object.assign(e,t),e}}QV.className="LayerNormalization",Cp(QV);class JV extends zB{constructor(e){if(null==e&&(e={}),super(e),this.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,null==e.padding)this.padding=[[1,1],[1,1]];else if("number"==typeof e.padding)this.padding=[[e.padding,e.padding],[e.padding,e.padding]];else{if(e.padding=e.padding,2!==e.padding.length)throw new HP(`ZeroPadding2D expects padding to be a length-2 array, but received a length-${e.padding.length} array.`);let t,n;if("number"==typeof e.padding[0])t=[e.padding[0],e.padding[0]],n=[e.padding[1],e.padding[1]];else{if(e.padding=e.padding,2!==e.padding[0].length)throw new HP(`ZeroPadding2D expects height padding to be a length-2 array, but received a length-${e.padding[0].length} array.`);if(t=e.padding[0],2!==e.padding[1].length)throw new HP(`ZeroPadding2D expects width padding to be a length-2 array, but received a length-${e.padding[1].length} array.`);n=e.padding[1]}this.padding=[t,n]}this.inputSpec=[new DB({ndim:4})]}computeOutputShape(e){let t,n;return e=$B(e),"channelsFirst"===this.dataFormat?(t=null!=e[2]&&e[2]>=0?e[2]+this.padding[0][0]+this.padding[0][1]:null,n=null!=e[3]&&e[3]>=0?e[3]+this.padding[1][0]+this.padding[1][1]:null,[e[0],e[1],t,n]):(t=null!=e[1]&&e[1]>=0?e[1]+this.padding[0][0]+this.padding[0][1]:null,n=null!=e[2]&&e[2]>=0?e[2]+this.padding[1][0]+this.padding[1][1]:null,[e[0],t,n,e[3]])}call(e,t){return bi((()=>
|
|
16321
16321
|
/**
|
|
16322
16322
|
* @license
|
|
16323
16323
|
* Copyright 2018 Google LLC
|
|
@@ -16337,7 +16337,7 @@ function(e,t,n){return bi((()=>{if(4!==e.rank)throw new HP(`temporalPadding expe
|
|
|
16337
16337
|
* https://opensource.org/licenses/MIT.
|
|
16338
16338
|
* =============================================================================
|
|
16339
16339
|
*/
|
|
16340
|
-
function
|
|
16340
|
+
function ZV(e,t,n,s,r,a){return bi((()=>{let i;Sz(r),Nz(a),Cz(s),null==n&&(n=[1,1]),null==s&&(s="valid"),null==r&&(r="channelsLast"),null==a&&(a="max"),e=KU(e,r);const o="same"===s?"same":"valid";return i="max"===a?Jl(e,t,n,o):ru(e,t,n,o),"channelsFirst"===r&&(i=ed(i,[0,3,1,2])),i}))}function eG(e,t,n,s,r,a){return bi((()=>{let i;Sz(r),Nz(a),Cz(s),null==n&&(n=[1,1,1]),null==s&&(s="valid"),null==r&&(r="channelsLast"),null==a&&(a="max"),e=YU(e,r);const o="same"===s?"same":"valid";return i="max"===a?Zl(e,t,n,o):au(e,t,n,o),"channelsFirst"===r&&(i=ed(i,[0,4,1,2,3])),i}))}JV.className="ZeroPadding2D",Cp(JV);class tG extends zB{constructor(e){if(null==e.poolSize&&(e.poolSize=2),super(e),"number"==typeof e.poolSize)this.poolSize=[e.poolSize];else{if(!Array.isArray(e.poolSize)||1!==e.poolSize.length||"number"!=typeof e.poolSize[0])throw new HP(`poolSize for 1D convolutional layer must be a number or an Array of a single number, but received ${JSON.stringify(e.poolSize)}`);this.poolSize=e.poolSize}if(hz(this.poolSize,"poolSize"),null==e.strides)this.strides=this.poolSize;else if("number"==typeof e.strides)this.strides=[e.strides];else{if(!Array.isArray(e.strides)||1!==e.strides.length||"number"!=typeof e.strides[0])throw new HP(`strides for 1D convolutional layer must be a number or an Array of a single number, but received ${JSON.stringify(e.strides)}`);this.strides=e.strides}hz(this.strides,"strides"),this.padding=null==e.padding?"valid":e.padding,Cz(this.padding),this.inputSpec=[new DB({ndim:3})]}computeOutputShape(e){const t=jU((e=$B(e))[1],this.poolSize[0],this.padding,this.strides[0]);return[e[0],t,e[2]]}call(e,t){return bi((()=>{this.invokeCallHook(e,t),e=Uz(TB(e),2);const n=this.poolingFunction(TB(e),[this.poolSize[0],1],[this.strides[0],1],this.padding,"channelsLast");return Fh(n,[2])}))}getConfig(){const e={poolSize:this.poolSize,padding:this.padding,strides:this.strides},t=super.getConfig();return Object.assign(e,t),e}}class nG extends tG{constructor(e){super(e)}poolingFunction(e,t,n,s,r){return Sz(r),Cz(s),ZV(e,t,n,s,r,"max")}}nG.className="MaxPooling1D",Cp(nG);class sG extends tG{constructor(e){super(e)}poolingFunction(e,t,n,s,r){return Sz(r),Cz(s),ZV(e,t,n,s,r,"avg")}}sG.className="AveragePooling1D",Cp(sG);class rG extends zB{constructor(e){if(null==e.poolSize&&(e.poolSize=[2,2]),super(e),this.poolSize=Array.isArray(e.poolSize)?e.poolSize:[e.poolSize,e.poolSize],null==e.strides)this.strides=this.poolSize;else if(Array.isArray(e.strides)){if(2!==e.strides.length)throw new HP(`If the strides property of a 2D pooling layer is an Array, it is expected to have a length of 2, but received length ${e.strides.length}.`);this.strides=e.strides}else this.strides=[e.strides,e.strides];hz(this.poolSize,"poolSize"),hz(this.strides,"strides"),this.padding=null==e.padding?"valid":e.padding,this.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,Sz(this.dataFormat),Cz(this.padding),this.inputSpec=[new DB({ndim:4})]}computeOutputShape(e){e=$B(e);let t="channelsFirst"===this.dataFormat?e[2]:e[1],n="channelsFirst"===this.dataFormat?e[3]:e[2];return t=jU(t,this.poolSize[0],this.padding,this.strides[0]),n=jU(n,this.poolSize[1],this.padding,this.strides[1]),"channelsFirst"===this.dataFormat?[e[0],e[1],t,n]:[e[0],t,n,e[3]]}call(e,t){return bi((()=>(this.invokeCallHook(e,t),this.poolingFunction(TB(e),this.poolSize,this.strides,this.padding,this.dataFormat))))}getConfig(){const e={poolSize:this.poolSize,padding:this.padding,strides:this.strides,dataFormat:this.dataFormat},t=super.getConfig();return Object.assign(e,t),e}}class aG extends rG{constructor(e){super(e)}poolingFunction(e,t,n,s,r){return Sz(r),Cz(s),ZV(e,t,n,s,r,"max")}}aG.className="MaxPooling2D",Cp(aG);class iG extends rG{constructor(e){super(e)}poolingFunction(e,t,n,s,r){return Sz(r),Cz(s),ZV(e,t,n,s,r,"avg")}}iG.className="AveragePooling2D",Cp(iG);class oG extends zB{constructor(e){if(null==e.poolSize&&(e.poolSize=[2,2,2]),super(e),this.poolSize=Array.isArray(e.poolSize)?e.poolSize:[e.poolSize,e.poolSize,e.poolSize],null==e.strides)this.strides=this.poolSize;else if(Array.isArray(e.strides)){if(3!==e.strides.length)throw new HP(`If the strides property of a 3D pooling layer is an Array, it is expected to have a length of 3, but received length ${e.strides.length}.`);this.strides=e.strides}else this.strides=[e.strides,e.strides,e.strides];hz(this.poolSize,"poolSize"),hz(this.strides,"strides"),this.padding=null==e.padding?"valid":e.padding,this.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,Sz(this.dataFormat),Cz(this.padding),this.inputSpec=[new DB({ndim:5})]}computeOutputShape(e){e=$B(e);let t="channelsFirst"===this.dataFormat?e[2]:e[1],n="channelsFirst"===this.dataFormat?e[3]:e[2],s="channelsFirst"===this.dataFormat?e[4]:e[3];return t=jU(t,this.poolSize[0],this.padding,this.strides[0]),n=jU(n,this.poolSize[1],this.padding,this.strides[1]),s=jU(s,this.poolSize[2],this.padding,this.strides[2]),"channelsFirst"===this.dataFormat?[e[0],e[1],t,n,s]:[e[0],t,n,s,e[4]]}call(e,t){return bi((()=>(this.invokeCallHook(e,t),this.poolingFunction(TB(e),this.poolSize,this.strides,this.padding,this.dataFormat))))}getConfig(){const e={poolSize:this.poolSize,padding:this.padding,strides:this.strides,dataFormat:this.dataFormat},t=super.getConfig();return Object.assign(e,t),e}}class uG extends oG{constructor(e){super(e)}poolingFunction(e,t,n,s,r){return Sz(r),Cz(s),eG(e,t,n,s,r,"max")}}uG.className="MaxPooling3D",Cp(uG);class lG extends oG{constructor(e){super(e)}poolingFunction(e,t,n,s,r){return Sz(r),Cz(s),eG(e,t,n,s,r,"avg")}}lG.className="AveragePooling3D",Cp(lG);class cG extends zB{constructor(e){super(e),this.inputSpec=[new DB({ndim:3})]}computeOutputShape(e){return[e[0],e[2]]}call(e,t){throw new qP}}class hG extends cG{constructor(e){super(e||{})}call(e,t){return bi((()=>{const t=TB(e);return nc(t,1)}))}}hG.className="GlobalAveragePooling1D",Cp(hG);class dG extends cG{constructor(e){super(e||{})}call(e,t){return bi((()=>{const t=TB(e);return cl(t,1)}))}}dG.className="GlobalMaxPooling1D",Cp(dG);class pG extends zB{constructor(e){super(e),this.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,Sz(this.dataFormat),this.inputSpec=[new DB({ndim:4})]}computeOutputShape(e){return"channelsLast"===this.dataFormat?[e[0],e[3]]:[e[0],e[1]]}call(e,t){throw new qP}getConfig(){const e={dataFormat:this.dataFormat},t=super.getConfig();return Object.assign(e,t),e}}class fG extends pG{call(e,t){return bi((()=>{const t=TB(e);return"channelsLast"===this.dataFormat?nc(t,[1,2]):nc(t,[2,3])}))}}fG.className="GlobalAveragePooling2D",Cp(fG);class mG extends pG{call(e,t){return bi((()=>{const t=TB(e);return"channelsLast"===this.dataFormat?cl(t,[1,2]):cl(t,[2,3])}))}}mG.className="GlobalMaxPooling2D",Cp(mG);
|
|
16341
16341
|
/**
|
|
16342
16342
|
* @license
|
|
16343
16343
|
* Copyright 2018 Google LLC
|
|
@@ -16347,7 +16347,7 @@ function QV(e,t,n,s,r,a){return bi((()=>{let i;Sz(r),Nz(a),Cz(s),null==n&&(n=[1,
|
|
|
16347
16347
|
* https://opensource.org/licenses/MIT.
|
|
16348
16348
|
* =============================================================================
|
|
16349
16349
|
*/
|
|
16350
|
-
class
|
|
16350
|
+
class gG extends zB{constructor(e){super(e),this.layer=e.layer}build(e){this.built=!0}get trainable(){return null!=this.layer&&this.layer.trainable}set trainable(e){null!=this.layer&&(this.layer.trainable=e)}get trainableWeights(){return this.layer.trainableWeights}get nonTrainableWeights(){return this.layer.nonTrainableWeights}get updates(){return this.layer._updates}get losses(){return this.layer.losses}getWeights(){return this.layer.getWeights()}setWeights(e){this.layer.setWeights(e)}getConfig(){const e={layer:{className:this.layer.getClassName(),config:this.layer.getConfig()}},t=super.getConfig();return Object.assign(e,t),e}setFastWeightInitDuringBuild(e){super.setFastWeightInitDuringBuild(e),null!=this.layer&&this.layer.setFastWeightInitDuringBuild(e)}static fromConfig(e,t,n={}){const s=gW(t.layer,n);delete t.layer;const r={layer:s};return Object.assign(r,t),new e(r)}}class yG extends gG{constructor(e){super(e),this.supportsMasking=!0}build(e){if((e=$B(e)).length<3)throw new HP(`TimeDistributed layer expects an input shape >= 3D, but received input shape ${JSON.stringify(e)}`);this.inputSpec=[{shape:e}];const t=[e[0]].concat(e.slice(2));this.layer.built||(this.layer.build(t),this.layer.built=!0),super.build(e)}computeOutputShape(e){const t=[(e=$B(e))[0]].concat(e.slice(2)),n=this.layer.computeOutputShape(t),s=e[1];return[n[0],s].concat(n.slice(1))}call(e,t){return bi((()=>hV(((e,n)=>[TB(this.layer.call(e,t)),[]]),e=TB(e),[],!1,null,0,!1,!0)[1]))}}yG.className="TimeDistributed",Cp(yG);class bG extends gG{constructor(e){super(e);const t=e.layer.getConfig(),n={};n.className=e.layer.getClassName(),n.config=t,this.forwardLayer=gW(n),t.goBackwards=!0!==t.goBackwards;const s={};var r;if(s.className=e.layer.getClassName(),s.config=t,this.backwardLayer=gW(s),this.forwardLayer.name="forward_"+this.forwardLayer.name,this.backwardLayer.name="backward_"+this.backwardLayer.name,this.mergeMode=void 0===e.mergeMode?"concat":e.mergeMode,r=this.mergeMode,lz(vz,"BidirectionalMergeMode",r),e.weights)throw new qP("weights support is not implemented for Bidirectional layer yet.");this._stateful=e.layer.stateful,this.returnSequences=e.layer.returnSequences,this.returnState=e.layer.returnState,this.supportsMasking=!0,this._trainable=!0,this.inputSpec=e.layer.inputSpec,this.numConstants=null}get trainable(){return this._trainable}set trainable(e){this._trainable=e,null!=this.forwardLayer&&(this.forwardLayer.trainable=e),null!=this.backwardLayer&&(this.backwardLayer.trainable=e)}getWeights(){return this.forwardLayer.getWeights().concat(this.backwardLayer.getWeights())}setWeights(e){const t=e.length,n=Math.floor(t/2);this.forwardLayer.setWeights(e.slice(0,n)),this.backwardLayer.setWeights(e.slice(n))}computeOutputShape(e){let t,n,s,r=this.forwardLayer.computeOutputShape(e);return Array.isArray(r)&&Array.isArray(r[0])||(r=[r]),this.returnState?(s=r.slice(1),t=r[0]):t=r[0],"concat"===this.mergeMode?(t[t.length-1]*=2,n=[t]):n=null==this.mergeMode?[t,t.slice()]:[t],this.returnState?null==this.mergeMode?n.concat(s).concat(s.slice()):[t].concat(s).concat(s.slice()):JP(n)}apply(e,t){let n=null==t?null:t.initialState,s=null==t?null:t.constants;null==t&&(t={});const r=cV(e,n,s,this.numConstants);if(e=r.inputs,n=r.initialState,s=r.constants,Array.isArray(e)&&(n=e.slice(1),e=e[0]),(null==n||0===n.length)&&null==s)return super.apply(e,t);const a=[],i=[];if(null!=n){const e=n.length;if(e%2>0)throw new HP("When passing `initialState` to a Bidrectional RNN, the state should be an Array containing the states of the underlying RNNs.");t.initialState=n,a.push(...n);const s=n.map((e=>new DB({shape:e.shape})));this.forwardLayer.stateSpec=s.slice(0,e/2),this.backwardLayer.stateSpec=s.slice(e/2),i.push(...s)}if(null!=s)throw new qP("Support for constants in Bidirectional layers is not implemented yet.");const o=a[0]instanceof MB;for(const e of a)if(e instanceof MB!==o)throw new HP("The initial state of a Bidirectional layer cannot be specified as a mix of symbolic and non-symbolic tensors");if(o){const n=[e].concat(a),s=this.inputSpec.concat(i),r=this.inputSpec;this.inputSpec=s;const o=super.apply(n,t);return this.inputSpec=r,o}return super.apply(e,t)}call(e,t){return bi((()=>{const n=t.initialState;let s,r,a,i;if(null==n)s=this.forwardLayer.call(e,t),r=this.backwardLayer.call(e,t);else{const a=n.slice(0,n.length/2),i=n.slice(n.length/2);s=this.forwardLayer.call(e,Object.assign(t,{initialState:a})),r=this.backwardLayer.call(e,Object.assign(t,{initialState:i}))}return this.returnState&&(Array.isArray(s)&&(a=s.slice(1).concat(r.slice(1))),s=s[0],r=r[0]),this.returnSequences&&(r=lh(r,1)),"concat"===this.mergeMode?i=qz([s,r]):"sum"===this.mergeMode?i=Co(s,r):"ave"===this.mergeMode?i=$o(.5,Co(s,r)):"mul"===this.mergeMode?i=$o(s,r):null==this.mergeMode&&(i=[s,r]),this.returnState?null==this.mergeMode?i.concat(a):[i].concat(a):i}))}resetStates(e){this.forwardLayer.resetStates(),this.backwardLayer.resetStates()}build(e){Rz(this.forwardLayer.name,(()=>{this.forwardLayer.build(e)})),Rz(this.backwardLayer.name,(()=>{this.backwardLayer.build(e)})),this.built=!0}computeMask(e,t){let n;if(Array.isArray(t)&&(t=t[0]),n=this.returnSequences?null==this.mergeMode?[t,t]:t:null==this.mergeMode?[null,null]:null,this.returnState){const e=this.forwardLayer.states.map((e=>null));return Array.isArray(n)?n.concat(e).concat(e):[n].concat(e).concat(e)}return n}get trainableWeights(){return this.forwardLayer.trainableWeights.concat(this.backwardLayer.trainableWeights)}get nonTrainableWeights(){return this.forwardLayer.nonTrainableWeights.concat(this.backwardLayer.nonTrainableWeights)}setFastWeightInitDuringBuild(e){super.setFastWeightInitDuringBuild(e),null!=this.forwardLayer&&this.forwardLayer.setFastWeightInitDuringBuild(e),null!=this.backwardLayer&&this.backwardLayer.setFastWeightInitDuringBuild(e)}getConfig(){const e={mergeMode:this.mergeMode},t=super.getConfig();return Object.assign(e,t),e}static fromConfig(e,t){const n=gW(t.layer);if(delete t.layer,null!=t.numConstants)throw new qP("Deserialization of a Bidirectional layer with numConstants present is not supported yet.");const s=t;return s.layer=n,new e(s)}}bG.className="Bidirectional",Cp(bG);
|
|
16351
16351
|
/**
|
|
16352
16352
|
* @license
|
|
16353
16353
|
* Copyright 2022 CodeSmith LLC
|
|
@@ -16357,7 +16357,7 @@ class fG extends zB{constructor(e){super(e),this.layer=e.layer}build(e){this.bui
|
|
|
16357
16357
|
* https://opensource.org/licenses/MIT.
|
|
16358
16358
|
* =============================================================================
|
|
16359
16359
|
*/
|
|
16360
|
-
class
|
|
16360
|
+
class xG extends zB{constructor(e){super(e),this.scale=e.scale,e.offset?this.offset=e.offset:this.offset=0}getConfig(){const e={scale:this.scale,offset:this.offset},t=super.getConfig();return Object.assign(e,t),e}call(e,t){return bi((()=>("float32"!==(e=TB(e)).dtype&&(e=Wz(e,"float32")),Co($o(e,this.scale),this.offset))))}}xG.className="Rescaling",Cp(xG);
|
|
16361
16361
|
/**
|
|
16362
16362
|
* @license
|
|
16363
16363
|
* Copyright 2022 CodeSmith LLC
|
|
@@ -16367,7 +16367,7 @@ class yG extends zB{constructor(e){super(e),this.scale=e.scale,e.offset?this.off
|
|
|
16367
16367
|
* https://opensource.org/licenses/MIT.
|
|
16368
16368
|
* =============================================================================
|
|
16369
16369
|
*/
|
|
16370
|
-
const{resizeBilinear:
|
|
16370
|
+
const{resizeBilinear:wG,cropAndResize:kG}=gp;class vG extends zB{constructor(e){super(e),this.height=e.height,this.width=e.width}centerCrop(e,t,n,s,r,a,i,o){return bi((()=>{let u,l=!1;const c=[t/a,n/i,(s+t)/a,(r+n)/i],h=[];3===e.rank?(l=!0,u=Dh([e])):u=e;for(let e=0;e<u.shape[0];e++)h.push(c);const d=di(h,[h.length,4]),p=rh(0,h.length,1,"int32"),f=kG(u,d,p,[s,r],"nearest");return Wz(l?TB(Kh(f)):f,o)}))}upsize(e,t,n,s){return bi((()=>Wz(wG(e,[t,n]),s)))}call(e,t){return bi((()=>{const t=TB(e),n=t.dtype,s=t.shape,r=s[s.length-3],a=s[s.length-2];let i=0;r!==this.height&&(i=Math.floor((r-this.height)/2));let o=0;return a!==this.width&&(o=Math.floor((a-this.width)/2),0===o&&(o=1)),i>=0&&o>=0?this.centerCrop(t,i,o,this.height,this.width,r,a,n):this.upsize(e,this.height,this.width,n)}))}getConfig(){const e={height:this.height,width:this.width},t=super.getConfig();return Object.assign(e,t),e}computeOutputShape(e){const t=(e=$B(e)).length-3,n=e.length-2;return e[t]=this.height,e[n]=this.width,e}}vG.className="CenterCrop",Cp(vG);
|
|
16371
16371
|
/**
|
|
16372
16372
|
* @license
|
|
16373
16373
|
* Copyright 2022 CodeSmith LLC
|
|
@@ -16377,7 +16377,7 @@ const{resizeBilinear:bG,cropAndResize:xG}=gp;class wG extends zB{constructor(e){
|
|
|
16377
16377
|
* https://opensource.org/licenses/MIT.
|
|
16378
16378
|
* =============================================================================
|
|
16379
16379
|
*/
|
|
16380
|
-
class
|
|
16380
|
+
class IG extends zB{constructor(e){super(e),this.numTokens=e.numTokens,e.outputMode?this.outputMode=e.outputMode:this.outputMode="multiHot"}getConfig(){const e={numTokens:this.numTokens,outputMode:this.outputMode},t=super.getConfig();return Object.assign(e,t),e}computeOutputShape(e){return null==(e=$B(e))?[this.numTokens]:"oneHot"===this.outputMode&&1!==e[e.length-1]?(e.push(this.numTokens),e):(e[e.length-1]=this.numTokens,e)}call(e,t){return bi((()=>{let n;if("int32"!==(e=TB(e)).dtype&&(e=Wz(e,"int32")),void 0!==t.countWeights){if("count"!==this.outputMode)throw new HP(`countWeights is not used when outputMode !== count.\n Received countWeights=${t.countWeights}`);n=TB(t.countWeights)}const s=cl(e),r=hl(e),a=Tl(this.numTokens,s).bufferSync().get(0),i=$l(r,0).bufferSync().get(0);if(!a||!i)throw new HP(`Input values must be between 0 < values <= numTokens with numTokens=${this.numTokens}`);
|
|
16381
16381
|
/**
|
|
16382
16382
|
* @license
|
|
16383
16383
|
* Copyright 2022 CodeSmith LLC
|
|
@@ -16387,7 +16387,7 @@ class kG extends zB{constructor(e){super(e),this.numTokens=e.numTokens,e.outputM
|
|
|
16387
16387
|
* https://opensource.org/licenses/MIT.
|
|
16388
16388
|
* =============================================================================
|
|
16389
16389
|
*/
|
|
16390
|
-
return function(e,t,n,s){let r=TB(e);if("int32"!==r.dtype&&(r=Wz(r,"int32")),"int"===t)return r;const a=r.shape;if(0===r.rank&&(r=kl(r,-1)),"oneHot"===t&&1!==r.shape[r.shape.length-1]&&(r=kl(r,-1)),r.rank>2)throw new HP(`When outputMode is not int, maximum output rank is 2 Received outputMode ${t} and input shape ${a} which would result in output rank ${r.rank}.`);const i=["multiHot","oneHot"].includes(t);let o;if(o=zu(r,void 0!==s&&"count"===t?s:[],n,i),"tfIdf"!==t)return o;if(s)return $o(o,s);throw new HP("When outputMode is 'tfIdf', weights must be provided.")}(e,this.outputMode,this.numTokens,n)}))}}
|
|
16390
|
+
return function(e,t,n,s){let r=TB(e);if("int32"!==r.dtype&&(r=Wz(r,"int32")),"int"===t)return r;const a=r.shape;if(0===r.rank&&(r=kl(r,-1)),"oneHot"===t&&1!==r.shape[r.shape.length-1]&&(r=kl(r,-1)),r.rank>2)throw new HP(`When outputMode is not int, maximum output rank is 2 Received outputMode ${t} and input shape ${a} which would result in output rank ${r.rank}.`);const i=["multiHot","oneHot"].includes(t);let o;if(o=zu(r,void 0!==s&&"count"===t?s:[],n,i),"tfIdf"!==t)return o;if(s)return $o(o,s);throw new HP("When outputMode is 'tfIdf', weights must be provided.")}(e,this.outputMode,this.numTokens,n)}))}}IG.className="CategoryEncoding",Cp(IG);
|
|
16391
16391
|
/**
|
|
16392
16392
|
* @license
|
|
16393
16393
|
* Copyright 2022 CodeSmith LLC
|
|
@@ -16397,7 +16397,7 @@ return function(e,t,n,s){let r=TB(e);if("int32"!==r.dtype&&(r=Wz(r,"int32")),"in
|
|
|
16397
16397
|
* https://opensource.org/licenses/MIT.
|
|
16398
16398
|
* =============================================================================
|
|
16399
16399
|
*/
|
|
16400
|
-
const
|
|
16400
|
+
const SG=new Set(["bilinear","nearest"]);class CG extends zB{constructor(e){if(super(e),this.height=e.height,this.width=e.width,e.interpolation){if(!SG.has(e.interpolation))throw new HP(`Invalid interpolation parameter: ${e.interpolation} is not implemented`);this.interpolation=e.interpolation}else this.interpolation="bilinear";this.cropToAspectRatio=Boolean(e.cropToAspectRatio)}computeOutputShape(e){const t=(e=$B(e))[2];return[this.height,this.width,t]}getConfig(){const e={height:this.height,width:this.width,interpolation:this.interpolation,cropToAspectRatio:this.cropToAspectRatio},t=super.getConfig();return Object.assign(e,t),e}call(e,t){return bi((()=>{const t=[this.height,this.width];if("bilinear"===this.interpolation)return gp.resizeBilinear(e,t,!this.cropToAspectRatio);if("nearest"===this.interpolation)return gp.resizeNearestNeighbor(e,t,!this.cropToAspectRatio);throw new Error(`Interpolation is ${this.interpolation} but only ${[...SG]} are supported`)}))}}CG.className="Resizing",Cp(CG);
|
|
16401
16401
|
/**
|
|
16402
16402
|
* @license
|
|
16403
16403
|
* Copyright 2023 CodeSmith LLC
|
|
@@ -16407,7 +16407,7 @@ const vG=new Set(["bilinear","nearest"]);class IG extends zB{constructor(e){if(s
|
|
|
16407
16407
|
* https://opensource.org/licenses/MIT.
|
|
16408
16408
|
* =============================================================================
|
|
16409
16409
|
*/
|
|
16410
|
-
class
|
|
16410
|
+
class NG{constructor(e){this.seed=e}next(){if(void 0!==this.seed)return this.seed++}}NG.className="RandomSeed";
|
|
16411
16411
|
/**
|
|
16412
16412
|
* @license
|
|
16413
16413
|
* Copyright 2023 CodeSmith LLC
|
|
@@ -16417,7 +16417,7 @@ class SG{constructor(e){this.seed=e}next(){if(void 0!==this.seed)return this.see
|
|
|
16417
16417
|
* https://opensource.org/licenses/MIT.
|
|
16418
16418
|
* =============================================================================
|
|
16419
16419
|
*/
|
|
16420
|
-
class
|
|
16420
|
+
class TG extends zB{constructor(e){super(e),this.randomGenerator=new NG(e.seed)}getConfig(){const e={seed:this.randomGenerator.seed},t=super.getConfig();return Object.assign(e,t),e}}TG.className="BaseRandomLayer";
|
|
16421
16421
|
/**
|
|
16422
16422
|
* @license
|
|
16423
16423
|
* Copyright 2023 CodeSmith LLC
|
|
@@ -16427,7 +16427,7 @@ class CG extends zB{constructor(e){super(e),this.randomGenerator=new SG(e.seed)}
|
|
|
16427
16427
|
* https://opensource.org/licenses/MIT.
|
|
16428
16428
|
* =============================================================================
|
|
16429
16429
|
*/
|
|
16430
|
-
const
|
|
16430
|
+
const $G=new Set(["bilinear","nearest"]);class RG extends TG{constructor(e){super(e);const{factor:t,interpolation:n="bilinear"}=e;if(this.factor=t,Array.isArray(this.factor)&&2===this.factor.length)this.widthLower=this.factor[0],this.widthUpper=this.factor[1];else{if(Array.isArray(this.factor)||!(this.factor>0))throw new HP(`Invalid factor: ${this.factor}. Must be positive number or tuple of 2 numbers`);this.widthLower=-this.factor,this.widthUpper=this.factor}if(this.widthLower<-1||this.widthUpper<-1)throw new HP(`factor must have values larger than -1. Got: ${this.factor}`);if(this.widthUpper<this.widthLower)throw new HP(`factor cannot have upper bound less than lower bound.\n Got upper bound: ${this.widthUpper}.\n Got lower bound: ${this.widthLower}\n `);if(n){if(!$G.has(n))throw new HP(`Invalid interpolation parameter: ${n} is not implemented`);this.interpolation=n}}getConfig(){const e={factor:this.factor,interpolation:this.interpolation},t=super.getConfig();return Object.assign(e,t),e}computeOutputShape(e){const t=(e=$B(e))[2];return[this.imgHeight,-1,t]}call(e,t){return bi((()=>{const t=TB(e);this.imgHeight=t.shape[t.shape.length-3];const n=t.shape[t.shape.length-2];this.widthFactor=nh([1],1+this.widthLower,1+this.widthUpper,"float32",this.randomGenerator.next());let s=this.widthFactor.dataSync()[0]*n;s=Math.round(s);const r=[this.imgHeight,s];switch(this.interpolation){case"bilinear":return gp.resizeBilinear(e,r);case"nearest":return gp.resizeNearestNeighbor(e,r);default:throw new Error(`Interpolation is ${this.interpolation}\n but only ${[...$G]} are supported`)}}))}}RG.className="RandomWidth",Cp(RG);
|
|
16431
16431
|
/**
|
|
16432
16432
|
* @license
|
|
16433
16433
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -16445,7 +16445,7 @@ const NG=new Set(["bilinear","nearest"]);class TG extends CG{constructor(e){supe
|
|
|
16445
16445
|
*
|
|
16446
16446
|
* =============================================================================
|
|
16447
16447
|
*/
|
|
16448
|
-
var
|
|
16448
|
+
var EG,AG;Qe().registerFlag("KEEP_INTERMEDIATE_TENSORS",(()=>!1),(e=>{e&&console.warn("Keep intermediate tensors is ON. This will print the values of all intermediate tensors during model inference. Not all models support this mode. For details, check e2e/benchmarks/ model_config.js. This significantly impacts performance.")})),function(e){e[e.DT_INVALID=0]="DT_INVALID",e[e.DT_FLOAT=1]="DT_FLOAT",e[e.DT_DOUBLE=2]="DT_DOUBLE",e[e.DT_INT32=3]="DT_INT32",e[e.DT_UINT8=4]="DT_UINT8",e[e.DT_INT16=5]="DT_INT16",e[e.DT_INT8=6]="DT_INT8",e[e.DT_STRING=7]="DT_STRING",e[e.DT_COMPLEX64=8]="DT_COMPLEX64",e[e.DT_INT64=9]="DT_INT64",e[e.DT_BOOL=10]="DT_BOOL",e[e.DT_QINT8=11]="DT_QINT8",e[e.DT_QUINT8=12]="DT_QUINT8",e[e.DT_QINT32=13]="DT_QINT32",e[e.DT_BFLOAT16=14]="DT_BFLOAT16",e[e.DT_QINT16=15]="DT_QINT16",e[e.DT_QUINT16=16]="DT_QUINT16",e[e.DT_UINT16=17]="DT_UINT16",e[e.DT_COMPLEX128=18]="DT_COMPLEX128",e[e.DT_HALF=19]="DT_HALF",e[e.DT_RESOURCE=20]="DT_RESOURCE",e[e.DT_VARIANT=21]="DT_VARIANT",e[e.DT_UINT32=22]="DT_UINT32",e[e.DT_UINT64=23]="DT_UINT64",e[e.DT_FLOAT_REF=101]="DT_FLOAT_REF",e[e.DT_DOUBLE_REF=102]="DT_DOUBLE_REF",e[e.DT_INT32_REF=103]="DT_INT32_REF",e[e.DT_UINT8_REF=104]="DT_UINT8_REF",e[e.DT_INT16_REF=105]="DT_INT16_REF",e[e.DT_INT8_REF=106]="DT_INT8_REF",e[e.DT_STRING_REF=107]="DT_STRING_REF",e[e.DT_COMPLEX64_REF=108]="DT_COMPLEX64_REF",e[e.DT_INT64_REF=109]="DT_INT64_REF",e[e.DT_BOOL_REF=110]="DT_BOOL_REF",e[e.DT_QINT8_REF=111]="DT_QINT8_REF",e[e.DT_QUINT8_REF=112]="DT_QUINT8_REF",e[e.DT_QINT32_REF=113]="DT_QINT32_REF",e[e.DT_BFLOAT16_REF=114]="DT_BFLOAT16_REF",e[e.DT_QINT16_REF=115]="DT_QINT16_REF",e[e.DT_QUINT16_REF=116]="DT_QUINT16_REF",e[e.DT_UINT16_REF=117]="DT_UINT16_REF",e[e.DT_COMPLEX128_REF=118]="DT_COMPLEX128_REF",e[e.DT_HALF_REF=119]="DT_HALF_REF",e[e.DT_RESOURCE_REF=120]="DT_RESOURCE_REF",e[e.DT_VARIANT_REF=121]="DT_VARIANT_REF",e[e.DT_UINT32_REF=122]="DT_UINT32_REF",e[e.DT_UINT64_REF=123]="DT_UINT64_REF"}(EG||(EG={})),function(e){var t;(t=e.CheckpointFormatVersion||(e.CheckpointFormatVersion={}))[t.LEGACY=0]="LEGACY",t[t.V1=1]="V1",t[t.V2=2]="V2"}(AG||(AG={}));
|
|
16449
16449
|
/**
|
|
16450
16450
|
* @license
|
|
16451
16451
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -16462,7 +16462,7 @@ var $G,RG;Qe().registerFlag("KEEP_INTERMEDIATE_TENSORS",(()=>!1),(e=>{e&&console
|
|
|
16462
16462
|
* limitations under the License.
|
|
16463
16463
|
* =============================================================================
|
|
16464
16464
|
*/
|
|
16465
|
-
const
|
|
16465
|
+
const _G={};function FG(e){return _G[e]}
|
|
16466
16466
|
/**
|
|
16467
16467
|
* @license
|
|
16468
16468
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16478,7 +16478,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16478
16478
|
* See the License for the specific language governing permissions and
|
|
16479
16479
|
* limitations under the License.
|
|
16480
16480
|
* =============================================================================
|
|
16481
|
-
*/function
|
|
16481
|
+
*/function DG(e,t,n,s,r){const a=t.inputParams[e];if(a&&void 0!==a.inputIndexStart){const e=a.inputIndexStart,i=0===a.inputIndexEnd?void 0:void 0===a.inputIndexEnd?e+1:a.inputIndexEnd,o=e<0?t.inputNames.length+e:e;if("tensor"===a.type)return MG(t.inputNames[o],n,s,r);if("tensors"===a.type){const a=t.inputs.slice(e,i);return t.inputNames.slice(e,i).filter(((e,t)=>{var n;return"NoOp"!==(null===(n=a[t])||void 0===n?void 0:n.op)})).map((e=>MG(e,n,s,r)))}const u=MG(t.inputNames[o],n,s,r),l=u.dataSync();return"number"===a.type?l[0]:ze(u.shape,l)}const i=t.attrParams[e];return i&&i.value}function MG(e,t,n,s){const[r,a]=zG(e,n);if(null!=s){const e=s.getHashTableHandleByName(r);if(null!=e)return e}const i=n.currentContextIds.find((e=>!!t[PG(r,e)]));return void 0!==i?t[PG(r,i)][a]:void 0}function OG(e,t,n){return t[PG(e,n.currentContextId)]}function LG(e,t){const[n,s,r]=zG(e,t);return[PG(n,t&&t.currentContextId),s,r]}function PG(e,t){return t?`${e}-${t}`:e}function zG(e,t){if(""===e)return["",0,void 0];const n=null!=t&&null!=t.parseNodeNameCache;if(n){const n=t.parseNodeNameCache.get(e);if(null!=n)return n}const s=e.split(":");let r;if(1===s.length)r=[e,0,void 0];else{const e=s[0],t=3===s.length?s[1]:void 0;r=[e,Number(s[s.length-1]),t]}return n&&t.parseNodeNameCache.set(e,r),r}function BG(e,t,n){let s=DG("pad",e,t,n);if("explicit"===s){s=DG("explicitPaddings",e,t,n);const r=[[0,0],[0,0],[0,0],[0,0]];for(let e=0;e<4;e++)r[e][0]=s[2*e],r[e][1]=s[2*e+1];return r}return s}function WG(e){return e.kept?e:Io(e)}
|
|
16482
16482
|
/**
|
|
16483
16483
|
* @license
|
|
16484
16484
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16494,7 +16494,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16494
16494
|
* See the License for the specific language governing permissions and
|
|
16495
16495
|
* limitations under the License.
|
|
16496
16496
|
* =============================================================================
|
|
16497
|
-
*/var
|
|
16497
|
+
*/var UG=Object.freeze({__proto__:null,json:[{tfOpName:"Add",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AddV2",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AddN",category:"arithmetic",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}]},{tfOpName:"BiasAdd",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"Sub",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"RealDiv",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Div",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"DivNoNan",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"FloorDiv",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Mul",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Maximum",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Minimum",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Pow",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"SquaredDifference",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Mod",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"FloorMod",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}]});
|
|
16498
16498
|
/**
|
|
16499
16499
|
* @license
|
|
16500
16500
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16510,7 +16510,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16510
16510
|
* See the License for the specific language governing permissions and
|
|
16511
16511
|
* limitations under the License.
|
|
16512
16512
|
* =============================================================================
|
|
16513
|
-
*/var
|
|
16513
|
+
*/var VG=Object.freeze({__proto__:null,json:[{tfOpName:"Abs",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Acos",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Asin",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atan",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atan2",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"y",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Ceil",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ClipByValue",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"clipValueMin",type:"number"},{start:2,name:"clipValueMax",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Complex",category:"basic_math",inputs:[{start:0,name:"real",type:"tensor"},{start:1,name:"imag",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ComplexAbs",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Cos",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Cosh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Elu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Exp",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Floor",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Log",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Imag",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"Tout",name:"outputType",type:"dtype",notSupported:!0}]},{tfOpName:"Neg",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Real",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"Tout",name:"outputType",type:"dtype",notSupported:!0}]},{tfOpName:"Prelu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"alpha",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Relu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Relu6",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Selu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sigmoid",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sin",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sinh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sqrt",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Rsqrt",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Square",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Tan",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Tanh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sign",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Round",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Expm1",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Log1p",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Reciprocal",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Softplus",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Asinh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Acosh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atanh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Erf",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LeakyRelu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"alpha",name:"alpha",type:"number",defaultValue:.2},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"IsNan",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"IsFinite",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"IsInf",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}]});
|
|
16514
16514
|
/**
|
|
16515
16515
|
* @license
|
|
16516
16516
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16526,7 +16526,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16526
16526
|
* See the License for the specific language governing permissions and
|
|
16527
16527
|
* limitations under the License.
|
|
16528
16528
|
* =============================================================================
|
|
16529
|
-
*/var
|
|
16529
|
+
*/var GG=Object.freeze({__proto__:null,json:[{tfOpName:"EmptyTensorList",category:"control",inputs:[{start:0,name:"elementShape",type:"shape"},{start:1,name:"maxNumElements",type:"number"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"LoopCond",category:"control",inputs:[{start:0,name:"pred",type:"tensor"}]},{tfOpName:"Switch",category:"control",inputs:[{start:0,name:"data",type:"tensor"},{start:1,name:"pred",type:"tensor"}]},{tfOpName:"Merge",category:"control",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}]},{tfOpName:"Enter",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"frame_name",name:"frameName",type:"string"},{tfName:"is_constant",name:"isConstant",type:"bool"}]},{tfOpName:"Exit",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"NextIteration",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayV3",category:"control",inputs:[{start:0,name:"size",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape",name:"elementShape",type:"shape"},{tfName:"dynamic_size",name:"dynamicSize",type:"bool"},{tfName:"clear_after_read",name:"clearAfterRead",type:"bool"},{tfName:"identical_element_shapes",name:"identicalElementShapes",type:"bool"},{tfName:"tensor_array_name",name:"name",type:"string"}]},{tfOpName:"TensorArrayWriteV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"index",type:"number"},{start:2,name:"tensor",type:"tensor"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayReadV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"index",type:"number"},{start:2,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayGatherV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape",name:"elementShape",type:"shape"}]},{tfOpName:"TensorArrayScatterV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"tensor",type:"tensor"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"TensorArrayConcatV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape_except0",name:"elementShapeExcept0",type:"shape",notSupported:!0}]},{tfOpName:"TensorArraySplitV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"tensor",type:"tensor"},{start:2,name:"lengths",type:"number[]"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"TensorArraySizeV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"flowIn",type:"number"}]},{tfOpName:"TensorArrayCloseV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"}]},{tfOpName:"StatelessIf",category:"control",inputs:[{start:0,name:"cond",type:"tensor"},{start:1,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"then_branch",name:"thenBranch",type:"func"},{tfName:"else_branch",name:"elseBranch",type:"func"}]},{tfOpName:"If",category:"control",inputs:[{start:0,name:"cond",type:"tensor"},{start:1,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"then_branch",name:"thenBranch",type:"func"},{tfName:"else_branch",name:"elseBranch",type:"func"}]},{tfOpName:"StatelessWhile",category:"control",inputs:[{start:0,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"cond",name:"cond",type:"func"},{tfName:"body",name:"body",type:"func"}]},{tfOpName:"While",category:"control",inputs:[{start:0,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"cond",name:"cond",type:"func"},{tfName:"body",name:"body",type:"func"}]},{tfOpName:"TensorListScatter",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListScatterV2",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"elementShape",type:"shape"},{start:3,name:"numElements",type:"number"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListGather",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListGetItem",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"index",type:"number"},{start:2,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListSetItem",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"index",type:"number"},{start:2,name:"tensor",type:"tensor"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListReserve",category:"control",inputs:[{start:0,name:"elementShape",type:"shape"},{start:1,name:"numElements",type:"number"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListFromTensor",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListStack",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"},{tfName:"num_elements",name:"numElements",type:"dtype"}]},{tfOpName:"TensorListSplit",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"elementShape",type:"shape"},{start:2,name:"lengths",type:"number[]"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListConcat",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"}],attrs:[{tfName:"element_shape",name:"elementShape",type:"shape"},{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListConcatV2",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"}],attrs:[{tfName:"element_shape",name:"elementShape",type:"shape"},{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListPopBack",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListPushBack",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"tensor",type:"tensor"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListLength",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"}]},{tfOpName:"TensorListResize",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"size",type:"number"}]}]});
|
|
16530
16530
|
/**
|
|
16531
16531
|
* @license
|
|
16532
16532
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16542,7 +16542,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16542
16542
|
* See the License for the specific language governing permissions and
|
|
16543
16543
|
* limitations under the License.
|
|
16544
16544
|
* =============================================================================
|
|
16545
|
-
*/var
|
|
16545
|
+
*/var HG=Object.freeze({__proto__:null,json:[{tfOpName:"AvgPool",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPool",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[],notSupported:!0},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPoolWithArgmax",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"include_batch_in_index",name:"includeBatchInIndex",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AvgPool3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPool3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Conv1D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"stride",name:"stride",type:"number"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NWC"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"dilation",name:"dilation",type:"number",defaultValue:1}]},{tfOpName:"Conv2D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"useCudnnOnGpu",name:"useCudnnOnGpu",type:"bool"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"_FusedConv2D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"use_cudnn_on_gpu",name:"useCudnnOnGpu",type:"bool",defaultValue:!0},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]",defaultValue:[1,1,1,1]},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]},{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:1e-4},{tfName:"leakyrelu_alpha",name:"leakyreluAlpha",type:"number",defaultValue:.2}]},{tfOpName:"Conv2DBackpropInput",category:"convolution",inputs:[{start:2,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:0,name:"outputShape",type:"number[]"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"dilations",name:"dilations",type:"number[]",notSupported:!0}]},{tfOpName:"DepthwiseConv2d",category:"convolution",inputs:[{start:0,name:"input",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"DepthwiseConv2dNative",category:"convolution",inputs:[{start:0,name:"input",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"FusedDepthwiseConv2dNative",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]",defaultValue:[1,1,1,1]},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]}]},{tfOpName:"Conv3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"Dilation2D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"rates",name:"dilations",type:"number[]"},{tfName:"padding",name:"pad",type:"string"}]}]});
|
|
16546
16546
|
/**
|
|
16547
16547
|
* @license
|
|
16548
16548
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16558,7 +16558,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16558
16558
|
* See the License for the specific language governing permissions and
|
|
16559
16559
|
* limitations under the License.
|
|
16560
16560
|
* =============================================================================
|
|
16561
|
-
*/var
|
|
16561
|
+
*/var qG=Object.freeze({__proto__:null,json:[{tfOpName:"Fill",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"},{start:1,name:"value",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"LinSpace",category:"creation",inputs:[{start:0,name:"start",type:"number"},{start:1,name:"stop",type:"number"},{start:2,name:"num",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"OneHot",category:"creation",inputs:[{start:0,name:"indices",type:"tensor"},{start:1,name:"depth",type:"number"},{start:2,name:"onValue",type:"number",defaultValue:1},{start:3,name:"offValue",type:"number",defaultValue:0}],attrs:[{tfName:"axis",name:"axis",type:"number",notSupported:!0},{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"Ones",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"OnesLike",category:"creation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"RandomStandardNormal",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"seed",name:"seed",type:"number",defaultValue:0},{tfName:"seed2",name:"seed2",type:"number",defaultValue:0,notSupported:!0},{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"T",name:"T",type:"number",notSupported:!0}]},{tfOpName:"RandomUniform",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"minval",name:"minval",type:"number",defaultValue:0},{tfName:"maxval",name:"maxval",type:"number",defaultValue:1},{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"seed",name:"seed",type:"number",defaultValue:0},{tfName:"seed2",name:"seed2",type:"number",defaultValue:0,notSupported:!0},{tfName:"T",name:"T",type:"number",notSupported:!0}]},{tfOpName:"RandomUniformInt",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"minval",name:"minval",type:"number"},{tfName:"maxval",name:"maxval",type:"number"},{tfName:"seed",name:"seed",type:"number",defaultValue:0},{tfName:"seed2",name:"seed2",type:"number",defaultValue:0,notSupported:!0}]},{tfOpName:"Range",category:"creation",inputs:[{start:0,name:"start",type:"number"},{start:1,name:"stop",type:"number"},{start:2,name:"step",type:"number",defaultValue:0}],attrs:[{tfName:"Tidx",name:"dtype",type:"dtype"}]},{tfOpName:"TruncatedNormal",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"means",name:"mean",type:"number",defaultValue:0},{tfName:"stddev",name:"stdDev",type:"number",defaultValue:1},{tfName:"seed",name:"seed",type:"number"},{tfName:"seed2",name:"seed2",type:"number",defaultValue:0,notSupported:!0},{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"T",name:"T",type:"number",notSupported:!0}]},{tfOpName:"Zeros",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"ZerosLike",category:"creation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"Multinomial",category:"creation",inputs:[{start:0,name:"logits",type:"tensor"},{start:1,name:"numSamples",type:"number"}],attrs:[{tfName:"seed",name:"seed",type:"number"},{tfName:"seed2",name:"seed2",type:"number"},{tfName:"T",name:"dtype",type:"dtype"},{tfName:"output_dtype",name:"output_dtype",type:"dtype"}]}]});
|
|
16562
16562
|
/**
|
|
16563
16563
|
* @license
|
|
16564
16564
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16574,7 +16574,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16574
16574
|
* See the License for the specific language governing permissions and
|
|
16575
16575
|
* limitations under the License.
|
|
16576
16576
|
* =============================================================================
|
|
16577
|
-
*/var
|
|
16577
|
+
*/var jG=Object.freeze({__proto__:null,json:[{tfOpName:"NonMaxSuppressionV2",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"}]},{tfOpName:"NonMaxSuppressionV3",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"},{start:4,name:"scoreThreshold",type:"number"}]},{tfOpName:"NonMaxSuppressionV4",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"},{start:4,name:"scoreThreshold",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"T_threshold",name:"threshold",type:"dtype",notSupported:!0},{tfName:"pad_to_max_output_size",name:"padToMaxOutputSize",type:"bool"}]},{tfOpName:"NonMaxSuppressionV5",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"},{start:4,name:"scoreThreshold",type:"number"},{start:5,name:"softNmsSigma",type:"number"}]},{tfOpName:"Where",category:"dynamic",inputs:[{start:0,name:"condition",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ListDiff",category:"dynamic",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"y",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}]});
|
|
16578
16578
|
/**
|
|
16579
16579
|
* @license
|
|
16580
16580
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16590,7 +16590,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16590
16590
|
* See the License for the specific language governing permissions and
|
|
16591
16591
|
* limitations under the License.
|
|
16592
16592
|
* =============================================================================
|
|
16593
|
-
*/var
|
|
16593
|
+
*/var XG=Object.freeze({__proto__:null,json:[{tfOpName:"LowerBound",category:"evaluation",inputs:[{start:0,name:"sortedSequence",type:"tensor"},{start:1,name:"values",type:"tensor"}]},{tfOpName:"TopKV2",category:"evaluation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"k",type:"number"}],attrs:[{tfName:"sorted",name:"sorted",type:"bool"}]},{tfOpName:"UpperBound",category:"evaluation",inputs:[{start:0,name:"sortedSequence",type:"tensor"},{start:1,name:"values",type:"tensor"}]},{tfOpName:"Unique",category:"evaluation",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"UniqueV2",category:"evaluation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]}]});
|
|
16594
16594
|
/**
|
|
16595
16595
|
* @license
|
|
16596
16596
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16606,7 +16606,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16606
16606
|
* See the License for the specific language governing permissions and
|
|
16607
16607
|
* limitations under the License.
|
|
16608
16608
|
* =============================================================================
|
|
16609
|
-
*/var
|
|
16609
|
+
*/var KG=Object.freeze({__proto__:null,json:[{tfOpName:"PlaceholderWithDefault",category:"graph",inputs:[{start:0,name:"default",type:"tensor"}],attrs:[{tfName:"shape",name:"shape",type:"shape"},{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"Placeholder",category:"graph",attrs:[{tfName:"shape",name:"shape",type:"shape"},{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"Const",category:"graph"},{tfOpName:"Identity",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"IdentityN",category:"graph",inputs:[{start:0,end:0,name:"x",type:"tensors"}]},{tfOpName:"Snapshot",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Rank",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Size",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Shape",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"ShapeN",category:"graph",inputs:[{start:0,end:0,name:"x",type:"tensors"}]},{tfOpName:"Print",category:"graph",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"data",type:"tensors"}],attrs:[{tfName:"message",name:"message",type:"string"},{tfName:"first_n",name:"firstN",type:"number",notSupported:!0},{tfName:"summarize",name:"summarize",type:"number",defaultValue:3}]},{tfOpName:"NoOp",category:"graph",inputs:[]},{tfOpName:"StopGradient",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"FakeQuantWithMinMaxVars",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"min",name:"min",type:"number"},{tfName:"max",name:"max",type:"number"}]}]});
|
|
16610
16610
|
/**
|
|
16611
16611
|
* @license
|
|
16612
16612
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16622,7 +16622,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16622
16622
|
* See the License for the specific language governing permissions and
|
|
16623
16623
|
* limitations under the License.
|
|
16624
16624
|
* =============================================================================
|
|
16625
|
-
*/var
|
|
16625
|
+
*/var YG=Object.freeze({__proto__:null,json:[{tfOpName:"HashTable",category:"hash_table",inputs:[],attrs:[{tfName:"shared_name",name:"sharedName",type:"string"},{tfName:"use_node_name_sharing",name:"useNodeNameSharing",type:"bool"},{tfName:"key_dtype",name:"keyDType",type:"dtype"},{tfName:"value_dtype",name:"valueDType",type:"dtype"}]},{tfOpName:"HashTableV2",category:"hash_table",inputs:[],attrs:[{tfName:"shared_name",name:"sharedName",type:"string"},{tfName:"use_node_name_sharing",name:"useNodeNameSharing",type:"bool"},{tfName:"key_dtype",name:"keyDType",type:"dtype"},{tfName:"value_dtype",name:"valueDType",type:"dtype"}]},{tfOpName:"LookupTableImport",category:"hash_table",inputs:[{start:0,name:"tableHandle",type:"tensor"},{start:1,name:"keys",type:"tensor"},{start:2,name:"values",type:"tensor"}],attrs:[{tfName:"Tin",name:"tIn",type:"dtype",notSupported:!0},{tfName:"Tout",name:"tOut",type:"dtype",notSupported:!0}]},{tfOpName:"LookupTableImportV2",category:"hash_table",inputs:[{start:0,name:"tableHandle",type:"tensor"},{start:1,name:"keys",type:"tensor"},{start:2,name:"values",type:"tensor"}],attrs:[{tfName:"Tin",name:"tIn",type:"dtype",notSupported:!0},{tfName:"Tout",name:"tOut",type:"dtype",notSupported:!0}]},{tfOpName:"LookupTableFind",category:"hash_table",inputs:[{start:0,name:"tableHandle",type:"tensor"},{start:1,name:"keys",type:"tensor"},{start:2,name:"defaultValue",type:"tensor"}],attrs:[{tfName:"Tin",name:"tIn",type:"dtype",notSupported:!0},{tfName:"Tout",name:"tOut",type:"dtype",notSupported:!0}]},{tfOpName:"LookupTableFindV2",category:"hash_table",inputs:[{start:0,name:"tableHandle",type:"tensor"},{start:1,name:"keys",type:"tensor"},{start:2,name:"defaultValue",type:"tensor"}],attrs:[{tfName:"Tin",name:"tIn",type:"dtype",notSupported:!0},{tfName:"Tout",name:"tOut",type:"dtype",notSupported:!0}]},{tfOpName:"LookupTableSize",category:"hash_table",inputs:[{start:0,name:"tableHandle",type:"tensor"}]},{tfOpName:"LookupTableSizeV2",category:"hash_table",inputs:[{start:0,name:"tableHandle",type:"tensor"}]},{tfOpName:"InitializeTable",category:"hash_table",inputs:[{start:0,name:"tableHandle",type:"tensor"},{start:1,name:"keys",type:"tensor"},{start:2,name:"values",type:"tensor"}]},{tfOpName:"InitializeTableV2",category:"hash_table",inputs:[{start:0,name:"tableHandle",type:"tensor"},{start:1,name:"keys",type:"tensor"},{start:2,name:"values",type:"tensor"}]}]});
|
|
16626
16626
|
/**
|
|
16627
16627
|
* @license
|
|
16628
16628
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16638,7 +16638,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16638
16638
|
* See the License for the specific language governing permissions and
|
|
16639
16639
|
* limitations under the License.
|
|
16640
16640
|
* =============================================================================
|
|
16641
|
-
*/var
|
|
16641
|
+
*/var QG=Object.freeze({__proto__:null,json:[{tfOpName:"ResizeBilinear",category:"image",inputs:[{start:0,name:"images",type:"tensor"},{start:1,name:"size",type:"number[]"}],attrs:[{tfName:"align_corners",name:"alignCorners",type:"bool"},{tfName:"half_pixel_centers",name:"halfPixelCenters",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ResizeNearestNeighbor",category:"image",inputs:[{start:0,name:"images",type:"tensor"},{start:1,name:"size",type:"number[]"}],attrs:[{tfName:"align_corners",name:"alignCorners",type:"bool"},{tfName:"half_pixel_centers",name:"halfPixelCenters",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"CropAndResize",category:"image",inputs:[{start:0,name:"image",type:"tensor"},{start:1,name:"boxes",type:"tensor"},{start:2,name:"boxInd",type:"tensor"},{start:3,name:"cropSize",type:"number[]"}],attrs:[{tfName:"method",name:"method",type:"string"},{tfName:"extrapolation_value",name:"extrapolationValue",type:"number"}]},{tfOpName:"ImageProjectiveTransformV3",category:"image",inputs:[{start:0,name:"images",type:"tensor"},{start:1,name:"transforms",type:"tensor"},{start:2,name:"outputShape",type:"number[]"},{start:3,name:"fillValue",type:"number"}],attrs:[{tfName:"interpolation",name:"interpolation",type:"string"},{tfName:"fill_mode",name:"fillMode",type:"string"}]}]});
|
|
16642
16642
|
/**
|
|
16643
16643
|
* @license
|
|
16644
16644
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16654,7 +16654,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16654
16654
|
* See the License for the specific language governing permissions and
|
|
16655
16655
|
* limitations under the License.
|
|
16656
16656
|
* =============================================================================
|
|
16657
|
-
*/var
|
|
16657
|
+
*/var JG=Object.freeze({__proto__:null,json:[{tfOpName:"Equal",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"NotEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Greater",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"GreaterEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Less",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LessEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalAnd",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalNot",category:"logical",inputs:[{start:0,name:"a",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalOr",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Select",category:"logical",inputs:[{start:0,name:"condition",type:"tensor"},{start:1,name:"a",type:"tensor"},{start:2,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"SelectV2",category:"logical",inputs:[{start:0,name:"condition",type:"tensor"},{start:1,name:"a",type:"tensor"},{start:2,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"BitwiseAnd",category:"logical",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"y",type:"tensor"}]}]});
|
|
16658
16658
|
/**
|
|
16659
16659
|
* @license
|
|
16660
16660
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16670,7 +16670,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16670
16670
|
* See the License for the specific language governing permissions and
|
|
16671
16671
|
* limitations under the License.
|
|
16672
16672
|
* =============================================================================
|
|
16673
|
-
*/var
|
|
16673
|
+
*/var ZG=Object.freeze({__proto__:null,json:[{tfOpName:"_FusedMatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]},{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:1e-4},{tfName:"transpose_a",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"transpose_b",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"leakyrelu_alpha",name:"leakyreluAlpha",type:"number",defaultValue:.2},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"transpose_a",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"transpose_b",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"BatchMatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"adj_x",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"adj_y",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"BatchMatMulV2",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"adj_x",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"adj_y",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Transpose",category:"matrices",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"perm",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Einsum",category:"matrices",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}],attrs:[{tfName:"equation",name:"equation",type:"string"},{tfName:"N",name:"n",type:"number",defaultValue:2},{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"MatrixBandPart",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"numLower",type:"tensor"},{start:1,name:"numUpper",type:"tensor"}]}]});
|
|
16674
16674
|
/**
|
|
16675
16675
|
* @license
|
|
16676
16676
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16686,7 +16686,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16686
16686
|
* See the License for the specific language governing permissions and
|
|
16687
16687
|
* limitations under the License.
|
|
16688
16688
|
* =============================================================================
|
|
16689
|
-
*/var
|
|
16689
|
+
*/var eH=Object.freeze({__proto__:null,json:[{tfOpName:"EuclideanNorm",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool",defaultValue:!1}]},{tfOpName:"FusedBatchNorm",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"FusedBatchNormV2",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"FusedBatchNormV3",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"LRN",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"depth_radius",name:"radius",type:"number",defaultValue:5},{tfName:"bias",name:"bias",type:"number",defaultValue:1},{tfName:"alpha",name:"alpha",type:"number",defaultValue:1},{tfName:"beta",name:"beta",type:"number",defaultValue:.5}]},{tfOpName:"Softmax",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"LogSoftmax",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}]}]});
|
|
16690
16690
|
/**
|
|
16691
16691
|
* @license
|
|
16692
16692
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16702,7 +16702,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16702
16702
|
* See the License for the specific language governing permissions and
|
|
16703
16703
|
* limitations under the License.
|
|
16704
16704
|
* =============================================================================
|
|
16705
|
-
*/var
|
|
16705
|
+
*/var tH=Object.freeze({__proto__:null,json:[{tfOpName:"Bincount",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"size",type:"number"},{start:2,name:"weights",type:"tensor"}]},{tfOpName:"DenseBincount",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"size",type:"number"},{start:2,name:"weights",type:"tensor"}],attrs:[{tfName:"binary_output",name:"binaryOutput",type:"bool"}]},{tfOpName:"Max",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Mean",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Min",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Sum",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"All",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Any",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"ArgMax",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"ArgMin",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"Prod",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Cumprod",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}],attrs:[{tfName:"exclusive",name:"exclusive",type:"bool"},{tfName:"reverse",name:"reverse",type:"bool"}]},{tfOpName:"Cumsum",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}],attrs:[{tfName:"exclusive",name:"exclusive",type:"bool"},{tfName:"reverse",name:"reverse",type:"bool"}]}]});
|
|
16706
16706
|
/**
|
|
16707
16707
|
* @license
|
|
16708
16708
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16718,7 +16718,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16718
16718
|
* See the License for the specific language governing permissions and
|
|
16719
16719
|
* limitations under the License.
|
|
16720
16720
|
* =============================================================================
|
|
16721
|
-
*/var
|
|
16721
|
+
*/var nH=Object.freeze({__proto__:null,json:[{tfOpName:"ConcatV2",category:"slice_join",inputs:[{start:0,end:-1,name:"tensors",type:"tensors"},{start:-1,name:"axis",type:"number"}],attrs:[{tfName:"N",name:"n",type:"number",defaultValue:2}]},{tfOpName:"Concat",category:"slice_join",inputs:[{start:1,end:0,name:"tensors",type:"tensors"},{start:0,name:"axis",type:"number"}],attrs:[{tfName:"N",name:"n",type:"number",defaultValue:2}]},{tfOpName:"GatherV2",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"},{start:2,name:"axis",type:"number",defaultValue:0}],attrs:[{tfName:"batch_dims",name:"batchDims",type:"number",defaultValue:0}]},{tfOpName:"Gather",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"}],attrs:[{tfName:"validate_indices",name:"validateIndices",type:"bool",notSupported:!0}]},{tfOpName:"Reverse",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"dims",type:"bool[]"}]},{tfOpName:"ReverseV2",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}]},{tfOpName:"Slice",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"begin",type:"number[]"},{start:2,name:"size",type:"number[]"}]},{tfOpName:"StridedSlice",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"begin",type:"number[]"},{start:2,name:"end",type:"number[]"},{start:3,name:"strides",type:"number[]"}],attrs:[{tfName:"begin_mask",name:"beginMask",type:"number",defaultValue:0},{tfName:"end_mask",name:"endMask",type:"number",defaultValue:0},{tfName:"new_axis_mask",name:"newAxisMask",type:"number",defaultValue:0},{tfName:"ellipsis_mask",name:"ellipsisMask",type:"number",defaultValue:0},{tfName:"shrink_axis_mask",name:"shrinkAxisMask",type:"number",defaultValue:0}]},{tfOpName:"Pack",category:"slice_join",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}],attrs:[{tfName:"axis",name:"axis",type:"number",defaultValue:0}]},{tfOpName:"Unpack",category:"slice_join",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"axis",name:"axis",type:"number",defaultValue:0},{tfName:"num",name:"num",type:"number",defaultValue:0,notSupported:!0}]},{tfOpName:"Tile",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"reps",type:"number[]"}]},{tfOpName:"Split",category:"slice_join",inputs:[{start:0,name:"axis",type:"number",defaultValue:0},{start:1,name:"x",type:"tensor"}],attrs:[{tfName:"num_split",name:"numOrSizeSplits",type:"number",defaultValue:1}]},{tfOpName:"SplitV",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"numOrSizeSplits",type:"number[]"},{start:2,name:"axis",type:"number",defaultValue:0}]},{tfOpName:"ScatterNd",category:"slice_join",inputs:[{start:0,name:"indices",type:"tensor"},{start:1,name:"values",type:"tensor"},{start:2,name:"shape",type:"number[]"}]},{tfOpName:"GatherNd",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"}]},{tfOpName:"SparseToDense",category:"slice_join",inputs:[{start:0,name:"sparseIndices",type:"tensor"},{start:1,name:"outputShape",type:"number[]"},{start:2,name:"sparseValues",type:"tensor"},{start:3,name:"defaultValue",type:"tensor"}],attrs:[{tfName:"validate_indices",name:"validateIndices",type:"bool",defaultValue:!1,notSupported:!0}]},{tfOpName:"TensorScatterUpdate",category:"slice_join",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"indices",type:"tensor"},{start:2,name:"values",type:"tensor"}]}]});
|
|
16722
16722
|
/**
|
|
16723
16723
|
* @license
|
|
16724
16724
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16734,7 +16734,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16734
16734
|
* See the License for the specific language governing permissions and
|
|
16735
16735
|
* limitations under the License.
|
|
16736
16736
|
* =============================================================================
|
|
16737
|
-
*/var
|
|
16737
|
+
*/var sH=Object.freeze({__proto__:null,json:[{tfOpName:"SparseFillEmptyRows",category:"sparse",inputs:[{start:0,name:"indices",type:"tensor"},{start:1,name:"values",type:"tensor"},{start:2,name:"denseShape",type:"tensor"},{start:3,name:"defaultValue",type:"tensor"}]},{tfOpName:"SparseReshape",category:"sparse",inputs:[{start:0,name:"inputIndices",type:"tensor"},{start:1,name:"inputShape",type:"tensor"},{start:2,name:"newShape",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"SparseSegmentMean",category:"sparse",inputs:[{start:0,name:"data",type:"tensor"},{start:1,name:"indices",type:"tensor"},{start:2,name:"segmentIds",type:"tensor"}]},{tfOpName:"SparseSegmentSum",category:"sparse",inputs:[{start:0,name:"data",type:"tensor"},{start:1,name:"indices",type:"tensor"},{start:2,name:"segmentIds",type:"tensor"}]}]});
|
|
16738
16738
|
/**
|
|
16739
16739
|
* @license
|
|
16740
16740
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16750,7 +16750,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16750
16750
|
* See the License for the specific language governing permissions and
|
|
16751
16751
|
* limitations under the License.
|
|
16752
16752
|
* =============================================================================
|
|
16753
|
-
*/var
|
|
16753
|
+
*/var rH=Object.freeze({__proto__:null,json:[{tfOpName:"FFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"IFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"RFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"fft_length",type:"number",notSupported:!0}]},{tfOpName:"IRFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"fft_length",type:"number",notSupported:!0}]}]});
|
|
16754
16754
|
/**
|
|
16755
16755
|
* @license
|
|
16756
16756
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16766,7 +16766,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16766
16766
|
* See the License for the specific language governing permissions and
|
|
16767
16767
|
* limitations under the License.
|
|
16768
16768
|
* =============================================================================
|
|
16769
|
-
*/var
|
|
16769
|
+
*/var aH=Object.freeze({__proto__:null,json:[{tfOpName:"StaticRegexReplace",category:"string",inputs:[{start:0,name:"input",type:"tensor"}],attrs:[{tfName:"pattern",name:"pattern",type:"string"},{tfName:"rewrite",name:"rewrite",type:"string"},{tfName:"replace_global",name:"replaceGlobal",type:"bool"}]},{tfOpName:"StringNGrams",category:"string",inputs:[{start:0,name:"data",type:"tensor"},{start:1,name:"dataSplits",type:"tensor"}],attrs:[{tfName:"separator",name:"separator",type:"string"},{tfName:"ngram_widths",name:"nGramWidths",type:"number[]"},{tfName:"left_pad",name:"leftPad",type:"string"},{tfName:"right_pad",name:"rightPad",type:"string"},{tfName:"pad_width",name:"padWidth",type:"number"},{tfName:"preserve_short_sequences",name:"preserveShortSequences",type:"bool"}],outputs:["ngrams","ngrams_splits"]},{tfOpName:"StringSplit",category:"string",inputs:[{start:0,name:"input",type:"tensor"},{start:1,name:"delimiter",type:"tensor"}],attrs:[{tfName:"skip_empty",name:"skipEmpty",type:"bool"}],outputs:["indices","values","shape"]},{tfOpName:"StringToHashBucketFast",category:"string",inputs:[{start:0,name:"input",type:"tensor"}],attrs:[{tfName:"num_buckets",name:"numBuckets",type:"number"}]}]});
|
|
16770
16770
|
/**
|
|
16771
16771
|
* @license
|
|
16772
16772
|
* Copyright 2023 Google LLC. All Rights Reserved.
|
|
@@ -16782,7 +16782,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16782
16782
|
* See the License for the specific language governing permissions and
|
|
16783
16783
|
* limitations under the License.
|
|
16784
16784
|
* =============================================================================
|
|
16785
|
-
*/var
|
|
16785
|
+
*/var iH=Object.freeze({__proto__:null,json:[{tfOpName:"Cast",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"SrcT",name:"sdtype",type:"dtype",notSupported:!0},{tfName:"DstT",name:"dtype",type:"dtype"}]},{tfOpName:"ExpandDims",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"MirrorPad",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"padding",type:"number[]"}],attrs:[{tfName:"mode",name:"mode",type:"string"}]},{tfOpName:"Pad",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"padding",type:"number[]"}],attrs:[{tfName:"constant_value",name:"constantValue",type:"number",defaultValue:0}]},{tfOpName:"PadV2",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"padding",type:"number[]"},{start:2,name:"constantValue",type:"number",defaultValue:0}]},{tfOpName:"Reshape",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"shape",type:"number[]"}]},{tfOpName:"EnsureShape",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"shape",type:"number[]"}]},{tfOpName:"Squeeze",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"axis",tfDeprecatedName:"squeeze_dims",name:"axis",type:"number[]"}]},{tfOpName:"SpaceToBatchND",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"blockShape",type:"number[]"},{start:2,name:"paddings",type:"number[]"}]},{tfOpName:"BatchToSpaceND",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"blockShape",type:"number[]"},{start:2,name:"crops",type:"number[]"}]},{tfOpName:"DepthToSpace",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"block_size",name:"blockSize",type:"number"},{tfName:"data_format",name:"dataFormat",type:"string"}]},{tfOpName:"BroadcastTo",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"shape",type:"number[]"}],attrs:[]},{tfOpName:"BroadcastArgs",category:"transformation",inputs:[{start:0,name:"s0",type:"tensor"},{start:1,name:"s1",type:"tensor"}],attrs:[]}]});
|
|
16786
16786
|
/**
|
|
16787
16787
|
* @license
|
|
16788
16788
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16798,7 +16798,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16798
16798
|
* See the License for the specific language governing permissions and
|
|
16799
16799
|
* limitations under the License.
|
|
16800
16800
|
* =============================================================================
|
|
16801
|
-
*/class
|
|
16801
|
+
*/class oH{static get Instance(){return this._instance||(this._instance=new this)}constructor(){const e=[].concat(...[UG,VG,GG,HG,qG,jG,XG,KG,YG,QG,JG,ZG,eH,tH,nH,sH,rH,aH,iH].map((e=>e.json)));this.opMappers=e.reduce(((e,t)=>(e[t.tfOpName]=t,e)),{})}transformGraph(e,t={}){const n=e.node,s=[],r=[],a=[],i=n.reduce(((e,t)=>(e[t.name]=this.mapNode(t),t.op.startsWith("Placeholder")?s.push(e[t.name]):"Const"===t.op?r.push(e[t.name]):null!=t.input&&0!==t.input.length||a.push(e[t.name]),e)),{});let o=[];const u=[];let l={},c={};null!=t&&(l=this.mapSignatureEntries(t.inputs),c=this.mapSignatureEntries(t.outputs));const h=Object.keys(i);h.forEach((e=>{const t=i[e];t.inputNames.forEach(((e,n)=>{const[s,,r]=LG(e),a=i[s];if(null!=a.outputs){const e=a.outputs.indexOf(r);if(-1!==e){const r=`${s}:${e}`;t.inputNames[n]=r}}t.inputs.push(a),a.children.push(t)}))})),0===Object.keys(c).length?h.forEach((e=>{const t=i[e];0===t.children.length&&u.push(t)})):Object.keys(c).forEach((e=>{const[t]=LG(e),n=i[t];null!=n&&(n.signatureKey=c[e],u.push(n))})),Object.keys(l).length>0?Object.keys(l).forEach((e=>{const[t]=LG(e),n=i[t];n&&(n.signatureKey=l[e],o.push(n))})):o=s;let d={};null!=e.library&&null!=e.library.function&&(d=e.library.function.reduce(((e,t)=>(e[t.signature.name]=this.mapFunction(t),e)),{}));const p={nodes:i,inputs:o,outputs:u,weights:r,placeholders:s,signature:t,functions:d};return a.length>0&&(p.initNodes=a),p}mapSignatureEntries(e){return Object.keys(e||{}).reduce(((t,n)=>(t[e[n].name]=n,t)),{})}mapNode(e){const t=FG(e.op)||this.opMappers[e.op]||{};null==e.attr&&(e.attr={});const n={name:e.name,op:e.op,category:t.category,inputNames:(e.input||[]).map((e=>e.startsWith("^")?e.slice(1):e)),inputs:[],children:[],inputParams:{},attrParams:{},rawAttrs:e.attr,outputs:t.outputs};return null!=t.inputs&&(n.inputParams=t.inputs.reduce(((e,t)=>(e[t.name]={type:t.type,inputIndexStart:t.start,inputIndexEnd:t.end},e)),{})),null!=t.attrs&&(n.attrParams=t.attrs.reduce(((t,n)=>{const s=n.type;let r;switch(n.type){case"string":r=lH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=lH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"string[]":r=xH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=xH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"number":r=hH(e.attr,n.tfName,n.defaultValue||0),void 0===r&&n.tfDeprecatedName&&(r=hH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"number[]":r=bH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=bH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"bool":r=cH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=cH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"bool[]":r=kH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=kH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"shape":r=yH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=yH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"shape[]":r=wH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=wH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"dtype":r=fH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=fH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"dtype[]":r=mH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=mH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"func":r=pH(e.attr,n.tfName,n.defaultValue),void 0===r&&n.tfDeprecatedName&&(r=pH(e.attr,n.tfDeprecatedName,n.defaultValue));break;case"tensor":case"tensors":break;default:throw new Error(`Unsupported param type: ${n.type} for op: ${e.op}`)}return t[n.name]={value:r,type:s},t}),{})),n}mapFunction(e){const t=e.nodeDef,n=[];let s={};null!=t&&(s=t.reduce(((e,t)=>(e[t.name]=this.mapNode(t),"Const"===t.op&&n.push(e[t.name]),e)),{}));const r=[],a=[];e.signature.inputArg.forEach((e=>{const[t]=LG(e.name),n={name:t,op:"Placeholder",inputs:[],inputNames:[],category:"graph",inputParams:{},attrParams:{dtype:{value:dH(e.type),type:"dtype"}},children:[]};n.signatureKey=e.name,r.push(n),s[t]=n}));Object.keys(s).forEach((e=>{const t=s[e];t.inputNames.forEach(((e,n)=>{const[r,,a]=LG(e),i=s[r];if(null!=i.outputs){const e=i.outputs.indexOf(a);if(-1!==e){const s=`${r}:${e}`;t.inputNames[n]=s}}t.inputs.push(i),i.children.push(t)}))}));const i=e.ret;e.signature.outputArg.forEach((e=>{const[t,n]=LG(i[e.name]),r=s[t];null!=r&&(r.defaultOutput=n,a.push(r))}));const o=this.mapArgsToSignature(e);return{nodes:s,inputs:r,outputs:a,weights:n,placeholders:[],signature:o}}mapArgsToSignature(e){return{methodName:e.signature.name,inputs:e.signature.inputArg.reduce(((e,t)=>(e[t.name]=this.mapArgToTensorInfo(t),e)),{}),outputs:e.signature.outputArg.reduce(((t,n)=>(t[n.name]=this.mapArgToTensorInfo(n,e.ret),t)),{})}}mapArgToTensorInfo(e,t){let n=e.name;return null!=t&&(n=t[n]),{name:n,dtype:e.type}}}function uH(e,t){const n=Array.isArray(e)?String.fromCharCode.apply(null,e):function(e){const t=Qe().global;if(void 0!==t.atob)return t.atob(e);if("undefined"!=typeof Buffer)return new Buffer(e,"base64").toString();throw new Error("Unable to decode base64 in this environment. Missing built-in atob() or Buffer()")}(e);return t?n:n.toLowerCase()}function lH(e,t,n,s=!1){const r=e[t];return null!=r?uH(r.s,s):n}function cH(e,t,n){const s=e[t];return s?s.b:n}function hH(e,t,n){const s=e[t]||{},r=null!=s.i?s.i:null!=s.f?s.f:n;return"number"==typeof r?r:parseInt(r,10)}function dH(e){switch("string"==typeof e&&(e=EG[e]),e){case EG.DT_FLOAT:case EG.DT_HALF:return"float32";case EG.DT_INT32:case EG.DT_INT64:case EG.DT_INT8:case EG.DT_UINT8:return"int32";case EG.DT_BOOL:return"bool";case EG.DT_DOUBLE:return"float32";case EG.DT_STRING:return"string";case EG.DT_COMPLEX64:case EG.DT_COMPLEX128:return"complex64";default:return null}}function pH(e,t,n){const s=e[t];return s&&s.func?s.func.name:n}function fH(e,t,n){const s=e[t];return s&&s.type?dH(s.type):n}function mH(e,t,n){const s=e[t];return s&&s.list&&s.list.type?s.list.type.map((e=>dH(e))):n}function gH(e){if(!e.unknownRank)return null!=e.dim?e.dim.map((e=>"number"==typeof e.size?e.size:parseInt(e.size,10))):[]}function yH(e,t,n){const s=e[t];return s&&s.shape?gH(s.shape):n}function bH(e,t,n){const s=e[t];return s?((s.list.f&&s.list.f.length?s.list.f:s.list.i)||[]).map((e=>"number"==typeof e?e:parseInt(e,10))):n}function xH(e,t,n,s=!1){const r=e[t];return r&&r.list&&r.list.s?r.list.s.map((e=>uH(e,s))):n}function wH(e,t,n){const s=e[t];return s&&s.list&&s.list.shape?s.list.shape.map((e=>gH(e))):n}function kH(e,t,n){const s=e[t];return s&&s.list&&s.list.b?s.list.b:n}
|
|
16802
16802
|
/**
|
|
16803
16803
|
* @license
|
|
16804
16804
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -16814,7 +16814,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16814
16814
|
* See the License for the specific language governing permissions and
|
|
16815
16815
|
* limitations under the License.
|
|
16816
16816
|
* =============================================================================
|
|
16817
|
-
*/class
|
|
16817
|
+
*/class vH{constructor(e,t,n){this.node=e,this.tensorMap=t,this.context=n,this.inputs=[],this.attrs={},this.inputs=e.inputNames.map((e=>this.getInput(e))),null!=e.rawAttrs&&(this.attrs=Object.keys(e.rawAttrs).reduce(((e,t)=>(e[t]=this.getAttr(t),e)),{}))}getInput(e){return MG(e,this.tensorMap,this.context)}getAttr(e,t){const n=this.node.rawAttrs[e];if(null!=n.tensor)return MG(e,this.tensorMap,this.context);if(null!=n.i||null!=n.f)return hH(this.node.rawAttrs,e,t);if(null!=n.s)return lH(this.node.rawAttrs,e,t);if(null!=n.b)return cH(this.node.rawAttrs,e,t);if(null!=n.shape)return yH(this.node.rawAttrs,e,t);if(null!=n.type)return fH(this.node.rawAttrs,e,t);if(null!=n.list){if(null!=n.list.i||null!=n.list.f)return bH(this.node.rawAttrs,e,t);if(null!=n.list.s)return xH(this.node.rawAttrs,e,t);if(null!=n.list.shape)return wH(this.node.rawAttrs,e,t);if(null!=n.list.b)return kH(this.node.rawAttrs,e,t);if(null!=n.list.type)return mH(this.node.rawAttrs,e,t)}return t}}
|
|
16818
16818
|
/**
|
|
16819
16819
|
* @license
|
|
16820
16820
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -16830,7 +16830,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16830
16830
|
* See the License for the specific language governing permissions and
|
|
16831
16831
|
* limitations under the License.
|
|
16832
16832
|
* =============================================================================
|
|
16833
|
-
*/var
|
|
16833
|
+
*/var IH=Object.freeze({__proto__:null,OP_SCOPE_SUFFIX:ui,abs:Ro,acos:Eo,acosh:Ao,add:Co,addN:_o,all:Fo,any:Do,argMax:Mo,argMin:Oo,asin:Lo,asinh:Po,atan:zo,atan2:Bo,atanh:Wo,avgPool:ru,avgPool3d:au,basicLSTMCell:hu,batchNorm:pu,batchNorm2d:fu,batchNorm3d:mu,batchNorm4d:gu,batchToSpaceND:du,bincount:yu,bitwiseAnd:bu,booleanMaskAsync:Zh,broadcastArgs:xu,broadcastTo:wu,buffer:ko,cast:vo,ceil:ku,clipByValue:Iu,clone:Io,complex:ci,concat:iu,concat1d:Su,concat2d:Cu,concat3d:Nu,concat4d:Tu,conv1d:Ru,conv2d:$u,conv2dTranspose:Au,conv3d:_u,conv3dTranspose:Du,cos:Mu,cosh:Ou,cosineWindow:od,cumprod:Lu,cumsum:Pu,denseBincount:zu,depthToSpace:Bu,depthwiseConv2d:Wu,diag:Uu,dilation2d:Vu,div:To,divNoNan:Yu,dot:Qu,dropout:ad,einsum:Ju,elu:Zu,enclosingPowerOfTwo:id,ensureShape:el,equal:ju,erf:tl,euclideanNorm:xl,exp:wl,expandDims:kl,expm1:vl,eye:Sl,fft:Th,fill:vu,floor:Cl,floorDiv:No,fused:xd,gather:Nl,gatherND:rd,greater:Tl,greaterEqual:$l,ifft:$h,imag:Rl,image:gp,inTopKAsync:ud,irfft:Rh,isFinite:El,isInf:Al,isNaN:_l,leakyRelu:Fl,less:Dl,lessEqual:Ml,linalg:yp,linspace:function(e,t,n){if(n<=0)throw new Error("The number of values should be positive.");const s={start:e,stop:t,num:n};return Ja.runKernel(Tn,{},s)},localResponseNormalization:Ol,log:Ll,log1p:Pl,logSigmoid:Ul,logSoftmax:Gl,logSumExp:Hl,logicalAnd:ql,logicalNot:jl,logicalOr:Xl,logicalXor:Kl,losses:bp,lowerBound:function(e,t){return Ql(e,t,"left")},matMul:ou,max:cl,maxPool:Jl,maxPool3d:Zl,maxPoolWithArgmax:ec,maximum:tc,mean:nc,meshgrid:function(e,t,{indexing:n="xy"}={}){if("xy"!==n&&"ij"!==n)throw new TypeError(`${n} is not a valid third argument to meshgrid`);if(void 0===e)return[];let s=ii(e,"x","meshgrid",e instanceof _a?e.dtype:"float32");if(void 0===t)return[s];let r=ii(t,"y","meshgrid",t instanceof _a?t.dtype:"float32");const a=be(s.shape),i=be(r.shape);return"xy"===n?(s=su(s,[1,-1]),r=su(r,[-1,1]),[ou(rc([i,1],s.dtype),s),ou(r,rc([1,a],r.dtype))]):(s=su(s,[-1,1]),r=su(r,[1,-1]),[ou(s,rc([1,i],s.dtype)),ou(rc([a,1],r.dtype),r)])},min:hl,minimum:ac,mirrorPad:ic,mod:oc,moments:uc,movingAverage:td,mul:$o,multiRNNCell:lc,multinomial:cc,neg:Bl,norm:bl,notEqual:hc,oneHot:dc,ones:rc,onesLike:pc,op:li,outerProduct:fc,pad:mc,pad1d:gc,pad2d:yc,pad3d:bc,pad4d:xc,pool:kc,pow:dl,prelu:vc,print:So,prod:Ic,raggedGather:Sc,raggedRange:Cc,raggedTensorToTensor:Nc,rand:Tc,randomGamma:Zc,randomNormal:eh,randomStandardNormal:th,randomUniform:nh,randomUniformInt:sh,range:rh,real:ah,reciprocal:ih,relu:oh,relu6:uh,reshape:su,reverse:lh,reverse1d:ch,reverse2d:hh,reverse3d:dh,reverse4d:ph,rfft:Ah,round:fh,rsqrt:mh,scalar:pl,scatterND:nd,searchSorted:Ql,selu:gh,separableConv2d:yh,setdiff1dAsync:bh,sigmoid:uu,sign:xh,signal:mp,sin:wh,sinh:kh,slice:lu,slice1d:vh,slice2d:Ih,slice3d:Sh,slice4d:Ch,softmax:Nh,softplus:Wl,spaceToBatchND:wc,sparse:xp,sparseToDense:sd,spectral:fp,split:Eh,sqrt:fl,square:ml,squaredDifference:_h,squeeze:Fh,stack:Dh,step:Mh,stridedSlice:Oh,string:wp,sub:Vl,sum:gl,tan:Lh,tanh:cu,tensor:di,tensor1d:Ph,tensor2d:zh,tensor3d:Bh,tensor4d:function(e,t,n){if(ye(e),null!=t&&4!==t.length)throw new Error("tensor4d() requires shape to have four numbers");const s=si(e,n);if(4!==s.length&&1!==s.length)throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");if(1===s.length&&null==t)throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");return hi(e,t,s,n)}
|
|
16834
16834
|
/**
|
|
16835
16835
|
* @license
|
|
16836
16836
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16895,7 +16895,7 @@ const EG={};function AG(e){return EG[e]}
|
|
|
16895
16895
|
* limitations under the License.
|
|
16896
16896
|
* =============================================================================
|
|
16897
16897
|
*/
|
|
16898
|
-
function
|
|
16898
|
+
function SH(e,t,n=""){if("number"!=typeof e&&"number"!=typeof t){me(e.length===t.length,(()=>n+` Shapes ${e} and ${t} must match`));for(let s=0;s<e.length;s++){const r=e[s],a=t[s];me(r<0||a<0||r===a,(()=>n+` Shapes ${e} and ${t} must match`))}}}function CH(e){return"number"!=typeof e&&!e.some((e=>e<0))}function NH(e,t,n){let s=TH(e,n);const r=!CH(s);if(r&&0===t.length)throw new Error(`Tried to calculate elements of an empty list with non-fully-defined elementShape: ${s}`);if(r&&t.forEach((e=>{s=TH(e.shape,s)})),!CH(s))throw new Error(`Non-fully-defined elementShape: ${s}`);return s}function TH(e,t){if("number"==typeof e)return t;if("number"==typeof t)return e;if(e.length!==t.length)throw new Error(`Incompatible ranks during merge: ${e} vs. ${t}`);const n=[];for(let s=0;s<e.length;++s){const r=e[s],a=t[s];if(r>=0&&a>=0&&r!==a)throw new Error(`Incompatible shape during merge: ${e} vs. ${t}`);n[s]=r>=0?r:a}return n}
|
|
16899
16899
|
/**
|
|
16900
16900
|
* @license
|
|
16901
16901
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16911,7 +16911,7 @@ function vH(e,t,n=""){if("number"!=typeof e&&"number"!=typeof t){me(e.length===t
|
|
|
16911
16911
|
* See the License for the specific language governing permissions and
|
|
16912
16912
|
* limitations under the License.
|
|
16913
16913
|
* =============================================================================
|
|
16914
|
-
*/class
|
|
16914
|
+
*/class $H{constructor(e,t,n,s,r,a,i){this.name=e,this.dtype=t,this.maxSize=n,this.elementShape=s,this.identicalElementShapes=r,this.dynamicSize=a,this.clearAfterRead=i,this.tensors=[],this.closed_=!1,this.idTensor=pl(0),wi(this.idTensor)}get id(){return this.idTensor.id}get closed(){return this.closed_}clearAndClose(e){this.tensors.forEach((t=>{null!=e&&e.has(t.tensor.id)||t.tensor.dispose()})),this.tensors=[],this.closed_=!0,this.idTensor.dispose()}size(){return this.tensors.length}read(e){if(this.closed_)throw new Error(`TensorArray ${this.name} has already been closed.`);if(e<0||e>=this.size())throw new Error(`Tried to read from index ${e}, but array size is: ${this.size()}`);const t=this.tensors[e];if(t.cleared)throw new Error(`TensorArray ${this.name}: Could not read index ${e} twice because it was cleared after a previous read (perhaps try setting clear_after_read = false?).`);return this.clearAfterRead&&(t.cleared=!0),t.read=!0,t.tensor}readMany(e){return e.map((e=>this.read(e)))}write(e,t){if(this.closed_)throw new Error(`TensorArray ${this.name} has already been closed.`);if(e<0||!this.dynamicSize&&e>=this.maxSize)throw new Error(`Tried to write to index ${e}, but array is not resizeable and size is: ${this.maxSize}`);const n=this.tensors[e]||{};if(t.dtype!==this.dtype)throw new Error(`TensorArray ${this.name}: Could not write to TensorArray index ${e},\n because the value dtype is ${t.dtype}, but TensorArray dtype is ${this.dtype}.`);if(0!==this.size()||null!=this.elementShape&&0!==this.elementShape.length||(this.elementShape=t.shape),SH(this.elementShape,t.shape,`TensorArray ${this.name}: Could not write to TensorArray index ${e}.`),n.read)throw new Error(`TensorArray ${this.name}: Could not write to TensorArray index ${e}, because it has already been read.`);if(n.written)throw new Error(`TensorArray ${this.name}: Could not write to TensorArray index ${e}, because it has already been written.`);n.tensor=t,wi(t),n.written=!0,this.tensors[e]=n}writeMany(e,t){if(e.length!==t.length)throw new Error(`TensorArray ${this.name}: could not write multiple tensors,because the index size: ${e.length} is not the same as tensors size: ${t.length}.`);e.forEach(((e,n)=>this.write(e,t[n])))}gather(e,t){if(t&&t!==this.dtype)throw new Error(`TensorArray dtype is ${this.dtype} but gather requested dtype ${t}`);if(e)e=e.slice(0,this.size());else{e=[];for(let t=0;t<this.size();t++)e.push(t)}if(0===e.length)return di([],[0].concat(this.elementShape));const n=this.readMany(e);return SH(this.elementShape,n[0].shape,"TensorArray shape mismatch: "),Dh(n,0)}concat(e){if(e&&e!==this.dtype)throw new Error(`TensorArray dtype is ${this.dtype} but concat requested dtype ${e}`);if(0===this.size())return di([],[0].concat(this.elementShape));const t=[];for(let e=0;e<this.size();e++)t.push(e);const n=this.readMany(t);return SH(this.elementShape,n[0].shape,`TensorArray shape mismatch: tensor array shape (${this.elementShape}) vs first tensor shape (${n[0].shape})`),iu(n,0)}scatter(e,t){if(t.dtype!==this.dtype)throw new Error(`TensorArray dtype is ${this.dtype} but tensor has dtype ${t.dtype}`);if(e.length!==t.shape[0])throw new Error(`Expected len(indices) == tensor.shape[0], but saw: ${e.length} vs. ${t.shape[0]}`);const n=Math.max(...e);if(!this.dynamicSize&&n>=this.maxSize)throw new Error(`Max index must be < array size (${n} vs. ${this.maxSize})`);this.writeMany(e,Kh(t,0))}split(e,t){if(t.dtype!==this.dtype)throw new Error(`TensorArray dtype is ${this.dtype} but tensor has dtype ${t.dtype}`);let n=0;const s=e.map((e=>(n+=e,n)));if(n!==t.shape[0])throw new Error(`Expected sum of lengths to be equal to\n tensor.shape[0], but sum of lengths is\n ${n}, and tensor's shape is: ${t.shape}`);if(!this.dynamicSize&&e.length!==this.maxSize)throw new Error(`TensorArray's size is not equal to the size of lengths (${this.maxSize} vs. ${e.length}), and the TensorArray is not marked as dynamically resizeable`);const r=0===n?0:t.size/n,a=[];bi((()=>{t=su(t,[1,n,r]);for(let n=0;n<e.length;++n){const i=[0,0===n?0:s[n-1],0],o=[1,e[n],r];a[n]=su(lu(t,i,o),this.elementShape)}return a}));const i=[];for(let t=0;t<e.length;t++)i[t]=t;this.writeMany(i,a)}}
|
|
16915
16915
|
/**
|
|
16916
16916
|
* @license
|
|
16917
16917
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -16927,7 +16927,7 @@ function vH(e,t,n=""){if("number"!=typeof e&&"number"!=typeof t){me(e.length===t
|
|
|
16927
16927
|
* See the License for the specific language governing permissions and
|
|
16928
16928
|
* limitations under the License.
|
|
16929
16929
|
* =============================================================================
|
|
16930
|
-
*/class
|
|
16930
|
+
*/class RH{get id(){return this.idTensor.id}constructor(e,t,n,s=-1){this.tensors=e,this.elementShape=t,this.elementDtype=n,null!=e&&e.forEach((e=>{if(n!==e.dtype)throw new Error(`Invalid data types; op elements ${n}, but list elements ${e.dtype}`);SH(t,e.shape,"TensorList shape mismatch: "),wi(e)})),this.idTensor=pl(0),this.maxNumElements=s,wi(this.idTensor)}copy(){return new RH([...this.tensors],this.elementShape,this.elementDtype)}clearAndClose(e){this.tensors.forEach((t=>{null!=e&&e.has(t.id)||t.dispose()})),this.tensors.length=0,this.idTensor.dispose()}size(){return this.tensors.length}stack(e,t,n=-1){if(t!==this.elementDtype)throw new Error(`Invalid data types; op elements ${t}, but list elements ${this.elementDtype}`);if(-1!==n&&this.tensors.length!==n)throw new Error(`Operation expected a list with ${n} elements but got a list with ${this.tensors.length} elements.`);SH(e,this.elementShape,"TensorList shape mismatch: ");const s=NH(this.elementShape,this.tensors,e);return bi((()=>{const e=this.tensors.map((e=>su(e,s)));return Dh(e,0)}))}popBack(e,t){if(t!==this.elementDtype)throw new Error(`Invalid data types; op elements ${t}, but list elements ${this.elementDtype}`);if(0===this.size())throw new Error("Trying to pop from an empty list.");const n=NH(this.elementShape,this.tensors,e),s=this.tensors.pop();return s.kept=!1,SH(s.shape,e,"TensorList shape mismatch: "),su(s,n)}pushBack(e){if(e.dtype!==this.elementDtype)throw new Error(`Invalid data types; op elements ${e.dtype}, but list elements ${this.elementDtype}`);if(SH(e.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");wi(e),this.tensors.push(e)}resize(e){if(e<0)throw new Error(`TensorListResize expects size to be non-negative. Got: ${e}`);if(-1!==this.maxNumElements&&e>this.maxNumElements)throw new Error(`TensorListResize input size ${e} is greater maxNumElement ${this.maxNumElements}.`);const t=new RH([],this.elementShape,this.elementDtype,this.maxNumElements);t.tensors.length=e;for(let n=0;n<Math.min(this.tensors.length,e);++n)t.tensors[n]=this.tensors[n];return t}getItem(e,t,n){if(n!==this.elementDtype)throw new Error(`Invalid data types; op elements ${n}, but list elements ${this.elementDtype}`);if(e<0||e>this.tensors.length)throw new Error(`Trying to access element ${e} in a list with ${this.tensors.length} elements.`);if(null==this.tensors[e])throw new Error(`element at index ${e} is null.`);SH(this.tensors[e].shape,t,"TensorList shape mismatch: ");const s=NH(this.elementShape,this.tensors,t);return su(this.tensors[e],s)}setItem(e,t){if(t.dtype!==this.elementDtype)throw new Error(`Invalid data types; op elements ${t.dtype}, but list elements ${this.elementDtype}`);if(e<0||-1!==this.maxNumElements&&e>=this.maxNumElements)throw new Error(`Trying to set element ${e} in a list with max ${this.maxNumElements} elements.`);SH(this.elementShape,t.shape,"TensorList shape mismatch: "),wi(t),null!=this.tensors[e]&&(this.tensors[e].kept=!1),this.tensors[e]=t}gather(e,t,n){if(t!==this.elementDtype)throw new Error(`Invalid data types; op elements ${t}, but list elements ${this.elementDtype}`);SH(this.elementShape,n,"TensorList shape mismatch: "),e=e.slice(0,this.size());const s=NH(this.elementShape,this.tensors,n);return 0===e.length?di([],[0].concat(s)):bi((()=>{const t=e.map((e=>su(this.tensors[e],s)));return Dh(t,0)}))}concat(e,t){if(e&&e!==this.elementDtype)throw new Error(`TensorList dtype is ${this.elementDtype} but concat requested dtype ${e}`);SH(this.elementShape,t,"TensorList shape mismatch: ");const n=NH(this.elementShape,this.tensors,t);return 0===this.size()?di([],[0].concat(n)):bi((()=>{const e=this.tensors.map((e=>su(e,n)));return iu(e,0)}))}}
|
|
16931
16931
|
/**
|
|
16932
16932
|
* @license
|
|
16933
16933
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16944,7 +16944,7 @@ function vH(e,t,n=""){if("number"!=typeof e&&"number"!=typeof t){me(e.length===t
|
|
|
16944
16944
|
* limitations under the License.
|
|
16945
16945
|
* =============================================================================
|
|
16946
16946
|
*/
|
|
16947
|
-
const
|
|
16947
|
+
const EH=async(e,t,n)=>{switch(e.op){case"If":case"StatelessIf":{const s=DG("thenBranch",e,t,n),r=DG("elseBranch",e,t,n),a=DG("cond",e,t,n),i=DG("args",e,t,n);return(await a.data())[0]?n.functionMap[s].executeFunctionAsync(i,n.tensorArrayMap,n.tensorListMap):n.functionMap[r].executeFunctionAsync(i,n.tensorArrayMap,n.tensorListMap)}case"While":case"StatelessWhile":{const s=DG("body",e,t,n),r=DG("cond",e,t,n),a=DG("args",e,t,n),i=await n.functionMap[r].executeFunctionAsync(a,n.tensorArrayMap,n.tensorListMap),o=a.map((e=>e.id));let u=await i[0].data();i.forEach((e=>{e.kept||-1!==o.indexOf(e.id)||e.dispose()}));let l=a;for(;u[0];){const e=l;l=await n.functionMap[s].executeFunctionAsync(l,n.tensorArrayMap,n.tensorListMap);const t=l.map((e=>e.id));e.forEach((e=>{e.kept||-1!==o.indexOf(e.id)||-1!==t.indexOf(e.id)||e.dispose()}));const a=await n.functionMap[r].executeFunctionAsync(l,n.tensorArrayMap,n.tensorListMap);u=await a[0].data(),a.forEach((e=>{e.kept||-1!==o.indexOf(e.id)||-1!==t.indexOf(e.id)||e.dispose()}))}return l}case"LoopCond":return[WG(DG("pred",e,t,n))];case"Switch":{const s=DG("pred",e,t,n);let r=DG("data",e,t,n);return r.kept||(r=WG(r)),(await s.data())[0]?[void 0,r]:[r,void 0]}case"Merge":{const s=e.inputNames.find((e=>void 0!==MG(e,t,n)));if(s){return[WG(MG(s,t,n))]}return}case"Enter":{const s=DG("frameName",e,t,n),r=DG("tensor",e,t,n);return n.enterFrame(s),[WG(r)]}case"Exit":{const s=DG("tensor",e,t,n);return n.exitFrame(),[WG(s)]}case"NextIteration":{const s=DG("tensor",e,t,n);return n.nextIteration(),[WG(s)]}case"TensorArrayV3":{const s=DG("size",e,t,n),r=DG("dtype",e,t,n),a=DG("elementShape",e,t,n),i=DG("dynamicSize",e,t,n),o=DG("clearAfterRead",e,t,n),u=DG("identicalElementShapes",e,t,n),l=DG("name",e,t,n),c=new $H(l,r,s,a,u,i,o);return n.addTensorArray(c),[c.idTensor,pl(1)]}case"TensorArrayWriteV3":{const s=DG("tensorArrayId",e,t,n),r=DG("index",e,t,n),a=DG("tensor",e,t,n),i=n.getTensorArray(s.id);return i.write(r,a),[i.idTensor]}case"TensorArrayReadV3":{const s=DG("tensorArrayId",e,t,n),r=DG("index",e,t,n);return[n.getTensorArray(s.id).read(r)]}case"TensorArrayGatherV3":{const s=DG("tensorArrayId",e,t,n),r=DG("indices",e,t,n),a=DG("dtype",e,t,n);return[n.getTensorArray(s.id).gather(r,a)]}case"TensorArrayScatterV3":{const s=DG("tensorArrayId",e,t,n),r=DG("indices",e,t,n),a=DG("tensor",e,t,n),i=n.getTensorArray(s.id);return i.scatter(r,a),[i.idTensor]}case"TensorArrayConcatV3":{const s=DG("tensorArrayId",e,t,n),r=n.getTensorArray(s.id),a=DG("dtype",e,t,n);return[r.concat(a)]}case"TensorArraySplitV3":{const s=DG("tensorArrayId",e,t,n),r=DG("tensor",e,t,n),a=DG("lengths",e,t,n),i=n.getTensorArray(s.id);return i.split(a,r),[i.idTensor]}case"TensorArraySizeV3":{const s=DG("tensorArrayId",e,t,n);return[pl(n.getTensorArray(s.id).size(),"int32")]}case"TensorArrayCloseV3":{const s=DG("tensorArrayId",e,t,n),r=n.getTensorArray(s.id);return r.clearAndClose(),[r.idTensor]}case"TensorListSetItem":{const s=DG("tensorListId",e,t,n),r=DG("index",e,t,n),a=DG("tensor",e,t,n),i=n.getTensorList(s.id);return i.setItem(r,a),[i.idTensor]}case"TensorListGetItem":{const s=DG("tensorListId",e,t,n),r=DG("index",e,t,n),a=DG("elementShape",e,t,n),i=DG("elementDType",e,t,n);return[n.getTensorList(s.id).getItem(r,a,i)]}case"TensorListScatterV2":case"TensorListScatter":{const s=DG("indices",e,t,n),r=function(e,t,n,s){if(t.length!==e.shape[0])throw new Error(`Expected len(indices) == tensor.shape[0], but saw: ${t.length} vs. ${e.shape[0]}`);const r=Math.max(...t);if(null!=s&&-1!==s&&r>=s)throw new Error(`Max index must be < array size (${r} vs. ${s})`);const a=new RH([],n,e.dtype,s),i=Kh(e,0);return t.forEach(((e,t)=>{a.setItem(e,i[t])})),a}(DG("tensor",e,t,n),s,DG("elementShape",e,t,n),DG("numElements",e,t,n));return n.addTensorList(r),[r.idTensor]}case"TensorListReserve":case"EmptyTensorList":{const s=DG("elementShape",e,t,n),r=DG("elementDType",e,t,n);let a;a="TensorListReserve"===e.op?"numElements":"maxNumElements";const i=DG(a,e,t,n),o=function(e,t,n,s){return new RH([],e,t,s)}(s,r,0,"TensorListReserve"===e.op?-1:i);return n.addTensorList(o),[o.idTensor]}case"TensorListGather":{const s=DG("tensorListId",e,t,n),r=DG("indices",e,t,n),a=DG("elementShape",e,t,n),i=DG("elementDType",e,t,n);return[n.getTensorList(s.id).gather(r,i,a)]}case"TensorListStack":{const s=DG("tensorListId",e,t,n),r=DG("elementShape",e,t,n),a=DG("elementDType",e,t,n),i=DG("numElements",e,t,n);return[n.getTensorList(s.id).stack(r,a,i)]}case"TensorListFromTensor":{const s=function(e,t,n){const s=e.dtype;if(e.shape.length<1)throw new Error(`Tensor must be at least a vector, but saw shape: ${e.shape}`);if(e.dtype!==n)throw new Error(`Invalid data types; op elements ${e.dtype}, but list elements ${n}`);SH(e.shape.slice(1),t,"TensorList shape mismatch: ");const r=Kh(e);return new RH(r,t,s)}(DG("tensor",e,t,n),DG("elementShape",e,t,n),DG("elementDType",e,t,n));return n.addTensorList(s),[s.idTensor]}case"TensorListConcat":case"TensorListConcatV2":{const s=DG("tensorListId",e,t,n),r=n.getTensorList(s.id),a=DG("dtype",e,t,n),i=DG("elementShape",e,t,n);return[r.concat(a,i)]}case"TensorListPushBack":{const s=DG("tensorListId",e,t,n),r=DG("tensor",e,t,n),a=n.getTensorList(s.id);return a.pushBack(r),[a.idTensor]}case"TensorListPopBack":{const s=DG("tensorListId",e,t,n),r=DG("elementShape",e,t,n),a=DG("elementDType",e,t,n);return[n.getTensorList(s.id).popBack(r,a)]}case"TensorListSplit":{const s=DG("tensor",e,t,n),r=DG("elementShape",e,t,n),a=function(e,t,n){let s=0;const r=t.map((e=>(s+=e,s)));if(s!==e.shape[0])throw new Error(`Expected sum of lengths to be equal to\n tensor.shape[0], but sum of lengths is\n ${s}, and tensor's shape is: ${e.shape}`);const a=TH(e.shape.slice(1),n),i=0===s?0:e.size/s,o=bi((()=>{const n=[];e=su(e,[1,s,i]);for(let s=0;s<t.length;++s){const o=[0,0===s?0:r[s-1],0],u=[1,t[s],i];n[s]=su(lu(e,o,u),a)}return e.dispose(),n})),u=new RH([],n,e.dtype,t.length);for(let e=0;e<o.length;e++)u.setItem(e,o[e]);return u}(s,DG("lengths",e,t,n),r);return n.addTensorList(a),[a.idTensor]}case"TensorListLength":{const s=DG("tensorListId",e,t,n);return[pl(n.getTensorList(s.id).size(),"int32")]}case"TensorListResize":{const s=DG("tensorListId",e,t,n),r=DG("size",e,t,n),a=n.getTensorList(s.id).resize(r);return n.addTensorList(a),[a.idTensor]}default:throw TypeError(`Node type ${e.op} is not implemented`)}};
|
|
16948
16948
|
/**
|
|
16949
16949
|
* @license
|
|
16950
16950
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16960,7 +16960,7 @@ const $H=async(e,t,n)=>{switch(e.op){case"If":case"StatelessIf":{const s=_G("the
|
|
|
16960
16960
|
* See the License for the specific language governing permissions and
|
|
16961
16961
|
* limitations under the License.
|
|
16962
16962
|
* =============================================================================
|
|
16963
|
-
*/function
|
|
16963
|
+
*/function AH(e,t,n){const[s,r]=DG("fusedOps",e,t,n),a="biasadd"===s,i=!a,o="prelu"===r,u="fusedbatchnorm"===s,l=DG("numArgs",e,t,n);if(a){if(o&&2!==l)throw new Error("FusedConv2d and DepthwiseConv2d with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!o&&a&&1!==l)throw new Error("FusedConv2d and DepthwiseConv2d with BiasAdd must have one extra argument: bias.")}if(u)throw new Error("FusedConv2d and DepthwiseConv2d with FusedBatchNorm is not supported");const c=DG("strides",e,t,n),h=BG(e,t,n),d=DG("dataFormat",e,t,n).toUpperCase(),p=DG("dilations",e,t,n);let[f,m]=DG("args",e,t,n);i&&(m=f,f=void 0);return{stride:c,pad:h,dataFormat:d,dilations:p,biasArg:f,preluArg:m,activationFunc:r,leakyreluAlpha:DG("leakyreluAlpha",e,t,n)}}
|
|
16964
16964
|
/**
|
|
16965
16965
|
* @license
|
|
16966
16966
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16977,7 +16977,7 @@ const $H=async(e,t,n)=>{switch(e.op){case"If":case"StatelessIf":{const s=_G("the
|
|
|
16977
16977
|
* limitations under the License.
|
|
16978
16978
|
* =============================================================================
|
|
16979
16979
|
*/
|
|
16980
|
-
function
|
|
16980
|
+
function _H(e,t,n){return{boxes:DG("boxes",e,t,n),scores:DG("scores",e,t,n),maxOutputSize:DG("maxOutputSize",e,t,n),iouThreshold:DG("iouThreshold",e,t,n),scoreThreshold:DG("scoreThreshold",e,t,n),softNmsSigma:DG("softNmsSigma",e,t,n)}}
|
|
16981
16981
|
/**
|
|
16982
16982
|
* @license
|
|
16983
16983
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -16994,7 +16994,7 @@ function EH(e,t,n){return{boxes:_G("boxes",e,t,n),scores:_G("scores",e,t,n),maxO
|
|
|
16994
16994
|
* limitations under the License.
|
|
16995
16995
|
* =============================================================================
|
|
16996
16996
|
*/
|
|
16997
|
-
class
|
|
16997
|
+
class FH{get id(){return this.handle.id}constructor(e,t){this.keyDType=e,this.valueDType=t,this.handle=pl(0),this.tensorMap=new Map,wi(this.handle)}clearAndClose(){this.tensorMap.forEach((e=>e.dispose())),this.tensorMap.clear(),this.handle.dispose()}size(){return this.tensorMap.size}tensorSize(){return pl(this.size(),"int32")}async import(e,t){this.checkKeyAndValueTensor(e,t);const n=await e.data();return this.tensorMap.forEach((e=>e.dispose())),this.tensorMap.clear(),bi((()=>{const e=Kh(t),s=n.length,r=e.length;me(s===r,(()=>`The number of elements doesn't match, keys has ${s} elements, the values has ${r} elements.`));for(let t=0;t<s;t++){const s=n[t],r=e[t];wi(r),this.tensorMap.set(s,r)}return this.handle}))}async find(e,t){this.checkKeyAndValueTensor(e,t);const n=await e.data();return bi((()=>{const e=[];for(let s=0;s<n.length;s++){const r=n[s],a=this.findWithDefault(r,t);e.push(a)}return Dh(e)}))}findWithDefault(e,t){const n=this.tensorMap.get(e);return null!=n?n:t}checkKeyAndValueTensor(e,t){if(e.dtype!==this.keyDType)throw new Error(`Expect key dtype ${this.keyDType}, but got ${e.dtype}`);if(t.dtype!==this.valueDType)throw new Error(`Expect value dtype ${this.valueDType}, but got ${t.dtype}`)}}
|
|
16998
16998
|
/**
|
|
16999
16999
|
* @license
|
|
17000
17000
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17027,7 +17027,7 @@ class AH{get id(){return this.handle.id}constructor(e,t){this.keyDType=e,this.va
|
|
|
17027
17027
|
* limitations under the License.
|
|
17028
17028
|
* =============================================================================
|
|
17029
17029
|
*/
|
|
17030
|
-
function _H(e,t,n,s,r=bi){const a=((e,t,n)=>{switch(e.category){case"arithmetic":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"BiasAdd":case"AddV2":case"Add":return[s.add(_G("a",e,t,n),_G("b",e,t,n))];case"AddN":return[s.addN(_G("tensors",e,t,n))];case"FloorMod":case"Mod":return[s.mod(_G("a",e,t,n),_G("b",e,t,n))];case"Mul":return[s.mul(_G("a",e,t,n),_G("b",e,t,n))];case"RealDiv":case"Div":return[s.div(_G("a",e,t,n),_G("b",e,t,n))];case"DivNoNan":return[s.divNoNan(_G("a",e,t,n),_G("b",e,t,n))];case"FloorDiv":return[s.floorDiv(_G("a",e,t,n),_G("b",e,t,n))];case"Sub":return[s.sub(_G("a",e,t,n),_G("b",e,t,n))];case"Minimum":return[s.minimum(_G("a",e,t,n),_G("b",e,t,n))];case"Maximum":return[s.maximum(_G("a",e,t,n),_G("b",e,t,n))];case"Pow":return[s.pow(_G("a",e,t,n),_G("b",e,t,n))];case"SquaredDifference":return[s.squaredDifference(_G("a",e,t,n),_G("b",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"basic_math":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"Abs":case"ComplexAbs":return[s.abs(_G("x",e,t,n))];case"Acos":return[s.acos(_G("x",e,t,n))];case"Acosh":return[s.acosh(_G("x",e,t,n))];case"Asin":return[s.asin(_G("x",e,t,n))];case"Asinh":return[s.asinh(_G("x",e,t,n))];case"Atan":return[s.atan(_G("x",e,t,n))];case"Atan2":return[s.atan2(_G("x",e,t,n),_G("y",e,t,n))];case"Atanh":return[s.atanh(_G("x",e,t,n))];case"Ceil":return[s.ceil(_G("x",e,t,n))];case"Complex":return[s.complex(_G("real",e,t,n),_G("imag",e,t,n))];case"Cos":return[s.cos(_G("x",e,t,n))];case"Cosh":return[s.cosh(_G("x",e,t,n))];case"Elu":return[s.elu(_G("x",e,t,n))];case"Erf":return[s.erf(_G("x",e,t,n))];case"Exp":return[s.exp(_G("x",e,t,n))];case"Expm1":return[s.expm1(_G("x",e,t,n))];case"Floor":return[s.floor(_G("x",e,t,n))];case"Log":return[s.log(_G("x",e,t,n))];case"Log1p":return[s.log1p(_G("x",e,t,n))];case"Imag":return[s.imag(_G("x",e,t,n))];case"Neg":return[s.neg(_G("x",e,t,n))];case"Reciprocal":return[s.reciprocal(_G("x",e,t,n))];case"Real":return[s.real(_G("x",e,t,n))];case"Relu":return[s.relu(_G("x",e,t,n))];case"Round":return[s.round(_G("x",e,t,n))];case"Selu":return[s.selu(_G("x",e,t,n))];case"Sigmoid":return[s.sigmoid(_G("x",e,t,n))];case"Sin":return[s.sin(_G("x",e,t,n))];case"Sign":return[s.sign(_G("x",e,t,n))];case"Sinh":return[s.sinh(_G("x",e,t,n))];case"Softplus":return[s.softplus(_G("x",e,t,n))];case"Sqrt":return[s.sqrt(_G("x",e,t,n))];case"Square":return[s.square(_G("x",e,t,n))];case"Tanh":return[s.tanh(_G("x",e,t,n))];case"Tan":return[s.tan(_G("x",e,t,n))];case"ClipByValue":return[s.clipByValue(_G("x",e,t,n),_G("clipValueMin",e,t,n),_G("clipValueMax",e,t,n))];case"Relu6":return[s.relu6(_G("x",e,t,n))];case"Rsqrt":return[s.rsqrt(FG(e.inputNames[0],t,n))];case"LeakyRelu":return[s.leakyRelu(_G("x",e,t,n),_G("alpha",e,t,n))];case"Prelu":return[s.prelu(_G("x",e,t,n),_G("alpha",e,t,n))];case"IsNan":return[s.isNaN(FG(e.inputNames[0],t,n))];case"IsInf":return[s.isInf(FG(e.inputNames[0],t,n))];case"IsFinite":return[s.isFinite(FG(e.inputNames[0],t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"control":return $H(e,t,n);case"convolution":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"Conv1D":{const r=_G("stride",e,t,n),a=_G("pad",e,t,n),i=_G("dataFormat",e,t,n).toUpperCase(),o=_G("dilation",e,t,n);return[s.conv1d(_G("x",e,t,n),_G("filter",e,t,n),r,a,i,o)]}case"Conv2D":{const r=_G("strides",e,t,n),a=PG(e,t,n),i=_G("dataFormat",e,t,n).toUpperCase(),o=_G("dilations",e,t,n);return[s.conv2d(_G("x",e,t,n),_G("filter",e,t,n),[r[1],r[2]],a,i,[o[1],o[2]])]}case"_FusedConv2D":{const{stride:r,pad:a,dataFormat:i,dilations:o,biasArg:u,preluArg:l,activationFunc:c,leakyreluAlpha:h}=RH(e,t,n);return[s.fused.conv2d({x:_G("x",e,t,n),filter:_G("filter",e,t,n),strides:[r[1],r[2]],pad:a,dataFormat:i,dilations:[o[1],o[2]],bias:u,activation:c,preluActivationWeights:l,leakyreluAlpha:h})]}case"FusedDepthwiseConv2dNative":{const{stride:r,pad:a,dataFormat:i,dilations:o,biasArg:u,preluArg:l,activationFunc:c,leakyreluAlpha:h}=RH(e,t,n);return[s.fused.depthwiseConv2d({x:_G("x",e,t,n),filter:_G("filter",e,t,n),strides:[r[1],r[2]],pad:a,dataFormat:i,dilations:[o[1],o[2]],bias:u,activation:c,preluActivationWeights:l,leakyreluAlpha:h})]}case"Conv2DBackpropInput":case"Conv2dTranspose":{const r=_G("outputShape",e,t,n),a=_G("strides",e,t,n),i=PG(e,t,n);return[s.conv2dTranspose(_G("x",e,t,n),_G("filter",e,t,n),r,[a[1],a[2]],i)]}case"DepthwiseConv2dNative":case"DepthwiseConv2d":{const r=_G("strides",e,t,n),a=PG(e,t,n),i=_G("dilations",e,t,n),o=_G("dataFormat",e,t,n).toUpperCase();return[s.depthwiseConv2d(_G("input",e,t,n),_G("filter",e,t,n),[r[1],r[2]],a,o,[i[1],i[2]])]}case"Conv3D":{const r=_G("strides",e,t,n),a=_G("pad",e,t,n),i=_G("dataFormat",e,t,n).toUpperCase(),o=_G("dilations",e,t,n);return[s.conv3d(_G("x",e,t,n),_G("filter",e,t,n),[r[1],r[2],r[3]],a,i,[o[1],o[2],o[3]])]}case"AvgPool":{const r=_G("strides",e,t,n),a=_G("pad",e,t,n),i=_G("kernelSize",e,t,n);return[s.avgPool(_G("x",e,t,n),[i[1],i[2]],[r[1],r[2]],a)]}case"MaxPool":{const r=_G("strides",e,t,n),a=_G("pad",e,t,n),i=_G("kernelSize",e,t,n);return[s.maxPool(_G("x",e,t,n),[i[1],i[2]],[r[1],r[2]],a)]}case"MaxPoolWithArgmax":{const r=_G("strides",e,t,n),a=_G("pad",e,t,n),i=_G("kernelSize",e,t,n),o=_G("includeBatchInIndex",e,t,n),{result:u,indexes:l}=s.maxPoolWithArgmax(_G("x",e,t,n),[i[1],i[2]],[r[1],r[2]],a,o);return[u,l]}case"AvgPool3D":{const r=_G("strides",e,t,n),a=_G("pad",e,t,n),i=_G("kernelSize",e,t,n);return[s.avgPool3d(_G("x",e,t,n),[i[1],i[2],i[3]],[r[1],r[2],r[3]],a)]}case"MaxPool3D":{const r=_G("strides",e,t,n),a=_G("pad",e,t,n),i=_G("kernelSize",e,t,n);return[s.maxPool3d(_G("x",e,t,n),[i[1],i[2],i[3]],[r[1],r[2],r[3]],a)]}case"Dilation2D":{const r=_G("strides",e,t,n),a=_G("pad",e,t,n),i=_G("dilations",e,t,n),o=r[1],u=r[2],l=i[1],c=i[2];return[s.dilation2d(_G("x",e,t,n),_G("filter",e,t,n),[o,u],a,[l,c],"NHWC")]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"creation":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"Fill":{const r=_G("shape",e,t,n),a=_G("dtype",e,t,n),i=_G("value",e,t,n);return[s.fill(r,i,a)]}case"LinSpace":{const r=_G("start",e,t,n),a=_G("stop",e,t,n),i=_G("num",e,t,n);return[s.linspace(r,a,i)]}case"Multinomial":{const r=_G("logits",e,t,n),a=_G("numSamples",e,t,n),i=_G("seed",e,t,n);return[s.multinomial(r,a,i)]}case"OneHot":{const r=_G("indices",e,t,n),a=_G("depth",e,t,n),i=_G("onValue",e,t,n),o=_G("offValue",e,t,n),u=_G("dtype",e,t,n);return[s.oneHot(r,a,i,o,u)]}case"Ones":return[s.ones(_G("shape",e,t,n),_G("dtype",e,t,n))];case"OnesLike":return[s.onesLike(_G("x",e,t,n))];case"RandomStandardNormal":return[s.randomStandardNormal(_G("shape",e,t,n),_G("dtype",e,t,n),_G("seed",e,t,n))];case"RandomUniform":return[s.randomUniform(_G("shape",e,t,n),_G("minval",e,t,n),_G("maxval",e,t,n),_G("dtype",e,t,n))];case"RandomUniformInt":return[s.randomUniformInt(_G("shape",e,t,n),_G("minval",e,t,n),_G("maxval",e,t,n),_G("seed",e,t,n))];case"Range":{const r=_G("start",e,t,n),a=_G("stop",e,t,n),i=_G("step",e,t,n);return[s.range(r,a,i,_G("dtype",e,t,n))]}case"TruncatedNormal":{const r=_G("shape",e,t,n),a=_G("mean",e,t,n),i=_G("stdDev",e,t,n),o=_G("seed",e,t,n);return[s.truncatedNormal(r,a,i,_G("dtype",e,t,n),o)]}case"Zeros":return[s.zeros(_G("shape",e,t,n),_G("dtype",e,t,n))];case"ZerosLike":return[s.zerosLike(_G("x",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"dynamic":return(async(e,t,n,s,r=kH)=>{switch(e.op){case"NonMaxSuppressionV5":{const{boxes:s,scores:a,maxOutputSize:i,iouThreshold:o,scoreThreshold:u,softNmsSigma:l}=EH(e,t,n),c=await r.image.nonMaxSuppressionWithScoreAsync(s,a,i,o,u,l);return[c.selectedIndices,c.selectedScores]}case"NonMaxSuppressionV4":{const{boxes:s,scores:a,maxOutputSize:i,iouThreshold:o,scoreThreshold:u}=EH(e,t,n),l=_G("padToMaxOutputSize",e,t,n),c=await r.image.nonMaxSuppressionPaddedAsync(s,a,i,o,u,l);return[c.selectedIndices,c.validOutputs]}case"NonMaxSuppressionV3":case"NonMaxSuppressionV2":{const{boxes:s,scores:a,maxOutputSize:i,iouThreshold:o,scoreThreshold:u}=EH(e,t,n);return[await r.image.nonMaxSuppressionAsync(s,a,i,o,u)]}case"Where":{const s=r.cast(_G("condition",e,t,n),"bool"),a=[await r.whereAsync(s)];return s.dispose(),a}case"ListDiff":return r.setdiff1dAsync(_G("x",e,t,n),_G("y",e,t,n));default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n);case"evaluation":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"LowerBound":{const r=_G("sortedSequence",e,t,n),a=_G("values",e,t,n);return[s.lowerBound(r,a)]}case"TopKV2":{const r=_G("x",e,t,n),a=_G("k",e,t,n),i=_G("sorted",e,t,n),o=s.topk(r,a,i);return[o.values,o.indices]}case"UpperBound":{const r=_G("sortedSequence",e,t,n),a=_G("values",e,t,n);return[s.upperBound(r,a)]}case"Unique":{const r=_G("x",e,t,n),a=s.unique(r);return[a.values,a.indices]}case"UniqueV2":{const r=_G("x",e,t,n),a=_G("axis",e,t,n),i=s.unique(r,a);return[i.values,i.indices]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"image":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"ResizeBilinear":{const r=_G("images",e,t,n),a=_G("size",e,t,n),i=_G("alignCorners",e,t,n),o=_G("halfPixelCenters",e,t,n);return[s.image.resizeBilinear(r,[a[0],a[1]],i,o)]}case"ResizeNearestNeighbor":{const r=_G("images",e,t,n),a=_G("size",e,t,n),i=_G("alignCorners",e,t,n),o=_G("halfPixelCenters",e,t,n);return[s.image.resizeNearestNeighbor(r,[a[0],a[1]],i,o)]}case"CropAndResize":{const r=_G("image",e,t,n),a=_G("boxes",e,t,n),i=_G("boxInd",e,t,n),o=_G("cropSize",e,t,n),u=_G("method",e,t,n),l=_G("extrapolationValue",e,t,n);return[s.image.cropAndResize(r,a,i,o,u,l)]}case"ImageProjectiveTransformV3":{const r=_G("images",e,t,n),a=_G("transforms",e,t,n),i=_G("outputShape",e,t,n),o=_G("fillValue",e,t,n),u=_G("interpolation",e,t,n),l=_G("fillMode",e,t,n);return[s.image.transform(r,a,u.toLowerCase(),l.toLowerCase(),o,i)]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"graph":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"Const":return t[e.name];case"PlaceholderWithDefault":const r=_G("default",e,t,n);return[FG(e.name,t,n)||r];case"Placeholder":return[FG(e.name,t,n)];case"Identity":case"StopGradient":case"FakeQuantWithMinMaxVars":case"Snapshot":return[zG(_G("x",e,t,n))];case"IdentityN":return _G("x",e,t,n).map((e=>zG(e)));case"Shape":return[s.tensor1d(_G("x",e,t,n).shape,"int32")];case"ShapeN":return _G("x",e,t,n).map((e=>s.tensor1d(e.shape)));case"Size":return[s.scalar(_G("x",e,t,n).size,"int32")];case"Rank":return[s.scalar(_G("x",e,t,n).rank,"int32")];case"NoOp":return[s.scalar(1)];case"Print":const a=_G("x",e,t,n),i=_G("data",e,t,n),o=_G("message",e,t,n),u=_G("summarize",e,t,n);console.warn("The graph has a tf.print() operation,usually used for debugging, which slows down performance."),console.log(o);for(let e=0;e<i.length;e++)console.log(Array.prototype.slice.call(i[e].dataSync()).slice(0,u));return[a];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"logical":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"Equal":return[s.equal(_G("a",e,t,n),_G("b",e,t,n))];case"NotEqual":return[s.notEqual(_G("a",e,t,n),_G("b",e,t,n))];case"Greater":return[s.greater(_G("a",e,t,n),_G("b",e,t,n))];case"GreaterEqual":return[s.greaterEqual(_G("a",e,t,n),_G("b",e,t,n))];case"Less":return[s.less(_G("a",e,t,n),_G("b",e,t,n))];case"LessEqual":return[s.lessEqual(_G("a",e,t,n),_G("b",e,t,n))];case"LogicalAnd":return[s.logicalAnd(_G("a",e,t,n),_G("b",e,t,n))];case"LogicalNot":return[s.logicalNot(_G("a",e,t,n))];case"LogicalOr":return[s.logicalOr(_G("a",e,t,n),_G("b",e,t,n))];case"Select":case"SelectV2":return[s.where(_G("condition",e,t,n),_G("a",e,t,n),_G("b",e,t,n))];case"BitwiseAnd":return[s.bitwiseAnd(_G("a",e,t,n),_G("b",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"matrices":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"BatchMatMul":case"BatchMatMulV2":case"MatMul":return[s.matMul(_G("a",e,t,n),_G("b",e,t,n),_G("transposeA",e,t,n),_G("transposeB",e,t,n))];case"Einsum":return[s.einsum(_G("equation",e,t,n),..._G("tensors",e,t,n))];case"Transpose":return[s.transpose(_G("x",e,t,n),_G("perm",e,t,n))];case"_FusedMatMul":const[r,a]=_G("fusedOps",e,t,n),i="biasadd"===r,o="prelu"===a,u=_G("numArgs",e,t,n),l=_G("leakyreluAlpha",e,t,n);if(i){if(o&&2!==u)throw new Error("Fused MatMul with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!o&&1!==u)throw new Error("Fused MatMul with BiasAdd must have one extra argument: bias.")}const[c,h]=_G("args",e,t,n);return[s.fused.matMul({a:_G("a",e,t,n),b:_G("b",e,t,n),transposeA:_G("transposeA",e,t,n),transposeB:_G("transposeB",e,t,n),bias:c,activation:a,preluActivationWeights:h,leakyreluAlpha:l})];case"MatrixBandPart":return[s.linalg.bandPart(_G("a",e,t,n),_G("numLower",e,t,n),_G("numUpper",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"normalization":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"EuclideanNorm":return[s.euclideanNorm(_G("x",e,t,n),_G("axis",e,t,n),_G("keepDims",e,t,n))];case"FusedBatchNorm":case"FusedBatchNormV2":case"FusedBatchNormV3":return[s.batchNorm(_G("x",e,t,n),_G("mean",e,t,n),_G("variance",e,t,n),_G("offset",e,t,n),_G("scale",e,t,n),_G("epsilon",e,t,n))];case"LRN":return[s.localResponseNormalization(_G("x",e,t,n),_G("radius",e,t,n),_G("bias",e,t,n),_G("alpha",e,t,n),_G("beta",e,t,n))];case"Softmax":return[s.softmax(_G("x",e,t,n))];case"LogSoftmax":return[s.logSoftmax(_G("x",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"ragged":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"RaggedGather":{const{outputNestedSplits:r,outputDenseValues:a}=s.raggedGather(_G("paramsNestedSplits",e,t,n),_G("paramsDenseValues",e,t,n),_G("indices",e,t,n),_G("outputRaggedRank",e,t,n));return r.concat(a)}case"RaggedRange":{const{rtNestedSplits:r,rtDenseValues:a}=s.raggedRange(_G("starts",e,t,n),_G("limits",e,t,n),_G("splits",e,t,n));return[r,a]}case"RaggedTensorToTensor":return[s.raggedTensorToTensor(_G("shape",e,t,n),_G("values",e,t,n),_G("defaultValue",e,t,n),_G("rowPartitionTensors",e,t,n),_G("rowPartitionTypes",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"reduction":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"Max":{const r=_G("axis",e,t,n),a=_G("keepDims",e,t,n);return[s.max(_G("x",e,t,n),r,a)]}case"Mean":{const r=_G("axis",e,t,n),a=_G("keepDims",e,t,n);return[s.mean(_G("x",e,t,n),r,a)]}case"Min":{const r=_G("axis",e,t,n),a=_G("keepDims",e,t,n);return[s.min(_G("x",e,t,n),r,a)]}case"Sum":{const r=_G("axis",e,t,n),a=_G("keepDims",e,t,n);return[s.sum(_G("x",e,t,n),r,a)]}case"All":{const r=_G("axis",e,t,n),a=_G("keepDims",e,t,n);return[s.all(_G("x",e,t,n),r,a)]}case"Any":{const r=_G("axis",e,t,n),a=_G("keepDims",e,t,n);return[s.any(_G("x",e,t,n),r,a)]}case"ArgMax":{const r=_G("axis",e,t,n);return[s.argMax(_G("x",e,t,n),r)]}case"ArgMin":{const r=_G("axis",e,t,n);return[s.argMin(_G("x",e,t,n),r)]}case"Prod":{const r=_G("axis",e,t,n),a=_G("keepDims",e,t,n);return[s.prod(_G("x",e,t,n),r,a)]}case"Cumprod":{const r=_G("axis",e,t,n),a=_G("exclusive",e,t,n),i=_G("reverse",e,t,n);return[s.cumprod(_G("x",e,t,n),r,a,i)]}case"Cumsum":{const r=_G("axis",e,t,n),a=_G("exclusive",e,t,n),i=_G("reverse",e,t,n);return[s.cumsum(_G("x",e,t,n),r,a,i)]}case"Bincount":const r=_G("x",e,t,n),a=_G("weights",e,t,n),i=_G("size",e,t,n);return[s.bincount(r,a,i)];case"DenseBincount":{const r=_G("x",e,t,n),a=_G("weights",e,t,n),i=_G("size",e,t,n),o=_G("binaryOutput",e,t,n);return[s.denseBincount(r,a,i,o)]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"slice_join":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"ConcatV2":case"Concat":{const r=_G("n",e,t,n),a=_G("axis",e,t,n);let i=_G("tensors",e,t,n);return i=i.slice(0,r),[s.concat(i,a)]}case"Gather":{const r=_G("x",e,t,n),a=_G("indices",e,t,n);return[s.gather(r,s.cast(a,"int32"),0)]}case"GatherV2":{const r=_G("axis",e,t,n),a=_G("batchDims",e,t,n),i=_G("x",e,t,n),o=_G("indices",e,t,n);return[s.gather(i,s.cast(o,"int32"),r,a)]}case"Reverse":{const r=_G("dims",e,t,n),a=[];for(let e=0;e<r.length;e++)r[e]&&a.push(e);const i=_G("x",e,t,n);return[s.reverse(i,a)]}case"ReverseV2":{const r=_G("axis",e,t,n),a=_G("x",e,t,n);return[s.reverse(a,r)]}case"Slice":{const r=_G("begin",e,t,n),a=_G("size",e,t,n);return[s.slice(_G("x",e,t,n),r,a)]}case"StridedSlice":{const r=_G("begin",e,t,n),a=_G("end",e,t,n),i=_G("strides",e,t,n),o=_G("beginMask",e,t,n),u=_G("endMask",e,t,n),l=_G("ellipsisMask",e,t,n),c=_G("newAxisMask",e,t,n),h=_G("shrinkAxisMask",e,t,n),d=_G("x",e,t,n);return[s.stridedSlice(d,r,a,i,o,u,l,c,h)]}case"Pack":return bi((()=>{const r=_G("axis",e,t,n),a=_G("tensors",e,t,n),i=a[0].shape,o=s.squeeze(a[0]).shape,u=a.map((e=>{const t=we(e.shape,i);if(!t&&!we(s.squeeze(e).shape,o))throw new Error("the input tensors shape does not match");return t?e:s.reshape(e,i)}));return[s.stack(u,r)]}));case"Unpack":{const r=_G("axis",e,t,n),a=_G("tensor",e,t,n);return s.unstack(a,r)}case"Tile":{const r=_G("reps",e,t,n);return[s.tile(_G("x",e,t,n),r)]}case"Split":case"SplitV":{const r=_G("axis",e,t,n),a=_G("numOrSizeSplits",e,t,n),i=_G("x",e,t,n);return s.split(i,a,r)}case"ScatterNd":{const r=_G("indices",e,t,n),a=_G("values",e,t,n),i=_G("shape",e,t,n);return[s.scatterND(r,a,i)]}case"GatherNd":{const r=_G("x",e,t,n),a=_G("indices",e,t,n);return[s.gatherND(r,a)]}case"SparseToDense":{const r=_G("sparseIndices",e,t,n),a=_G("outputShape",e,t,n),i=_G("sparseValues",e,t,n),o=_G("defaultValue",e,t,n);return[s.sparseToDense(r,i,a,i.dtype===o.dtype?o:s.cast(o,i.dtype))]}case"TensorScatterUpdate":{const r=_G("indices",e,t,n),a=_G("values",e,t,n),i=_G("tensor",e,t,n);return[s.tensorScatterUpdate(i,r,a)]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"sparse":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"SparseFillEmptyRows":{const{outputIndices:r,outputValues:a,emptyRowIndicator:i,reverseIndexMap:o}=s.sparse.sparseFillEmptyRows(_G("indices",e,t,n),_G("values",e,t,n),_G("denseShape",e,t,n),_G("defaultValue",e,t,n));return[r,a,i,o]}case"SparseReshape":{const{outputIndices:r,outputShape:a}=s.sparse.sparseReshape(_G("inputIndices",e,t,n),_G("inputShape",e,t,n),_G("newShape",e,t,n));return[r,a]}case"SparseSegmentMean":return[s.sparse.sparseSegmentMean(_G("data",e,t,n),_G("indices",e,t,n),_G("segmentIds",e,t,n))];case"SparseSegmentSum":return[s.sparse.sparseSegmentSum(_G("data",e,t,n),_G("indices",e,t,n),_G("segmentIds",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"spectral":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"FFT":return[s.fft(_G("x",e,t,n))];case"IFFT":return[s.ifft(_G("x",e,t,n))];case"RFFT":return[s.rfft(_G("x",e,t,n))];case"IRFFT":return[s.irfft(_G("x",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"string":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"StaticRegexReplace":return[s.string.staticRegexReplace(_G("input",e,t,n),_G("pattern",e,t,n),_G("rewrite",e,t,n),_G("replaceGlobal",e,t,n))];case"StringNGrams":{const{nGrams:r,nGramsSplits:a}=s.string.stringNGrams(_G("data",e,t,n),_G("dataSplits",e,t,n),_G("separator",e,t,n),_G("nGramWidths",e,t,n),_G("leftPad",e,t,n),_G("rightPad",e,t,n),_G("padWidth",e,t,n),_G("preserveShortSequences",e,t,n));return[r,a]}case"StringSplit":{const{indices:r,values:a,shape:i}=s.string.stringSplit(_G("input",e,t,n),_G("delimiter",e,t,n),_G("skipEmpty",e,t,n));return[r,a,i]}case"StringToHashBucketFast":return[s.string.stringToHashBucketFast(_G("input",e,t,n),_G("numBuckets",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"transformation":return r((()=>((e,t,n,s=kH)=>{switch(e.op){case"Cast":return[s.cast(_G("x",e,t,n),_G("dtype",e,t,n))];case"ExpandDims":{const r=_G("axis",e,t,n);return[s.expandDims(_G("x",e,t,n),r)]}case"Squeeze":{const r=_G("axis",e,t,n);return[s.squeeze(_G("x",e,t,n),r)]}case"Reshape":return[s.reshape(_G("x",e,t,n),_G("shape",e,t,n))];case"EnsureShape":return[s.ensureShape(_G("x",e,t,n),_G("shape",e,t,n))];case"MirrorPad":return[s.mirrorPad(_G("x",e,t,n),_G("padding",e,t,n),_G("mode",e,t,n))];case"PadV2":case"Pad":return[s.pad(_G("x",e,t,n),_G("padding",e,t,n),_G("constantValue",e,t,n))];case"SpaceToBatchND":{const r=_G("blockShape",e,t,n),a=_G("paddings",e,t,n);return[s.spaceToBatchND(_G("x",e,t,n),r,a)]}case"BatchToSpaceND":{const r=_G("blockShape",e,t,n),a=_G("crops",e,t,n);return[s.batchToSpaceND(_G("x",e,t,n),r,a)]}case"DepthToSpace":{const r=_G("blockSize",e,t,n),a=_G("dataFormat",e,t,n).toUpperCase();return[s.depthToSpace(_G("x",e,t,n),r,a)]}case"BroadcastTo":return[s.broadcastTo(_G("x",e,t,n),_G("shape",e,t,n))];case"BroadcastArgs":return[s.broadcastArgs(_G("s0",e,t,n),_G("s1",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"hash_table":return(async(e,t,n,s)=>{switch(e.op){case"HashTable":case"HashTableV2":{const r=s.getHashTableHandleByName(e.name);if(null!=r)return[r];{const r=_G("keyDType",e,t,n),a=_G("valueDType",e,t,n),i=new AH(r,a);return s.addHashTable(e.name,i),[i.handle]}}case"InitializeTable":case"InitializeTableV2":case"LookupTableImport":case"LookupTableImportV2":{const r=_G("tableHandle",e,t,n,s),a=_G("keys",e,t,n),i=_G("values",e,t,n),o=s.getHashTableById(r.id);return[await o.import(a,i)]}case"LookupTableFind":case"LookupTableFindV2":{const r=_G("tableHandle",e,t,n,s),a=_G("keys",e,t,n),i=_G("defaultValue",e,t,n),o=s.getHashTableById(r.id);return[await o.find(a,i)]}case"LookupTableSize":case"LookupTableSizeV2":{const r=_G("tableHandle",e,t,n,s);return[s.getHashTableById(r.id).tensorSize()]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n,s);case"custom":const a=AG(e.op);if(a&&a.customExecutor)return a.customExecutor(new wH(e,t,n));throw TypeError(`Custom op ${e.op} is not registered.`);default:throw TypeError(`Unknown op '${e.op}'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()`)}})(e,t,n);return je(a)?a.then((e=>[].concat(e))):[].concat(a)}class FH{constructor(e={},t={},n={},s={},r){this.weightMap=e,this.tensorArrayMap=t,this.tensorListMap=n,this.functionMap=s,this.parseNodeNameCache=r,this.rootContext={id:0,frameName:"",iterationId:0},this.contexts=[this.rootContext],this.lastId=0,this.generateCurrentContextIds()}newFrame(e,t){return{id:e,frameName:t,iterationId:0}}set currentContext(e){this.contexts!==e&&(this.contexts=e,this.generateCurrentContextIds())}get currentContext(){return this.contexts}get currentContextId(){return this._currentContextIds[0]}get currentContextIds(){return this._currentContextIds}generateCurrentContextIds(){const e=[];for(let t=0;t<this.contexts.length-1;t++){const n=this.contexts.slice(0,this.contexts.length-t);e.push(this.contextIdforContexts(n))}e.push(""),this._currentContextIds=e}contextIdforContexts(e){return e?e.map((e=>0===e.id&&0===e.iterationId?"":`${e.frameName}-${e.iterationId}`)).join("/"):""}enterFrame(e){this.contexts&&(this.lastId++,this.contexts=this.contexts.slice(),this.contexts.push(this.newFrame(this.lastId,e)),this._currentContextIds.unshift(this.contextIdforContexts(this.contexts)))}exitFrame(){if(!(this.contexts&&this.contexts.length>1))throw new Error("Cannot exit frame, the context is empty");this.contexts=this.contexts.slice(),this.contexts.splice(-1),this.currentContextIds.shift()}nextIteration(){if(!(this.contexts&&this.contexts.length>0))throw new Error("Cannot increase frame iteration, the context is empty");{this.contexts=this.contexts.slice(),this.lastId++;const e=Object.assign({},this.contexts[this.contexts.length-1]);e.iterationId+=1,e.id=this.lastId,this.contexts.splice(-1,1,e),this._currentContextIds.splice(0,1,this.contextIdforContexts(this.contexts))}}getWeight(e){return this.weightMap[e]}addTensorArray(e){this.tensorArrayMap[e.id]=e}getTensorArray(e){return this.tensorArrayMap[e]}addTensorList(e){this.tensorListMap[e.id]=e}getTensorList(e){return this.tensorListMap[e]}dispose(e){for(const t in this.tensorArrayMap)this.tensorArrayMap[t].clearAndClose(e);for(const t in this.tensorListMap)this.tensorListMap[t].clearAndClose(e)}}
|
|
17030
|
+
function DH(e,t,n,s,r=bi){const a=((e,t,n)=>{switch(e.category){case"arithmetic":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"BiasAdd":case"AddV2":case"Add":return[s.add(DG("a",e,t,n),DG("b",e,t,n))];case"AddN":return[s.addN(DG("tensors",e,t,n))];case"FloorMod":case"Mod":return[s.mod(DG("a",e,t,n),DG("b",e,t,n))];case"Mul":return[s.mul(DG("a",e,t,n),DG("b",e,t,n))];case"RealDiv":case"Div":return[s.div(DG("a",e,t,n),DG("b",e,t,n))];case"DivNoNan":return[s.divNoNan(DG("a",e,t,n),DG("b",e,t,n))];case"FloorDiv":return[s.floorDiv(DG("a",e,t,n),DG("b",e,t,n))];case"Sub":return[s.sub(DG("a",e,t,n),DG("b",e,t,n))];case"Minimum":return[s.minimum(DG("a",e,t,n),DG("b",e,t,n))];case"Maximum":return[s.maximum(DG("a",e,t,n),DG("b",e,t,n))];case"Pow":return[s.pow(DG("a",e,t,n),DG("b",e,t,n))];case"SquaredDifference":return[s.squaredDifference(DG("a",e,t,n),DG("b",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"basic_math":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"Abs":case"ComplexAbs":return[s.abs(DG("x",e,t,n))];case"Acos":return[s.acos(DG("x",e,t,n))];case"Acosh":return[s.acosh(DG("x",e,t,n))];case"Asin":return[s.asin(DG("x",e,t,n))];case"Asinh":return[s.asinh(DG("x",e,t,n))];case"Atan":return[s.atan(DG("x",e,t,n))];case"Atan2":return[s.atan2(DG("x",e,t,n),DG("y",e,t,n))];case"Atanh":return[s.atanh(DG("x",e,t,n))];case"Ceil":return[s.ceil(DG("x",e,t,n))];case"Complex":return[s.complex(DG("real",e,t,n),DG("imag",e,t,n))];case"Cos":return[s.cos(DG("x",e,t,n))];case"Cosh":return[s.cosh(DG("x",e,t,n))];case"Elu":return[s.elu(DG("x",e,t,n))];case"Erf":return[s.erf(DG("x",e,t,n))];case"Exp":return[s.exp(DG("x",e,t,n))];case"Expm1":return[s.expm1(DG("x",e,t,n))];case"Floor":return[s.floor(DG("x",e,t,n))];case"Log":return[s.log(DG("x",e,t,n))];case"Log1p":return[s.log1p(DG("x",e,t,n))];case"Imag":return[s.imag(DG("x",e,t,n))];case"Neg":return[s.neg(DG("x",e,t,n))];case"Reciprocal":return[s.reciprocal(DG("x",e,t,n))];case"Real":return[s.real(DG("x",e,t,n))];case"Relu":return[s.relu(DG("x",e,t,n))];case"Round":return[s.round(DG("x",e,t,n))];case"Selu":return[s.selu(DG("x",e,t,n))];case"Sigmoid":return[s.sigmoid(DG("x",e,t,n))];case"Sin":return[s.sin(DG("x",e,t,n))];case"Sign":return[s.sign(DG("x",e,t,n))];case"Sinh":return[s.sinh(DG("x",e,t,n))];case"Softplus":return[s.softplus(DG("x",e,t,n))];case"Sqrt":return[s.sqrt(DG("x",e,t,n))];case"Square":return[s.square(DG("x",e,t,n))];case"Tanh":return[s.tanh(DG("x",e,t,n))];case"Tan":return[s.tan(DG("x",e,t,n))];case"ClipByValue":return[s.clipByValue(DG("x",e,t,n),DG("clipValueMin",e,t,n),DG("clipValueMax",e,t,n))];case"Relu6":return[s.relu6(DG("x",e,t,n))];case"Rsqrt":return[s.rsqrt(MG(e.inputNames[0],t,n))];case"LeakyRelu":return[s.leakyRelu(DG("x",e,t,n),DG("alpha",e,t,n))];case"Prelu":return[s.prelu(DG("x",e,t,n),DG("alpha",e,t,n))];case"IsNan":return[s.isNaN(MG(e.inputNames[0],t,n))];case"IsInf":return[s.isInf(MG(e.inputNames[0],t,n))];case"IsFinite":return[s.isFinite(MG(e.inputNames[0],t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"control":return EH(e,t,n);case"convolution":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"Conv1D":{const r=DG("stride",e,t,n),a=DG("pad",e,t,n),i=DG("dataFormat",e,t,n).toUpperCase(),o=DG("dilation",e,t,n);return[s.conv1d(DG("x",e,t,n),DG("filter",e,t,n),r,a,i,o)]}case"Conv2D":{const r=DG("strides",e,t,n),a=BG(e,t,n),i=DG("dataFormat",e,t,n).toUpperCase(),o=DG("dilations",e,t,n);return[s.conv2d(DG("x",e,t,n),DG("filter",e,t,n),[r[1],r[2]],a,i,[o[1],o[2]])]}case"_FusedConv2D":{const{stride:r,pad:a,dataFormat:i,dilations:o,biasArg:u,preluArg:l,activationFunc:c,leakyreluAlpha:h}=AH(e,t,n);return[s.fused.conv2d({x:DG("x",e,t,n),filter:DG("filter",e,t,n),strides:[r[1],r[2]],pad:a,dataFormat:i,dilations:[o[1],o[2]],bias:u,activation:c,preluActivationWeights:l,leakyreluAlpha:h})]}case"FusedDepthwiseConv2dNative":{const{stride:r,pad:a,dataFormat:i,dilations:o,biasArg:u,preluArg:l,activationFunc:c,leakyreluAlpha:h}=AH(e,t,n);return[s.fused.depthwiseConv2d({x:DG("x",e,t,n),filter:DG("filter",e,t,n),strides:[r[1],r[2]],pad:a,dataFormat:i,dilations:[o[1],o[2]],bias:u,activation:c,preluActivationWeights:l,leakyreluAlpha:h})]}case"Conv2DBackpropInput":case"Conv2dTranspose":{const r=DG("outputShape",e,t,n),a=DG("strides",e,t,n),i=BG(e,t,n);return[s.conv2dTranspose(DG("x",e,t,n),DG("filter",e,t,n),r,[a[1],a[2]],i)]}case"DepthwiseConv2dNative":case"DepthwiseConv2d":{const r=DG("strides",e,t,n),a=BG(e,t,n),i=DG("dilations",e,t,n),o=DG("dataFormat",e,t,n).toUpperCase();return[s.depthwiseConv2d(DG("input",e,t,n),DG("filter",e,t,n),[r[1],r[2]],a,o,[i[1],i[2]])]}case"Conv3D":{const r=DG("strides",e,t,n),a=DG("pad",e,t,n),i=DG("dataFormat",e,t,n).toUpperCase(),o=DG("dilations",e,t,n);return[s.conv3d(DG("x",e,t,n),DG("filter",e,t,n),[r[1],r[2],r[3]],a,i,[o[1],o[2],o[3]])]}case"AvgPool":{const r=DG("strides",e,t,n),a=DG("pad",e,t,n),i=DG("kernelSize",e,t,n);return[s.avgPool(DG("x",e,t,n),[i[1],i[2]],[r[1],r[2]],a)]}case"MaxPool":{const r=DG("strides",e,t,n),a=DG("pad",e,t,n),i=DG("kernelSize",e,t,n);return[s.maxPool(DG("x",e,t,n),[i[1],i[2]],[r[1],r[2]],a)]}case"MaxPoolWithArgmax":{const r=DG("strides",e,t,n),a=DG("pad",e,t,n),i=DG("kernelSize",e,t,n),o=DG("includeBatchInIndex",e,t,n),{result:u,indexes:l}=s.maxPoolWithArgmax(DG("x",e,t,n),[i[1],i[2]],[r[1],r[2]],a,o);return[u,l]}case"AvgPool3D":{const r=DG("strides",e,t,n),a=DG("pad",e,t,n),i=DG("kernelSize",e,t,n);return[s.avgPool3d(DG("x",e,t,n),[i[1],i[2],i[3]],[r[1],r[2],r[3]],a)]}case"MaxPool3D":{const r=DG("strides",e,t,n),a=DG("pad",e,t,n),i=DG("kernelSize",e,t,n);return[s.maxPool3d(DG("x",e,t,n),[i[1],i[2],i[3]],[r[1],r[2],r[3]],a)]}case"Dilation2D":{const r=DG("strides",e,t,n),a=DG("pad",e,t,n),i=DG("dilations",e,t,n),o=r[1],u=r[2],l=i[1],c=i[2];return[s.dilation2d(DG("x",e,t,n),DG("filter",e,t,n),[o,u],a,[l,c],"NHWC")]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"creation":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"Fill":{const r=DG("shape",e,t,n),a=DG("dtype",e,t,n),i=DG("value",e,t,n);return[s.fill(r,i,a)]}case"LinSpace":{const r=DG("start",e,t,n),a=DG("stop",e,t,n),i=DG("num",e,t,n);return[s.linspace(r,a,i)]}case"Multinomial":{const r=DG("logits",e,t,n),a=DG("numSamples",e,t,n),i=DG("seed",e,t,n);return[s.multinomial(r,a,i)]}case"OneHot":{const r=DG("indices",e,t,n),a=DG("depth",e,t,n),i=DG("onValue",e,t,n),o=DG("offValue",e,t,n),u=DG("dtype",e,t,n);return[s.oneHot(r,a,i,o,u)]}case"Ones":return[s.ones(DG("shape",e,t,n),DG("dtype",e,t,n))];case"OnesLike":return[s.onesLike(DG("x",e,t,n))];case"RandomStandardNormal":return[s.randomStandardNormal(DG("shape",e,t,n),DG("dtype",e,t,n),DG("seed",e,t,n))];case"RandomUniform":return[s.randomUniform(DG("shape",e,t,n),DG("minval",e,t,n),DG("maxval",e,t,n),DG("dtype",e,t,n))];case"RandomUniformInt":return[s.randomUniformInt(DG("shape",e,t,n),DG("minval",e,t,n),DG("maxval",e,t,n),DG("seed",e,t,n))];case"Range":{const r=DG("start",e,t,n),a=DG("stop",e,t,n),i=DG("step",e,t,n);return[s.range(r,a,i,DG("dtype",e,t,n))]}case"TruncatedNormal":{const r=DG("shape",e,t,n),a=DG("mean",e,t,n),i=DG("stdDev",e,t,n),o=DG("seed",e,t,n);return[s.truncatedNormal(r,a,i,DG("dtype",e,t,n),o)]}case"Zeros":return[s.zeros(DG("shape",e,t,n),DG("dtype",e,t,n))];case"ZerosLike":return[s.zerosLike(DG("x",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"dynamic":return(async(e,t,n,s,r=IH)=>{switch(e.op){case"NonMaxSuppressionV5":{const{boxes:s,scores:a,maxOutputSize:i,iouThreshold:o,scoreThreshold:u,softNmsSigma:l}=_H(e,t,n),c=await r.image.nonMaxSuppressionWithScoreAsync(s,a,i,o,u,l);return[c.selectedIndices,c.selectedScores]}case"NonMaxSuppressionV4":{const{boxes:s,scores:a,maxOutputSize:i,iouThreshold:o,scoreThreshold:u}=_H(e,t,n),l=DG("padToMaxOutputSize",e,t,n),c=await r.image.nonMaxSuppressionPaddedAsync(s,a,i,o,u,l);return[c.selectedIndices,c.validOutputs]}case"NonMaxSuppressionV3":case"NonMaxSuppressionV2":{const{boxes:s,scores:a,maxOutputSize:i,iouThreshold:o,scoreThreshold:u}=_H(e,t,n);return[await r.image.nonMaxSuppressionAsync(s,a,i,o,u)]}case"Where":{const s=r.cast(DG("condition",e,t,n),"bool"),a=[await r.whereAsync(s)];return s.dispose(),a}case"ListDiff":return r.setdiff1dAsync(DG("x",e,t,n),DG("y",e,t,n));default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n);case"evaluation":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"LowerBound":{const r=DG("sortedSequence",e,t,n),a=DG("values",e,t,n);return[s.lowerBound(r,a)]}case"TopKV2":{const r=DG("x",e,t,n),a=DG("k",e,t,n),i=DG("sorted",e,t,n),o=s.topk(r,a,i);return[o.values,o.indices]}case"UpperBound":{const r=DG("sortedSequence",e,t,n),a=DG("values",e,t,n);return[s.upperBound(r,a)]}case"Unique":{const r=DG("x",e,t,n),a=s.unique(r);return[a.values,a.indices]}case"UniqueV2":{const r=DG("x",e,t,n),a=DG("axis",e,t,n),i=s.unique(r,a);return[i.values,i.indices]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"image":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"ResizeBilinear":{const r=DG("images",e,t,n),a=DG("size",e,t,n),i=DG("alignCorners",e,t,n),o=DG("halfPixelCenters",e,t,n);return[s.image.resizeBilinear(r,[a[0],a[1]],i,o)]}case"ResizeNearestNeighbor":{const r=DG("images",e,t,n),a=DG("size",e,t,n),i=DG("alignCorners",e,t,n),o=DG("halfPixelCenters",e,t,n);return[s.image.resizeNearestNeighbor(r,[a[0],a[1]],i,o)]}case"CropAndResize":{const r=DG("image",e,t,n),a=DG("boxes",e,t,n),i=DG("boxInd",e,t,n),o=DG("cropSize",e,t,n),u=DG("method",e,t,n),l=DG("extrapolationValue",e,t,n);return[s.image.cropAndResize(r,a,i,o,u,l)]}case"ImageProjectiveTransformV3":{const r=DG("images",e,t,n),a=DG("transforms",e,t,n),i=DG("outputShape",e,t,n),o=DG("fillValue",e,t,n),u=DG("interpolation",e,t,n),l=DG("fillMode",e,t,n);return[s.image.transform(r,a,u.toLowerCase(),l.toLowerCase(),o,i)]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"graph":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"Const":return t[e.name];case"PlaceholderWithDefault":const r=DG("default",e,t,n);return[MG(e.name,t,n)||r];case"Placeholder":return[MG(e.name,t,n)];case"Identity":case"StopGradient":case"FakeQuantWithMinMaxVars":case"Snapshot":return[WG(DG("x",e,t,n))];case"IdentityN":return DG("x",e,t,n).map((e=>WG(e)));case"Shape":return[s.tensor1d(DG("x",e,t,n).shape,"int32")];case"ShapeN":return DG("x",e,t,n).map((e=>s.tensor1d(e.shape)));case"Size":return[s.scalar(DG("x",e,t,n).size,"int32")];case"Rank":return[s.scalar(DG("x",e,t,n).rank,"int32")];case"NoOp":return[s.scalar(1)];case"Print":const a=DG("x",e,t,n),i=DG("data",e,t,n),o=DG("message",e,t,n),u=DG("summarize",e,t,n);console.warn("The graph has a tf.print() operation,usually used for debugging, which slows down performance."),console.log(o);for(let e=0;e<i.length;e++)console.log(Array.prototype.slice.call(i[e].dataSync()).slice(0,u));return[a];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"logical":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"Equal":return[s.equal(DG("a",e,t,n),DG("b",e,t,n))];case"NotEqual":return[s.notEqual(DG("a",e,t,n),DG("b",e,t,n))];case"Greater":return[s.greater(DG("a",e,t,n),DG("b",e,t,n))];case"GreaterEqual":return[s.greaterEqual(DG("a",e,t,n),DG("b",e,t,n))];case"Less":return[s.less(DG("a",e,t,n),DG("b",e,t,n))];case"LessEqual":return[s.lessEqual(DG("a",e,t,n),DG("b",e,t,n))];case"LogicalAnd":return[s.logicalAnd(DG("a",e,t,n),DG("b",e,t,n))];case"LogicalNot":return[s.logicalNot(DG("a",e,t,n))];case"LogicalOr":return[s.logicalOr(DG("a",e,t,n),DG("b",e,t,n))];case"Select":case"SelectV2":return[s.where(DG("condition",e,t,n),DG("a",e,t,n),DG("b",e,t,n))];case"BitwiseAnd":return[s.bitwiseAnd(DG("a",e,t,n),DG("b",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"matrices":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"BatchMatMul":case"BatchMatMulV2":case"MatMul":return[s.matMul(DG("a",e,t,n),DG("b",e,t,n),DG("transposeA",e,t,n),DG("transposeB",e,t,n))];case"Einsum":return[s.einsum(DG("equation",e,t,n),...DG("tensors",e,t,n))];case"Transpose":return[s.transpose(DG("x",e,t,n),DG("perm",e,t,n))];case"_FusedMatMul":const[r,a]=DG("fusedOps",e,t,n),i="biasadd"===r,o="prelu"===a,u=DG("numArgs",e,t,n),l=DG("leakyreluAlpha",e,t,n);if(i){if(o&&2!==u)throw new Error("Fused MatMul with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!o&&1!==u)throw new Error("Fused MatMul with BiasAdd must have one extra argument: bias.")}const[c,h]=DG("args",e,t,n);return[s.fused.matMul({a:DG("a",e,t,n),b:DG("b",e,t,n),transposeA:DG("transposeA",e,t,n),transposeB:DG("transposeB",e,t,n),bias:c,activation:a,preluActivationWeights:h,leakyreluAlpha:l})];case"MatrixBandPart":return[s.linalg.bandPart(DG("a",e,t,n),DG("numLower",e,t,n),DG("numUpper",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"normalization":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"EuclideanNorm":return[s.euclideanNorm(DG("x",e,t,n),DG("axis",e,t,n),DG("keepDims",e,t,n))];case"FusedBatchNorm":case"FusedBatchNormV2":case"FusedBatchNormV3":return[s.batchNorm(DG("x",e,t,n),DG("mean",e,t,n),DG("variance",e,t,n),DG("offset",e,t,n),DG("scale",e,t,n),DG("epsilon",e,t,n))];case"LRN":return[s.localResponseNormalization(DG("x",e,t,n),DG("radius",e,t,n),DG("bias",e,t,n),DG("alpha",e,t,n),DG("beta",e,t,n))];case"Softmax":return[s.softmax(DG("x",e,t,n))];case"LogSoftmax":return[s.logSoftmax(DG("x",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"ragged":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"RaggedGather":{const{outputNestedSplits:r,outputDenseValues:a}=s.raggedGather(DG("paramsNestedSplits",e,t,n),DG("paramsDenseValues",e,t,n),DG("indices",e,t,n),DG("outputRaggedRank",e,t,n));return r.concat(a)}case"RaggedRange":{const{rtNestedSplits:r,rtDenseValues:a}=s.raggedRange(DG("starts",e,t,n),DG("limits",e,t,n),DG("splits",e,t,n));return[r,a]}case"RaggedTensorToTensor":return[s.raggedTensorToTensor(DG("shape",e,t,n),DG("values",e,t,n),DG("defaultValue",e,t,n),DG("rowPartitionTensors",e,t,n),DG("rowPartitionTypes",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"reduction":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"Max":{const r=DG("axis",e,t,n),a=DG("keepDims",e,t,n);return[s.max(DG("x",e,t,n),r,a)]}case"Mean":{const r=DG("axis",e,t,n),a=DG("keepDims",e,t,n);return[s.mean(DG("x",e,t,n),r,a)]}case"Min":{const r=DG("axis",e,t,n),a=DG("keepDims",e,t,n);return[s.min(DG("x",e,t,n),r,a)]}case"Sum":{const r=DG("axis",e,t,n),a=DG("keepDims",e,t,n);return[s.sum(DG("x",e,t,n),r,a)]}case"All":{const r=DG("axis",e,t,n),a=DG("keepDims",e,t,n);return[s.all(DG("x",e,t,n),r,a)]}case"Any":{const r=DG("axis",e,t,n),a=DG("keepDims",e,t,n);return[s.any(DG("x",e,t,n),r,a)]}case"ArgMax":{const r=DG("axis",e,t,n);return[s.argMax(DG("x",e,t,n),r)]}case"ArgMin":{const r=DG("axis",e,t,n);return[s.argMin(DG("x",e,t,n),r)]}case"Prod":{const r=DG("axis",e,t,n),a=DG("keepDims",e,t,n);return[s.prod(DG("x",e,t,n),r,a)]}case"Cumprod":{const r=DG("axis",e,t,n),a=DG("exclusive",e,t,n),i=DG("reverse",e,t,n);return[s.cumprod(DG("x",e,t,n),r,a,i)]}case"Cumsum":{const r=DG("axis",e,t,n),a=DG("exclusive",e,t,n),i=DG("reverse",e,t,n);return[s.cumsum(DG("x",e,t,n),r,a,i)]}case"Bincount":const r=DG("x",e,t,n),a=DG("weights",e,t,n),i=DG("size",e,t,n);return[s.bincount(r,a,i)];case"DenseBincount":{const r=DG("x",e,t,n),a=DG("weights",e,t,n),i=DG("size",e,t,n),o=DG("binaryOutput",e,t,n);return[s.denseBincount(r,a,i,o)]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"slice_join":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"ConcatV2":case"Concat":{const r=DG("n",e,t,n),a=DG("axis",e,t,n);let i=DG("tensors",e,t,n);return i=i.slice(0,r),[s.concat(i,a)]}case"Gather":{const r=DG("x",e,t,n),a=DG("indices",e,t,n);return[s.gather(r,s.cast(a,"int32"),0)]}case"GatherV2":{const r=DG("axis",e,t,n),a=DG("batchDims",e,t,n),i=DG("x",e,t,n),o=DG("indices",e,t,n);return[s.gather(i,s.cast(o,"int32"),r,a)]}case"Reverse":{const r=DG("dims",e,t,n),a=[];for(let e=0;e<r.length;e++)r[e]&&a.push(e);const i=DG("x",e,t,n);return[s.reverse(i,a)]}case"ReverseV2":{const r=DG("axis",e,t,n),a=DG("x",e,t,n);return[s.reverse(a,r)]}case"Slice":{const r=DG("begin",e,t,n),a=DG("size",e,t,n);return[s.slice(DG("x",e,t,n),r,a)]}case"StridedSlice":{const r=DG("begin",e,t,n),a=DG("end",e,t,n),i=DG("strides",e,t,n),o=DG("beginMask",e,t,n),u=DG("endMask",e,t,n),l=DG("ellipsisMask",e,t,n),c=DG("newAxisMask",e,t,n),h=DG("shrinkAxisMask",e,t,n),d=DG("x",e,t,n);return[s.stridedSlice(d,r,a,i,o,u,l,c,h)]}case"Pack":return bi((()=>{const r=DG("axis",e,t,n),a=DG("tensors",e,t,n),i=a[0].shape,o=s.squeeze(a[0]).shape,u=a.map((e=>{const t=we(e.shape,i);if(!t&&!we(s.squeeze(e).shape,o))throw new Error("the input tensors shape does not match");return t?e:s.reshape(e,i)}));return[s.stack(u,r)]}));case"Unpack":{const r=DG("axis",e,t,n),a=DG("tensor",e,t,n);return s.unstack(a,r)}case"Tile":{const r=DG("reps",e,t,n);return[s.tile(DG("x",e,t,n),r)]}case"Split":case"SplitV":{const r=DG("axis",e,t,n),a=DG("numOrSizeSplits",e,t,n),i=DG("x",e,t,n);return s.split(i,a,r)}case"ScatterNd":{const r=DG("indices",e,t,n),a=DG("values",e,t,n),i=DG("shape",e,t,n);return[s.scatterND(r,a,i)]}case"GatherNd":{const r=DG("x",e,t,n),a=DG("indices",e,t,n);return[s.gatherND(r,a)]}case"SparseToDense":{const r=DG("sparseIndices",e,t,n),a=DG("outputShape",e,t,n),i=DG("sparseValues",e,t,n),o=DG("defaultValue",e,t,n);return[s.sparseToDense(r,i,a,i.dtype===o.dtype?o:s.cast(o,i.dtype))]}case"TensorScatterUpdate":{const r=DG("indices",e,t,n),a=DG("values",e,t,n),i=DG("tensor",e,t,n);return[s.tensorScatterUpdate(i,r,a)]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"sparse":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"SparseFillEmptyRows":{const{outputIndices:r,outputValues:a,emptyRowIndicator:i,reverseIndexMap:o}=s.sparse.sparseFillEmptyRows(DG("indices",e,t,n),DG("values",e,t,n),DG("denseShape",e,t,n),DG("defaultValue",e,t,n));return[r,a,i,o]}case"SparseReshape":{const{outputIndices:r,outputShape:a}=s.sparse.sparseReshape(DG("inputIndices",e,t,n),DG("inputShape",e,t,n),DG("newShape",e,t,n));return[r,a]}case"SparseSegmentMean":return[s.sparse.sparseSegmentMean(DG("data",e,t,n),DG("indices",e,t,n),DG("segmentIds",e,t,n))];case"SparseSegmentSum":return[s.sparse.sparseSegmentSum(DG("data",e,t,n),DG("indices",e,t,n),DG("segmentIds",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"spectral":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"FFT":return[s.fft(DG("x",e,t,n))];case"IFFT":return[s.ifft(DG("x",e,t,n))];case"RFFT":return[s.rfft(DG("x",e,t,n))];case"IRFFT":return[s.irfft(DG("x",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"string":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"StaticRegexReplace":return[s.string.staticRegexReplace(DG("input",e,t,n),DG("pattern",e,t,n),DG("rewrite",e,t,n),DG("replaceGlobal",e,t,n))];case"StringNGrams":{const{nGrams:r,nGramsSplits:a}=s.string.stringNGrams(DG("data",e,t,n),DG("dataSplits",e,t,n),DG("separator",e,t,n),DG("nGramWidths",e,t,n),DG("leftPad",e,t,n),DG("rightPad",e,t,n),DG("padWidth",e,t,n),DG("preserveShortSequences",e,t,n));return[r,a]}case"StringSplit":{const{indices:r,values:a,shape:i}=s.string.stringSplit(DG("input",e,t,n),DG("delimiter",e,t,n),DG("skipEmpty",e,t,n));return[r,a,i]}case"StringToHashBucketFast":return[s.string.stringToHashBucketFast(DG("input",e,t,n),DG("numBuckets",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"transformation":return r((()=>((e,t,n,s=IH)=>{switch(e.op){case"Cast":return[s.cast(DG("x",e,t,n),DG("dtype",e,t,n))];case"ExpandDims":{const r=DG("axis",e,t,n);return[s.expandDims(DG("x",e,t,n),r)]}case"Squeeze":{const r=DG("axis",e,t,n);return[s.squeeze(DG("x",e,t,n),r)]}case"Reshape":return[s.reshape(DG("x",e,t,n),DG("shape",e,t,n))];case"EnsureShape":return[s.ensureShape(DG("x",e,t,n),DG("shape",e,t,n))];case"MirrorPad":return[s.mirrorPad(DG("x",e,t,n),DG("padding",e,t,n),DG("mode",e,t,n))];case"PadV2":case"Pad":return[s.pad(DG("x",e,t,n),DG("padding",e,t,n),DG("constantValue",e,t,n))];case"SpaceToBatchND":{const r=DG("blockShape",e,t,n),a=DG("paddings",e,t,n);return[s.spaceToBatchND(DG("x",e,t,n),r,a)]}case"BatchToSpaceND":{const r=DG("blockShape",e,t,n),a=DG("crops",e,t,n);return[s.batchToSpaceND(DG("x",e,t,n),r,a)]}case"DepthToSpace":{const r=DG("blockSize",e,t,n),a=DG("dataFormat",e,t,n).toUpperCase();return[s.depthToSpace(DG("x",e,t,n),r,a)]}case"BroadcastTo":return[s.broadcastTo(DG("x",e,t,n),DG("shape",e,t,n))];case"BroadcastArgs":return[s.broadcastArgs(DG("s0",e,t,n),DG("s1",e,t,n))];default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n)));case"hash_table":return(async(e,t,n,s)=>{switch(e.op){case"HashTable":case"HashTableV2":{const r=s.getHashTableHandleByName(e.name);if(null!=r)return[r];{const r=DG("keyDType",e,t,n),a=DG("valueDType",e,t,n),i=new FH(r,a);return s.addHashTable(e.name,i),[i.handle]}}case"InitializeTable":case"InitializeTableV2":case"LookupTableImport":case"LookupTableImportV2":{const r=DG("tableHandle",e,t,n,s),a=DG("keys",e,t,n),i=DG("values",e,t,n),o=s.getHashTableById(r.id);return[await o.import(a,i)]}case"LookupTableFind":case"LookupTableFindV2":{const r=DG("tableHandle",e,t,n,s),a=DG("keys",e,t,n),i=DG("defaultValue",e,t,n),o=s.getHashTableById(r.id);return[await o.find(a,i)]}case"LookupTableSize":case"LookupTableSizeV2":{const r=DG("tableHandle",e,t,n,s);return[s.getHashTableById(r.id).tensorSize()]}default:throw TypeError(`Node type ${e.op} is not implemented`)}})(e,t,n,s);case"custom":const a=FG(e.op);if(a&&a.customExecutor)return a.customExecutor(new vH(e,t,n));throw TypeError(`Custom op ${e.op} is not registered.`);default:throw TypeError(`Unknown op '${e.op}'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()`)}})(e,t,n);return je(a)?a.then((e=>[].concat(e))):[].concat(a)}class MH{constructor(e={},t={},n={},s={},r){this.weightMap=e,this.tensorArrayMap=t,this.tensorListMap=n,this.functionMap=s,this.parseNodeNameCache=r,this.rootContext={id:0,frameName:"",iterationId:0},this.contexts=[this.rootContext],this.lastId=0,this.generateCurrentContextIds()}newFrame(e,t){return{id:e,frameName:t,iterationId:0}}set currentContext(e){this.contexts!==e&&(this.contexts=e,this.generateCurrentContextIds())}get currentContext(){return this.contexts}get currentContextId(){return this._currentContextIds[0]}get currentContextIds(){return this._currentContextIds}generateCurrentContextIds(){const e=[];for(let t=0;t<this.contexts.length-1;t++){const n=this.contexts.slice(0,this.contexts.length-t);e.push(this.contextIdforContexts(n))}e.push(""),this._currentContextIds=e}contextIdforContexts(e){return e?e.map((e=>0===e.id&&0===e.iterationId?"":`${e.frameName}-${e.iterationId}`)).join("/"):""}enterFrame(e){this.contexts&&(this.lastId++,this.contexts=this.contexts.slice(),this.contexts.push(this.newFrame(this.lastId,e)),this._currentContextIds.unshift(this.contextIdforContexts(this.contexts)))}exitFrame(){if(!(this.contexts&&this.contexts.length>1))throw new Error("Cannot exit frame, the context is empty");this.contexts=this.contexts.slice(),this.contexts.splice(-1),this.currentContextIds.shift()}nextIteration(){if(!(this.contexts&&this.contexts.length>0))throw new Error("Cannot increase frame iteration, the context is empty");{this.contexts=this.contexts.slice(),this.lastId++;const e=Object.assign({},this.contexts[this.contexts.length-1]);e.iterationId+=1,e.id=this.lastId,this.contexts.splice(-1,1,e),this._currentContextIds.splice(0,1,this.contextIdforContexts(this.contexts))}}getWeight(e){return this.weightMap[e]}addTensorArray(e){this.tensorArrayMap[e.id]=e}getTensorArray(e){return this.tensorArrayMap[e]}addTensorList(e){this.tensorListMap[e.id]=e}getTensorList(e){return this.tensorListMap[e]}dispose(e){for(const t in this.tensorArrayMap)this.tensorArrayMap[t].clearAndClose(e);for(const t in this.tensorListMap)this.tensorListMap[t].clearAndClose(e)}}
|
|
17031
17031
|
/**
|
|
17032
17032
|
* @license
|
|
17033
17033
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -17043,7 +17043,7 @@ function _H(e,t,n,s,r=bi){const a=((e,t,n)=>{switch(e.category){case"arithmetic"
|
|
|
17043
17043
|
* See the License for the specific language governing permissions and
|
|
17044
17044
|
* limitations under the License.
|
|
17045
17045
|
* =============================================================================
|
|
17046
|
-
*/function
|
|
17046
|
+
*/function OH(e,t,n,s){const r=new Set,a=[];let i=null,o=null;const u=new Set,l=new Set(Object.keys(e).map((e=>zG(e)[0])));s=s||[];const c=new Set(s.map((e=>zG(e.name)[0]))),h=[...t];for(;h.length>0;){const e=h.pop();(UH(e)||VH(e)||GH(e))&&null==i&&(i=e,o=i.children.map((e=>e.name)).filter((e=>r.has(e)))),r.add(e.name),null==n[e.name]&&(l.has(e.name)||c.has(e.name)||(0!==e.inputs.length?e.inputs.forEach((e=>{u.has(e.name)||(u.add(e.name),h.push(e))})):a.push(e.name)))}return{inputs:e,outputs:t,usedNodes:r,missingInputs:a,dynamicNode:i,syncInputs:o}}function LH(e,t){const{usedNodes:n,inputs:s}=t,r=Object.keys(s).map((e=>zG(e)[0])).map((t=>e.nodes[t])),a=e.initNodes||[],i=e=>n.has("string"==typeof e?e:e.name);function o(e){return[...new Map(e.map((e=>[e.name,e]))).values()]}const u=o([...r,...e.weights,...a]).filter(i),l=o([...u,...Object.values(e.nodes)]).filter(i),c=new Map(l.map((e=>[e.name,e]))),h={};for(const e of l){h[e.name]=h[e.name]||0;for(const t of e.children)i(t)||(h[t.name]=Number.POSITIVE_INFINITY),h[t.name]=(h[t.name]||0)+1}const d=Object.entries(h).filter((([,e])=>0===e)).map((([e])=>e)),p=[...d];for(;d.length>0;){const e=d.pop(),t=c.get(e);for(const e of t.children.filter(i))0==--h[e.name]&&(p.push(e.name),d.push(e.name))}const f=function(e,t){const n=new Map(e.map((e=>[e.name,e]))),s=t.map((e=>e.name)),r=new Set(s);for(;s.length>0;){const e=s.pop(),t=n.get(e);for(const e of t.children)n.has(e.name)&&!r.has(e.name)&&(r.add(e.name),s.push(e.name))}const a=e.filter((e=>r.has(e.name)));return a}(p.map((e=>c.get(e))),u);return function(e,t){const n=new Map(e.map(((e,t)=>[e.name,t]))),s=new Set(t.map((e=>e.name))),r=e=>s.has("string"==typeof e?e:e.name),a=new Set(e.map((e=>e.name))),i=e=>a.has("string"==typeof e?e:e.name);for(const t of e){for(const e of t.children.filter(i)){if(!n.has(e.name))throw new PH(`Child ${e.name} of node ${t.name} is unreachable.`);if(n.get(t.name)>n.get(e.name))throw new PH(`Node ${t.name} is scheduled to run after its child ${e.name}.`)}if(!r(t))for(const e of t.inputs){if(!n.has(e.name))throw new PH(`Input ${e.name} of node ${t.name} is unreachable.`);if(n.get(e.name)>n.get(t.name))throw new PH(`Node ${t.name} is scheduled to run before its input ${e.name}.`)}}}(f,u),f}class PH extends Error{constructor(e){super(`NodesExecutionOrderError: ${e}`)}}const zH=new Set(["Switch","Merge","Enter","Exit","NextIteration","StatelessIf","StatelessWhile","if","While"]),BH=new Set(["NonMaxSuppressionV2","NonMaxSuppressionV3","NonMaxSuppressionV5","Where"]),WH=new Set(["HashTable","HashTableV2","LookupTableImport","LookupTableImportV2","LookupTableFind","LookupTableFindV2","LookupTableSize","LookupTableSizeV2"]);function UH(e){return zH.has(e.op)}function VH(e){return BH.has(e.op)}function GH(e){return WH.has(e.op)}
|
|
17047
17047
|
/**
|
|
17048
17048
|
* @license
|
|
17049
17049
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -17059,7 +17059,7 @@ function _H(e,t,n,s,r=bi){const a=((e,t,n)=>{switch(e.category){case"arithmetic"
|
|
|
17059
17059
|
* See the License for the specific language governing permissions and
|
|
17060
17060
|
* limitations under the License.
|
|
17061
17061
|
* =============================================================================
|
|
17062
|
-
*/class VH{get weightIds(){return this.parent?this.parent.weightIds:this._weightIds}get functionExecutorMap(){return this.parent?this.parent.functionExecutorMap:this._functionExecutorMap}get weightMap(){return this.parent?this.parent.weightMap:this._weightMap}set weightMap(e){const t=Object.keys(e).map((t=>e[t].map((e=>e.id))));this._weightIds=[].concat(...t),this._weightMap=e}set resourceManager(e){this._resourceManager=e}get inputs(){return this._inputs.map((e=>({name:e.name,shape:e.attrParams.shape?e.attrParams.shape.value:void 0,dtype:e.attrParams.dtype?e.attrParams.dtype.value:void 0})))}get outputs(){return this._outputs.map((e=>({name:e.name,shape:e.attrParams.shape?e.attrParams.shape.value:void 0,dtype:e.attrParams.dtype?e.attrParams.dtype.value:void 0})))}get inputNodes(){return this._inputs.map((e=>e.signatureKey||e.name))}get outputNodes(){return this._outputs.map((e=>{const t=e.signatureKey||e.name;return e.defaultOutput?`${t}:${e.defaultOutput}`:t}))}get functions(){return Object.keys(this._functions).reduce(((e,t)=>(e[t]=this._functions[t].signature,e)),{})}constructor(e,t){this.graph=e,this.parent=t,this.compiledMap=new Map,this.parseNodeNameCache=new Map,this._weightMap={},this.SEPARATOR=",",this._functions={},this._functionExecutorMap={},this.keepIntermediateTensors=!1,this._outputs=e.outputs,this._inputs=e.inputs,this._initNodes=e.initNodes,this._signature=e.signature,this._functions=e.functions,null!=e.functions&&Object.keys(e.functions).forEach((t=>{this._functionExecutorMap[t]=new VH(e.functions[t],this)}))}getCompilationKey(e,t){const n=e.map((e=>e.name)).sort(),s=t.map((e=>e.name)).sort();return n.join(this.SEPARATOR)+"--"+s.join(this.SEPARATOR)}compile(e,t){const n=DH(e,t,this.weightMap,this._initNodes),{missingInputs:s,dynamicNode:r,syncInputs:a}=n;if(null!=r)throw new Error(`This execution contains the node '${r.name}', which has the dynamic op '${r.op}'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [${a}]`);if(s.length>0){const n=t.map((e=>e.name)),r=Object.keys(e);throw new Error(`Cannot compute the outputs [${n}] from the provided inputs [${r}]. Missing the following inputs: [${s}]`)}const i=MH(this.graph,n),o=function(e){const t=new Map(e.map(((e,t)=>[e.name,t]))),n=Number.MAX_SAFE_INTEGER,s=e.map(((e,t)=>BH(e)?n:t)),r=e=>{const n=s[t.get(e.name)];return null==n?-1:n},a=e.map(((e,t)=>e.children.map(r).reduce(((e,t)=>Math.max(e,t)),s[t]))),i=new Map;for(let t=0;t<e.length;++t){const s=a[t];if(s===n)continue;const r=e[t],o=e[s];i.has(o.name)||i.set(o.name,[]),i.get(o.name).push(r)}return i}(i);return{orderedNodes:i,nodeLiveUntilMap:o}}cloneAndKeepTensor(e){if(null==e)return null;const t=e.clone();return wi(t),t}cloneTensorList(e){if(!e)return null;const t=e.map((e=>this.cloneAndKeepTensor(e)));return t}cloneTensorMap(e){return Object.fromEntries(Object.entries(e).map((([e,t])=>[e,this.cloneTensorList(t)])))}execute(e,t){this.disposeIntermediateTensors(),e=this.mapInputs(e);const n=Object.keys(e).sort();this.checkInputs(e),this.checkInputShapeAndType(e),t=this.mapOutputs(t),this.checkOutputs(t);const s=n.map((e=>this.graph.nodes[LG(e)[0]])),r=t.map((e=>LG(e)[0])),a=new Set(r);let i=r.map((e=>this.graph.nodes[e]));0===i.length&&(i=this._outputs);const o=this.getCompilationKey(s,i);let u=this.compiledMap.get(o);null==u&&(u=this.compile(e,i),this.compiledMap.set(o,u));try{this.keepIntermediateTensors=Qe().getBool("KEEP_INTERMEDIATE_TENSORS")}catch(e){this.keepIntermediateTensors=!1,console.warn(e.message)}const l={},c={};return bi((()=>{const n=new FH(this.weightMap,l,c,this.functionExecutorMap,this.parseNodeNameCache),s=Object.assign({},this.weightMap);this.keepIntermediateTensors&&(this.clonedTensorsMap=this.cloneTensorMap(this.weightMap)),Object.keys(e).forEach((t=>{const[r,a]=LG(t,n),i=[];i[a]=e[t],s[r]=i,this.keepIntermediateTensors&&(this.clonedTensorsMap[r]=this.cloneTensorList(i))}));const r=this.getFrozenTensorIds(s),{orderedNodes:i,nodeLiveUntilMap:o}=u;for(const e of i){if(s[e.name])continue;const t=_H(e,s,n,this._resourceManager);if(je(t))throw new Error(`The execution of the op '${e.op}' returned a promise. Please use model.executeAsync() instead.`);s[e.name]=t,this.keepIntermediateTensors&&(this.clonedTensorsMap[e.name]=this.cloneTensorList(t)),this.checkTensorForDisposalWithNodeLiveUntilInfo(e,s,n,r,a,o.get(e.name))}return null==this.parent&&n.dispose(r),t.map((e=>FG(e,s,n)))}))}getFrozenTensorIds(e){const t=[].concat.apply([],Object.keys(e).map((t=>e[t])).map((e=>e.map((e=>e.id)))));return new Set(t)}checkTensorForDisposal(e,t,n,s,r,a,i){if(!BH(t)&&!a.has(e)){for(const s of n[e])null!=s&&(i[s.id]=(i[s.id]||0)+t.children.length);for(const e of t.inputs){if(BH(e))continue;const t=DG(e.name,n,s);if(null!=t)for(const e of t){if(!e||e.kept||r.has(e.id))continue;const t=i[e.id];1===t?(e.dispose(),delete i[e.id]):null!=t&&i[e.id]--}}}}checkTensorForDisposalWithNodeLiveUntilInfo(e,t,n,s,r,a){function i(e){return BH(e)||r.has(e.name)}if(!BH(e)&&null!=a)for(const e of a){if(i(e))continue;const r=DG(e.name,t,n);for(const e of r)!e||e.kept||s.has(e.id)||e.dispose()}}async executeAsync(e,t){return this._executeAsync(e,t)}disposeIntermediateTensors(){this.clonedTensorsMap&&(Object.values(this.clonedTensorsMap).forEach((e=>{for(const t of e)t&&!t.isDisposed&&t.dispose()})),this.clonedTensorsMap=null)}getIntermediateTensors(){return this.clonedTensorsMap}async _executeAsync(e,t,n=!1,s={},r={}){this.disposeIntermediateTensors(),n||(e=this.mapInputs(e),this.checkInputs(e),this.checkInputShapeAndType(e),t=this.mapOutputs(t),this.checkOutputs(t));try{this.keepIntermediateTensors=Qe().getBool("KEEP_INTERMEDIATE_TENSORS")}catch(e){this.keepIntermediateTensors=!1,console.warn(e.message)}const a=new FH(this.weightMap,s,r,this.functionExecutorMap,this.parseNodeNameCache);this.keepIntermediateTensors&&(this.clonedTensorsMap=this.cloneTensorMap(this.weightMap));const i=await this.executeWithControlFlow(e,a,t,n),o=t.map((e=>FG(e,i,a))),u=o.map((e=>e.id)),l=Object.keys(e).map((t=>e[t].id)),c=new Set([...u,...l,...this.weightIds]);return Object.values(i).forEach((e=>{e.forEach((e=>{!e||e.isDisposed||c.has(e.id)||e.dispose()}))})),null==this.parent&&a.dispose(c),o}async executeFunctionAsync(e,t,n){const s=e.reduce(((e,t,n)=>(e[this.inputs[n].name]=t,e)),{});return this._executeAsync(s,this.outputNodes,!0,t,n)}async executeWithControlFlow(e,t,n,s){const r=Object.keys(e),a=r.map((e=>this.graph.nodes[LG(e)[0]])),i=n.map((e=>LG(e)[0])),o=new Set(i);let u=i.map((e=>this.graph.nodes[e]));0===u.length&&(u=this._outputs);const{usedNodes:l,missingInputs:c,dynamicNode:h,syncInputs:d}=DH(e,u,this.weightMap,this._initNodes),p=[...a,...this.graph.weights,...this._initNodes||[]].map((e=>({node:e,contexts:t.currentContext}))),f=Object.assign({},this.weightMap);Object.keys(e).forEach((t=>{const[n,s]=LG(t),r=[];r[s]=e[t],f[n]=r}));const m={},g=this.getFrozenTensorIds(f),y={};for(;p.length>0;){const e=this.processStack(a,p,t,f,y,g,o,m,l);await Promise.all(e)}null!=h||s||console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead.");const b=u.filter((e=>!BH(e)&&!FG(e.name,f,t))).map((e=>e.name));if(b.length>0){let e="";throw null!=h&&(e=`Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs [${d}]`),new Error(`Cannot compute the outputs [${b}] from the provided inputs [${r}]. Consider providing the following inputs: [${c}]. ${e}`)}return f}processStack(e,t,n,s,r,a,i,o,u){const l=[];for(;t.length>0;){const e=t.pop();n.currentContext=e.contexts;let c="";if("Enter"===e.node.op&&_G("isConstant",e.node,s,n)&&([c]=MG(e.node.name,n)),null==s[e.node.name]){const h=_H(e.node,s,n,this._resourceManager);c||([c]=MG(e.node.name,n));const d=n.currentContext;je(h)?l.push(h.then((l=>(s[c]=l,this.keepIntermediateTensors&&(this.clonedTensorsMap[c]=this.cloneTensorList(l)),n.currentContext=d,this.checkTensorForDisposal(c,e.node,s,n,a,i,o),this.processChildNodes(e.node,t,n,s,r,u),l)))):(s[c]=h,this.keepIntermediateTensors&&(this.clonedTensorsMap[c]=this.cloneTensorList(h)),this.checkTensorForDisposal(c,e.node,s,n,a,i,o),this.processChildNodes(e.node,t,n,s,r,u))}else this.processChildNodes(e.node,t,n,s,r,u)}return l}processChildNodes(e,t,n,s,r,a){e.children.forEach((e=>{const[i]=MG(e.name,n);!r[i]&&a.has(e.name)&&("Merge"===e.op?e.inputNames.some((e=>!!FG(e,s,n)))&&(r[i]=!0,t.push({contexts:n.currentContext,node:e})):e.inputNames.every((e=>!!FG(e,s,n)))&&(r[i]=!0,t.push({contexts:n.currentContext,node:e})))}))}dispose(){Object.keys(this.weightMap).forEach((e=>this.weightMap[e].forEach((e=>e.dispose()))))}checkInputShapeAndType(e){Object.keys(e).forEach((t=>{const n=e[t],[s]=LG(t),r=this.graph.nodes[s];if(r.attrParams.shape&&r.attrParams.shape.value){const e=r.attrParams.shape.value;me(e.length===n.shape.length&&n.shape.every(((t,n)=>-1===e[n]||e[n]===t)),(()=>`The shape of dict['${r.name}'] provided in model.execute(dict) must be [${e}], but was [${n.shape}]`))}r.attrParams.dtype&&r.attrParams.dtype.value&&me(n.dtype===r.attrParams.dtype.value,(()=>`The dtype of dict['${r.name}'] provided in model.execute(dict) must be ${r.attrParams.dtype.value}, but was ${n.dtype}`))}))}mapInputs(e){var t,n;const s={};for(const r in e){const a=null===(n=null===(t=this._signature)||void 0===t?void 0:t.inputs)||void 0===n?void 0:n[r];null!=a?s[a.name]=e[r]:s[r]=e[r]}return s}checkInputs(e){const t=Object.keys(e).filter((e=>{const[t]=LG(e);return null==this.graph.nodes[t]}));if(t.length>0)throw new Error(`The dict provided in model.execute(dict) has keys: [${t}] that are not part of graph`)}mapOutputs(e){return e.map((e=>{var t,n;const s=null===(n=null===(t=this._signature)||void 0===t?void 0:t.outputs)||void 0===n?void 0:n[e];return null!=s?s.name:e}),{})}checkOutputs(e){e.forEach((e=>{const[t]=LG(e);if(!this.graph.nodes[t])throw new Error(`The output '${e}' is not found in the graph`)}))}}class GH{constructor(e={},t={}){this.hashTableNameToHandle=e,this.hashTableMap=t}addHashTable(e,t){this.hashTableNameToHandle[e]=t.handle,this.hashTableMap[t.id]=t}getHashTableHandleByName(e){return this.hashTableNameToHandle[e]}getHashTableById(e){return this.hashTableMap[e]}dispose(){for(const e in this.hashTableMap)this.hashTableMap[e].clearAndClose(),delete this.hashTableMap[e];for(const e in this.hashTableNameToHandle)this.hashTableNameToHandle[e].dispose(),delete this.hashTableNameToHandle[e]}}
|
|
17062
|
+
*/class HH{get weightIds(){return this.parent?this.parent.weightIds:this._weightIds}get functionExecutorMap(){return this.parent?this.parent.functionExecutorMap:this._functionExecutorMap}get weightMap(){return this.parent?this.parent.weightMap:this._weightMap}set weightMap(e){const t=Object.keys(e).map((t=>e[t].map((e=>e.id))));this._weightIds=[].concat(...t),this._weightMap=e}set resourceManager(e){this._resourceManager=e}get inputs(){return this._inputs.map((e=>({name:e.name,shape:e.attrParams.shape?e.attrParams.shape.value:void 0,dtype:e.attrParams.dtype?e.attrParams.dtype.value:void 0})))}get outputs(){return this._outputs.map((e=>({name:e.name,shape:e.attrParams.shape?e.attrParams.shape.value:void 0,dtype:e.attrParams.dtype?e.attrParams.dtype.value:void 0})))}get inputNodes(){return this._inputs.map((e=>e.signatureKey||e.name))}get outputNodes(){return this._outputs.map((e=>{const t=e.signatureKey||e.name;return e.defaultOutput?`${t}:${e.defaultOutput}`:t}))}get functions(){return Object.keys(this._functions).reduce(((e,t)=>(e[t]=this._functions[t].signature,e)),{})}constructor(e,t){this.graph=e,this.parent=t,this.compiledMap=new Map,this.parseNodeNameCache=new Map,this._weightMap={},this.SEPARATOR=",",this._functions={},this._functionExecutorMap={},this.keepIntermediateTensors=!1,this._outputs=e.outputs,this._inputs=e.inputs,this._initNodes=e.initNodes,this._signature=e.signature,this._functions=e.functions,null!=e.functions&&Object.keys(e.functions).forEach((t=>{this._functionExecutorMap[t]=new HH(e.functions[t],this)}))}getCompilationKey(e,t){const n=e.map((e=>e.name)).sort(),s=t.map((e=>e.name)).sort();return n.join(this.SEPARATOR)+"--"+s.join(this.SEPARATOR)}compile(e,t){const n=OH(e,t,this.weightMap,this._initNodes),{missingInputs:s,dynamicNode:r,syncInputs:a}=n;if(null!=r)throw new Error(`This execution contains the node '${r.name}', which has the dynamic op '${r.op}'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [${a}]`);if(s.length>0){const n=t.map((e=>e.name)),r=Object.keys(e);throw new Error(`Cannot compute the outputs [${n}] from the provided inputs [${r}]. Missing the following inputs: [${s}]`)}const i=LH(this.graph,n),o=function(e){const t=new Map(e.map(((e,t)=>[e.name,t]))),n=Number.MAX_SAFE_INTEGER,s=e.map(((e,t)=>UH(e)?n:t)),r=e=>{const n=s[t.get(e.name)];return null==n?-1:n},a=e.map(((e,t)=>e.children.map(r).reduce(((e,t)=>Math.max(e,t)),s[t]))),i=new Map;for(let t=0;t<e.length;++t){const s=a[t];if(s===n)continue;const r=e[t],o=e[s];i.has(o.name)||i.set(o.name,[]),i.get(o.name).push(r)}return i}(i);return{orderedNodes:i,nodeLiveUntilMap:o}}cloneAndKeepTensor(e){if(null==e)return null;const t=e.clone();return wi(t),t}cloneTensorList(e){if(!e)return null;const t=e.map((e=>this.cloneAndKeepTensor(e)));return t}cloneTensorMap(e){return Object.fromEntries(Object.entries(e).map((([e,t])=>[e,this.cloneTensorList(t)])))}execute(e,t){this.disposeIntermediateTensors(),e=this.mapInputs(e);const n=Object.keys(e).sort();this.checkInputs(e),this.checkInputShapeAndType(e),t=this.mapOutputs(t),this.checkOutputs(t);const s=n.map((e=>this.graph.nodes[zG(e)[0]])),r=t.map((e=>zG(e)[0])),a=new Set(r);let i=r.map((e=>this.graph.nodes[e]));0===i.length&&(i=this._outputs);const o=this.getCompilationKey(s,i);let u=this.compiledMap.get(o);null==u&&(u=this.compile(e,i),this.compiledMap.set(o,u));try{this.keepIntermediateTensors=Qe().getBool("KEEP_INTERMEDIATE_TENSORS")}catch(e){this.keepIntermediateTensors=!1,console.warn(e.message)}const l={},c={};return bi((()=>{const n=new MH(this.weightMap,l,c,this.functionExecutorMap,this.parseNodeNameCache),s=Object.assign({},this.weightMap);this.keepIntermediateTensors&&(this.clonedTensorsMap=this.cloneTensorMap(this.weightMap)),Object.keys(e).forEach((t=>{const[r,a]=zG(t,n),i=[];i[a]=e[t],s[r]=i,this.keepIntermediateTensors&&(this.clonedTensorsMap[r]=this.cloneTensorList(i))}));const r=this.getFrozenTensorIds(s),{orderedNodes:i,nodeLiveUntilMap:o}=u;for(const e of i){if(s[e.name])continue;const t=DH(e,s,n,this._resourceManager);if(je(t))throw new Error(`The execution of the op '${e.op}' returned a promise. Please use model.executeAsync() instead.`);s[e.name]=t,this.keepIntermediateTensors&&(this.clonedTensorsMap[e.name]=this.cloneTensorList(t)),this.checkTensorForDisposalWithNodeLiveUntilInfo(e,s,n,r,a,o.get(e.name))}return null==this.parent&&n.dispose(r),t.map((e=>MG(e,s,n)))}))}getFrozenTensorIds(e){const t=[].concat.apply([],Object.keys(e).map((t=>e[t])).map((e=>e.map((e=>e.id)))));return new Set(t)}checkTensorForDisposal(e,t,n,s,r,a,i){if(!UH(t)&&!a.has(e)){for(const s of n[e])null!=s&&(i[s.id]=(i[s.id]||0)+t.children.length);for(const e of t.inputs){if(UH(e))continue;const t=OG(e.name,n,s);if(null!=t)for(const e of t){if(!e||e.kept||r.has(e.id))continue;const t=i[e.id];1===t?(e.dispose(),delete i[e.id]):null!=t&&i[e.id]--}}}}checkTensorForDisposalWithNodeLiveUntilInfo(e,t,n,s,r,a){function i(e){return UH(e)||r.has(e.name)}if(!UH(e)&&null!=a)for(const e of a){if(i(e))continue;const r=OG(e.name,t,n);for(const e of r)!e||e.kept||s.has(e.id)||e.dispose()}}async executeAsync(e,t){return this._executeAsync(e,t)}disposeIntermediateTensors(){this.clonedTensorsMap&&(Object.values(this.clonedTensorsMap).forEach((e=>{for(const t of e)t&&!t.isDisposed&&t.dispose()})),this.clonedTensorsMap=null)}getIntermediateTensors(){return this.clonedTensorsMap}async _executeAsync(e,t,n=!1,s={},r={}){this.disposeIntermediateTensors(),n||(e=this.mapInputs(e),this.checkInputs(e),this.checkInputShapeAndType(e),t=this.mapOutputs(t),this.checkOutputs(t));try{this.keepIntermediateTensors=Qe().getBool("KEEP_INTERMEDIATE_TENSORS")}catch(e){this.keepIntermediateTensors=!1,console.warn(e.message)}const a=new MH(this.weightMap,s,r,this.functionExecutorMap,this.parseNodeNameCache);this.keepIntermediateTensors&&(this.clonedTensorsMap=this.cloneTensorMap(this.weightMap));const i=await this.executeWithControlFlow(e,a,t,n),o=t.map((e=>MG(e,i,a))),u=o.map((e=>e.id)),l=Object.keys(e).map((t=>e[t].id)),c=new Set([...u,...l,...this.weightIds]);return Object.values(i).forEach((e=>{e.forEach((e=>{!e||e.isDisposed||c.has(e.id)||e.dispose()}))})),null==this.parent&&a.dispose(c),o}async executeFunctionAsync(e,t,n){const s=e.reduce(((e,t,n)=>(e[this.inputs[n].name]=t,e)),{});return this._executeAsync(s,this.outputNodes,!0,t,n)}async executeWithControlFlow(e,t,n,s){const r=Object.keys(e),a=r.map((e=>this.graph.nodes[zG(e)[0]])),i=n.map((e=>zG(e)[0])),o=new Set(i);let u=i.map((e=>this.graph.nodes[e]));0===u.length&&(u=this._outputs);const{usedNodes:l,missingInputs:c,dynamicNode:h,syncInputs:d}=OH(e,u,this.weightMap,this._initNodes),p=[...a,...this.graph.weights,...this._initNodes||[]].map((e=>({node:e,contexts:t.currentContext}))),f=Object.assign({},this.weightMap);Object.keys(e).forEach((t=>{const[n,s]=zG(t),r=[];r[s]=e[t],f[n]=r}));const m={},g=this.getFrozenTensorIds(f),y={};for(;p.length>0;){const e=this.processStack(a,p,t,f,y,g,o,m,l);await Promise.all(e)}null!=h||s||console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead.");const b=u.filter((e=>!UH(e)&&!MG(e.name,f,t))).map((e=>e.name));if(b.length>0){let e="";throw null!=h&&(e=`Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs [${d}]`),new Error(`Cannot compute the outputs [${b}] from the provided inputs [${r}]. Consider providing the following inputs: [${c}]. ${e}`)}return f}processStack(e,t,n,s,r,a,i,o,u){const l=[];for(;t.length>0;){const e=t.pop();n.currentContext=e.contexts;let c="";if("Enter"===e.node.op&&DG("isConstant",e.node,s,n)&&([c]=LG(e.node.name,n)),null==s[e.node.name]){const h=DH(e.node,s,n,this._resourceManager);c||([c]=LG(e.node.name,n));const d=n.currentContext;je(h)?l.push(h.then((l=>(s[c]=l,this.keepIntermediateTensors&&(this.clonedTensorsMap[c]=this.cloneTensorList(l)),n.currentContext=d,this.checkTensorForDisposal(c,e.node,s,n,a,i,o),this.processChildNodes(e.node,t,n,s,r,u),l)))):(s[c]=h,this.keepIntermediateTensors&&(this.clonedTensorsMap[c]=this.cloneTensorList(h)),this.checkTensorForDisposal(c,e.node,s,n,a,i,o),this.processChildNodes(e.node,t,n,s,r,u))}else this.processChildNodes(e.node,t,n,s,r,u)}return l}processChildNodes(e,t,n,s,r,a){e.children.forEach((e=>{const[i]=LG(e.name,n);!r[i]&&a.has(e.name)&&("Merge"===e.op?e.inputNames.some((e=>!!MG(e,s,n)))&&(r[i]=!0,t.push({contexts:n.currentContext,node:e})):e.inputNames.every((e=>!!MG(e,s,n)))&&(r[i]=!0,t.push({contexts:n.currentContext,node:e})))}))}dispose(){Object.keys(this.weightMap).forEach((e=>this.weightMap[e].forEach((e=>e.dispose()))))}checkInputShapeAndType(e){Object.keys(e).forEach((t=>{const n=e[t],[s]=zG(t),r=this.graph.nodes[s];if(r.attrParams.shape&&r.attrParams.shape.value){const e=r.attrParams.shape.value;me(e.length===n.shape.length&&n.shape.every(((t,n)=>-1===e[n]||e[n]===t)),(()=>`The shape of dict['${r.name}'] provided in model.execute(dict) must be [${e}], but was [${n.shape}]`))}r.attrParams.dtype&&r.attrParams.dtype.value&&me(n.dtype===r.attrParams.dtype.value,(()=>`The dtype of dict['${r.name}'] provided in model.execute(dict) must be ${r.attrParams.dtype.value}, but was ${n.dtype}`))}))}mapInputs(e){var t,n;const s={};for(const r in e){const a=null===(n=null===(t=this._signature)||void 0===t?void 0:t.inputs)||void 0===n?void 0:n[r];null!=a?s[a.name]=e[r]:s[r]=e[r]}return s}checkInputs(e){const t=Object.keys(e).filter((e=>{const[t]=zG(e);return null==this.graph.nodes[t]}));if(t.length>0)throw new Error(`The dict provided in model.execute(dict) has keys: [${t}] that are not part of graph`)}mapOutputs(e){return e.map((e=>{var t,n;const s=null===(n=null===(t=this._signature)||void 0===t?void 0:t.outputs)||void 0===n?void 0:n[e];return null!=s?s.name:e}),{})}checkOutputs(e){e.forEach((e=>{const[t]=zG(e);if(!this.graph.nodes[t])throw new Error(`The output '${e}' is not found in the graph`)}))}}class qH{constructor(e={},t={}){this.hashTableNameToHandle=e,this.hashTableMap=t}addHashTable(e,t){this.hashTableNameToHandle[e]=t.handle,this.hashTableMap[t.id]=t}getHashTableHandleByName(e){return this.hashTableNameToHandle[e]}getHashTableById(e){return this.hashTableMap[e]}dispose(){for(const e in this.hashTableMap)this.hashTableMap[e].clearAndClose(),delete this.hashTableMap[e];for(const e in this.hashTableNameToHandle)this.hashTableNameToHandle[e].dispose(),delete this.hashTableNameToHandle[e]}}
|
|
17063
17063
|
/**
|
|
17064
17064
|
* @license
|
|
17065
17065
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -17075,7 +17075,7 @@ function _H(e,t,n,s,r=bi){const a=((e,t,n)=>{switch(e.category){case"arithmetic"
|
|
|
17075
17075
|
* See the License for the specific language governing permissions and
|
|
17076
17076
|
* limitations under the License.
|
|
17077
17077
|
* =============================================================================
|
|
17078
|
-
*/const
|
|
17078
|
+
*/const jH="?tfjs-format=file",XH="model.json";class KH{get modelVersion(){return this.version}get inputNodes(){return this.executor.inputNodes}get outputNodes(){return this.executor.outputNodes}get inputs(){return this.executor.inputs}get outputs(){return this.executor.outputs}get weights(){return this.executor.weightMap}get metadata(){return this.artifacts.userDefinedMetadata}get modelSignature(){return this.signature}get modelStructuredOutputKeys(){return this.structuredOutputKeys}constructor(e,t={},n=Kp){this.modelUrl=e,this.loadOptions=t,this.version="n/a",this.io=n,null==t&&(this.loadOptions={}),this.resourceManager=new qH}findIOHandler(){const e=this.modelUrl;if(null!=e.load)this.handler=e;else if(null!=this.loadOptions.requestInit)this.handler=this.io.browserHTTPRequest(e,this.loadOptions);else{const t=this.io.getLoadHandlers(e,this.loadOptions);if(0===t.length)t.push(this.io.browserHTTPRequest(e,this.loadOptions));else if(t.length>1)throw new Error(`Found more than one (${t.length}) load handlers for URL '${[e]}'`);this.handler=t[0]}}load(){if(this.findIOHandler(),null==this.handler.load)throw new Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");const e=this.handler.load();return je(e)?e.then((e=>null==e.getWeightStream?this.loadSync(e):this.loadStreaming(e))):this.loadSync(e)}loadSync(e){const t=this.io.decodeWeights(e.weightData,e.weightSpecs);return this.loadWithWeightMap(e,t)}async loadStreaming(e){if(null==e.getWeightStream)throw new Error("Model artifacts missing streamWeights function");const t=await _i(e.getWeightStream(),e.weightSpecs);return this.loadWithWeightMap(e,t)}loadWithWeightMap(e,t){this.artifacts=e;const n=this.artifacts.modelTopology;let s=this.artifacts.signature;if(null!=this.artifacts.userDefinedMetadata){const e=this.artifacts.userDefinedMetadata;null!=e.signature&&(s=e.signature),null!=e.structuredOutputKeys&&(this.structuredOutputKeys=e.structuredOutputKeys)}if(this.signature=s,this.version=`${n.versions.producer}.${n.versions.minConsumer}`,this.executor=new HH(oH.Instance.transformGraph(n,this.signature)),this.executor.weightMap=this.convertTensorMapToTensorsMap(t),this.executor.resourceManager=this.resourceManager,null!=e.modelInitializer&&null!=e.modelInitializer.node){const t=oH.Instance.transformGraph(e.modelInitializer);this.initializer=new HH(t),this.initializer.weightMap=this.executor.weightMap,this.initializer.resourceManager=this.resourceManager,this.initializerSignature=e.initializerSignature}return!0}async save(e,t){if("string"==typeof e){const t=this.io.getSaveHandlers(e);if(0===t.length)throw new Error(`Cannot find any save handlers for URL '${e}'`);if(t.length>1)throw new Error(`Found more than one (${t.length}) save handlers for URL '${e}'`);e=t[0]}if(null==e.save)throw new Error("GraphModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");return e.save(this.artifacts)}addStructuredOutputNames(e){if(this.structuredOutputKeys){const t={};return(e instanceof _a?[e]:e).forEach(((e,n)=>t[this.structuredOutputKeys[n]]=e)),t}return e}predict(e,t){const n=this.execute(e,this.outputNodes);return this.addStructuredOutputNames(n)}async predictAsync(e,t){const n=await this.executeAsync(e,this.outputNodes);return this.addStructuredOutputNames(n)}normalizeInputs(e){var t;if(!(e instanceof _a||Array.isArray(e))){const n=null===(t=this.signature)||void 0===t?void 0:t.inputs;if(null!=n)for(const t in n){const s=n[t];null!=s.resourceId&&(e[t]=this.resourceIdToCapturedInput[s.resourceId])}return e}e=Array.isArray(e)?e:[e];const n=Object.keys(this.resourceIdToCapturedInput).length;if(e.length+n!==this.inputNodes.length)throw new Error(`Input tensor count mismatch, the graph model has ${this.inputNodes.length-n} non-resource placeholders, while there are ${e.length} input tensors provided.`);let s=0;return this.inputNodes.reduce(((t,n)=>{var r,a,i;const o=null===(i=null===(a=null===(r=this.signature)||void 0===r?void 0:r.inputs)||void 0===a?void 0:a[n])||void 0===i?void 0:i.resourceId;return t[n]=null!=o?this.resourceIdToCapturedInput[o]:e[s++],t}),{})}normalizeOutputs(e){return e=e||this.outputNodes,Array.isArray(e)?e:[e]}executeInitializerGraph(){return null==this.initializer?[]:null==this.initializerSignature?this.initializer.execute({},[]):this.initializer.execute({},Object.keys(this.initializerSignature.outputs))}async executeInitializerGraphAsync(){return null==this.initializer?[]:null==this.initializerSignature?this.initializer.executeAsync({},[]):this.initializer.executeAsync({},Object.keys(this.initializerSignature.outputs))}setResourceIdToCapturedInput(e){if(this.resourceIdToCapturedInput={},this.initializerSignature){const t=this.initializerSignature.outputs,n=Object.keys(t);for(let s=0;s<n.length;s++){const r=t[n[s]];this.resourceIdToCapturedInput[r.resourceId]=e[s]}}}execute(e,t){null==this.resourceIdToCapturedInput&&this.setResourceIdToCapturedInput(this.executeInitializerGraph()),e=this.normalizeInputs(e),t=this.normalizeOutputs(t);const n=this.executor.execute(e,t);return n.length>1?n:n[0]}async executeAsync(e,t){null==this.resourceIdToCapturedInput&&this.setResourceIdToCapturedInput(await this.executeInitializerGraphAsync()),e=this.normalizeInputs(e),t=this.normalizeOutputs(t);const n=await this.executor.executeAsync(e,t);return n.length>1?n:n[0]}getIntermediateTensors(){return this.executor.getIntermediateTensors()}disposeIntermediateTensors(){this.executor.disposeIntermediateTensors()}convertTensorMapToTensorsMap(e){return Object.keys(e).reduce(((t,n)=>(t[n]=[e[n]],t)),{})}dispose(){this.executor.dispose(),this.initializer&&(this.initializer.dispose(),this.resourceIdToCapturedInput&&xi(this.resourceIdToCapturedInput)),this.resourceManager.dispose()}}async function YH(e,t={},n=Kp){if(null==e)throw new Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");null==t&&(t={}),t.fromTFHub&&"string"==typeof e&&(e=function(e){e.endsWith("/")||(e+="/");return`${e}${XH}${jH}`}
|
|
17079
17079
|
/**
|
|
17080
17080
|
* @license
|
|
17081
17081
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -17092,7 +17092,7 @@ function _H(e,t,n,s,r=bi){const a=((e,t,n)=>{switch(e.category){case"arithmetic"
|
|
|
17092
17092
|
* limitations under the License.
|
|
17093
17093
|
*
|
|
17094
17094
|
* =============================================================================
|
|
17095
|
-
*/(e));const s=new
|
|
17095
|
+
*/(e));const s=new KH(e,t,n);return await s.load(),s}var QH;!function(e){e[e.FAIL=0]="FAIL",e[e.SHORTEST=1]="SHORTEST",e[e.LONGEST=2]="LONGEST"}(QH||(QH={}));
|
|
17096
17096
|
/**
|
|
17097
17097
|
* @license
|
|
17098
17098
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -17109,7 +17109,7 @@ function _H(e,t,n,s,r=bi){const a=((e,t,n)=>{switch(e.category){case"arithmetic"
|
|
|
17109
17109
|
* limitations under the License.
|
|
17110
17110
|
* =============================================================================
|
|
17111
17111
|
*/
|
|
17112
|
-
const
|
|
17112
|
+
const JH=Qh;class ZH extends ue{nextDataId(){return ZH.nextDataId++}constructor(){super(),this.blockSize=48,this.firstUse=!0,this.data=new oe(this,gi())}write(e,t,n){this.firstUse&&(this.firstUse=!1,Qe().get("IS_NODE")&&fr("\n============================\nHi, looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, visit https://github.com/tensorflow/tfjs-node for more details. \n============================"));const s={id:this.nextDataId()};return this.data.set(s,{values:e,dtype:n,refCount:1}),s}makeTensorInfo(e,t,n){let s;if("string"===t&&null!=n&&n.length>0&&_e(n[0])){const r=n.map((e=>fa(e)));s=this.write(r,e,t)}else s=this.write(n,e,t);return{dataId:s,shape:e,dtype:t}}refCount(e){if(this.data.has(e)){return this.data.get(e).refCount}return 0}incRef(e){this.data.get(e).refCount++}decRef(e){if(this.data.has(e)){this.data.get(e).refCount--}}move(e,t,n,s,r){this.data.set(e,{values:t,dtype:s,refCount:r})}numDataIds(){return this.data.numDataIds()}async read(e){return this.readSync(e)}readSync(e){const{dtype:t,complexTensorInfos:n}=this.data.get(e);if("complex64"===t){return Gf(this.readSync(n.real.dataId),this.readSync(n.imag.dataId))}return Be(this.data.get(e).values,t)}bufferSync(e){const t=this.readSync(e.dataId);if("string"===e.dtype)try{const n=t.map((e=>ma(e)));return ko(e.shape,e.dtype,n)}catch(e){throw new Error("Failed to decode encoded string bytes into utf-8")}return ko(e.shape,e.dtype,t)}makeOutput(e,t,n){return gi().makeTensorFromTensorInfo(this.makeTensorInfo(t,n,e),this)}disposeData(e,t=!1){if(this.data.has(e)){if(this.data.get(e).refCount--,!t&&this.data.get(e).refCount>0)return!1;const{complexTensorInfos:n}=this.data.get(e);null!=n&&(this.disposeData(n.real.dataId,!0),this.disposeData(n.imag.dataId,!0)),this.data.delete(e)}return!0}disposeIntermediateTensorInfo(e){this.disposeData(e.dataId)}async time(e){const t=pa();e();return{kernelMs:pa()-t}}memory(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}}where(e){Jg([e],"where");const t=this.readSync(e.dataId);return JH(e.shape,t)}dispose(){}floatPrecision(){return 32}epsilon(){return super.epsilon()}}ZH.nextDataId=0,
|
|
17113
17113
|
/**
|
|
17114
17114
|
* @license
|
|
17115
17115
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17126,7 +17126,7 @@ const YH=Qh;class QH extends ue{nextDataId(){return QH.nextDataId++}constructor(
|
|
|
17126
17126
|
* limitations under the License.
|
|
17127
17127
|
* =============================================================================
|
|
17128
17128
|
*/
|
|
17129
|
-
Ii("cpu",(()=>new
|
|
17129
|
+
Ii("cpu",(()=>new ZH),1);
|
|
17130
17130
|
/**
|
|
17131
17131
|
* @license
|
|
17132
17132
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17143,7 +17143,7 @@ Ii("cpu",(()=>new QH),1);
|
|
|
17143
17143
|
* limitations under the License.
|
|
17144
17144
|
* =============================================================================
|
|
17145
17145
|
*/
|
|
17146
|
-
const
|
|
17146
|
+
const eq=Sy(en,(e=>e>=0?e:Math.exp(e)-1)),tq={kernelName:en,backendName:"cpu",kernelFunc:eq};
|
|
17147
17147
|
/**
|
|
17148
17148
|
* @license
|
|
17149
17149
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17160,7 +17160,7 @@ const JH=Sy(en,(e=>e>=0?e:Math.exp(e)-1)),ZH={kernelName:en,backendName:"cpu",ke
|
|
|
17160
17160
|
* limitations under the License.
|
|
17161
17161
|
* =============================================================================
|
|
17162
17162
|
*/
|
|
17163
|
-
function
|
|
17163
|
+
function nq(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{alpha:a}=s;Jg([r],"leakyRelu");const i=be(r.shape),o=n.data.get(r.dataId).values,u=$e("float32",i);for(let e=0;e<o.length;e++)u[e]=o[e]<0?a*o[e]:o[e];return n.makeTensorInfo(r.shape,"float32",u)}const sq={kernelName:Sn,backendName:"cpu",kernelFunc:nq},rq=ty(((e,t)=>e<0?t*e:e));
|
|
17164
17164
|
/**
|
|
17165
17165
|
* @license
|
|
17166
17166
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17176,7 +17176,7 @@ function eq(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{alpha:a}=s;Jg([r],"l
|
|
|
17176
17176
|
* See the License for the specific language governing permissions and
|
|
17177
17177
|
* limitations under the License.
|
|
17178
17178
|
* =============================================================================
|
|
17179
|
-
*/function
|
|
17179
|
+
*/function aq(e){const{inputs:t,backend:n}=e,{x:s,alpha:r}=t;Jg([s,r],"prelu");const a=n.data.get(s.dataId).values,i=n.data.get(r.dataId).values,[o,u]=rq(s.shape,r.shape,a,i,"float32");return n.makeTensorInfo(u,"float32",o)}const iq={kernelName:as,backendName:"cpu",kernelFunc:aq},oq=Sy(ps,(e=>Math.max(0,e))),uq={kernelName:ps,backendName:"cpu",kernelFunc:oq},lq=Sy(xs,(e=>Math.min(Math.max(0,e),6))),cq={kernelName:xs,backendName:"cpu",kernelFunc:lq};
|
|
17180
17180
|
/**
|
|
17181
17181
|
* @license
|
|
17182
17182
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17209,7 +17209,7 @@ function eq(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{alpha:a}=s;Jg([r],"l
|
|
|
17209
17209
|
* limitations under the License.
|
|
17210
17210
|
* =============================================================================
|
|
17211
17211
|
*/
|
|
17212
|
-
function
|
|
17212
|
+
function hq(e,t,n,s,r){if("linear"===n)return ay({inputs:{x:t},backend:e});if("relu"===n)return oq({inputs:{x:t},backend:e});if("elu"===n)return eq({inputs:{x:t},backend:e});if("relu6"===n)return lq({inputs:{x:t},backend:e});if("prelu"===n)return aq({inputs:{x:t,alpha:s},backend:e});if("leakyrelu"===n)return nq({inputs:{x:t},backend:e,attrs:{alpha:r}});if("sigmoid"===n)return jb({inputs:{x:t},backend:e});throw new Error(`Activation ${n} has not been implemented for the CPU backend.`)}
|
|
17213
17213
|
/**
|
|
17214
17214
|
* @license
|
|
17215
17215
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17225,7 +17225,7 @@ function lq(e,t,n,s,r){if("linear"===n)return ay({inputs:{x:t},backend:e});if("r
|
|
|
17225
17225
|
* See the License for the specific language governing permissions and
|
|
17226
17226
|
* limitations under the License.
|
|
17227
17227
|
* =============================================================================
|
|
17228
|
-
*/function
|
|
17228
|
+
*/function dq(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{shape:a}=s,i=be(r.shape),o=Ce(a,i),u=be(o);me(i===u,(()=>`The new shape (${o}) has ${u} elements and the old shape (${r.shape}) has ${i} elements. The new shape and old shape must have the same number of elements.`)),n.incRef(r.dataId);const l=n.data.get(r.dataId);if(null!=l.complexTensorInfos){const e=l.complexTensorInfos.real,t=l.complexTensorInfos.imag;e.shape=o,t.shape=o}return{dataId:r.dataId,shape:o,dtype:r.dtype}}const pq={kernelName:fs,backendName:"cpu",kernelFunc:dq};
|
|
17229
17229
|
/**
|
|
17230
17230
|
* @license
|
|
17231
17231
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17241,7 +17241,7 @@ function lq(e,t,n,s,r){if("linear"===n)return ay({inputs:{x:t},backend:e});if("r
|
|
|
17241
17241
|
* See the License for the specific language governing permissions and
|
|
17242
17242
|
* limitations under the License.
|
|
17243
17243
|
* =============================================================================
|
|
17244
|
-
*/function
|
|
17244
|
+
*/function fq(e){const{inputs:t,backend:n,attrs:s}=e,{a:r,b:a}=t,{transposeA:i,transposeB:o}=s;Jg([r,a],"matMul");const u=r.shape.length,l=a.shape.length,c=i?r.shape[u-2]:r.shape[u-1],h=o?a.shape[l-1]:a.shape[l-2],d=i?r.shape[u-1]:r.shape[u-2],p=o?a.shape[l-2]:a.shape[l-1],f=r.shape.slice(0,-2),m=a.shape.slice(0,-2),g=be(f),y=be(m),b=qu(r.shape.slice(0,-2),a.shape.slice(0,-2)).concat([d,p]);me(c===h,(()=>`Error in matMul: inner shapes (${c}) and (${h}) of Tensors with shapes ${r.shape} and ${a.shape} and transposeA=${i} and transposeB=${o} must match.`));const x=o?[y,p,h]:[y,h,p],w=dq({inputs:{x:r},backend:n,attrs:{shape:i?[g,c,d]:[g,d,c]}}),k=dq({inputs:{x:a},backend:n,attrs:{shape:x}}),v=i?w.shape[1]:w.shape[2],I=i?w.shape[2]:w.shape[1],S=o?k.shape[1]:k.shape[2],C=Math.max(g,y),N=n.data.get(w.dataId).values,T=n.data.get(k.dataId).values,$=Le(w.shape),R=Le(k.shape),[E,A,_]=i?[$[0],1,$[1]]:[$[0],$[1],1],[F,D,M]=o?[1,R[1],R[0]]:[R[1],1,R[0]],O=I*S,L=ko([C,I,S],w.dtype),P=L.values,z=n.blockSize;for(let e=0;e<C;e++){const t=e%g,n=e%y;for(let s=0;s<I;s+=z){const r=Math.min(s+z,I);for(let a=0;a<S;a+=z){const i=Math.min(a+z,S);for(let o=0;o<v;o+=z){const u=Math.min(o+z,v);for(let l=s;l<r;l++)for(let s=a;s<i;s++){let r=0;for(let e=o;e<u;e++){r+=N[t*E+l*A+e*_]*T[e*F+s*D+n*M]}P[e*O+(l*S+s)]+=r}}}}}return n.disposeIntermediateTensorInfo(w),n.disposeIntermediateTensorInfo(k),n.makeTensorInfo(b,L.dtype,L.values)}const mq={kernelName:wt,backendName:"cpu",kernelFunc:fq};
|
|
17245
17245
|
/**
|
|
17246
17246
|
* @license
|
|
17247
17247
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17257,7 +17257,7 @@ function lq(e,t,n,s,r){if("linear"===n)return ay({inputs:{x:t},backend:e});if("r
|
|
|
17257
17257
|
* See the License for the specific language governing permissions and
|
|
17258
17258
|
* limitations under the License.
|
|
17259
17259
|
* =============================================================================
|
|
17260
|
-
*/const
|
|
17260
|
+
*/const gq={kernelName:hr,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{a:r,b:a,bias:i,preluActivationWeights:o}=t,{transposeA:u,transposeB:l,activation:c,leakyreluAlpha:h}=s;let d,p,f;const m=[];d=fq({inputs:{a:r,b:a},attrs:{transposeA:u,transposeB:l},backend:n}),i&&(p=gy({inputs:{a:d,b:i},backend:n}),m.push(d),d=p),c&&(f=hq(n,d,c,o,h),m.push(d),d=f);for(const e of m)n.disposeIntermediateTensorInfo(e);return d}},yq=Sy(st,(e=>Math.acos(e))),bq={kernelName:st,backendName:"cpu",kernelFunc:yq},xq=Sy(rt,(e=>Math.acosh(e))),wq={kernelName:rt,backendName:"cpu",kernelFunc:xq};
|
|
17261
17261
|
/**
|
|
17262
17262
|
* @license
|
|
17263
17263
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17273,7 +17273,7 @@ function lq(e,t,n,s,r){if("linear"===n)return ay({inputs:{x:t},backend:e});if("r
|
|
|
17273
17273
|
* See the License for the specific language governing permissions and
|
|
17274
17274
|
* limitations under the License.
|
|
17275
17275
|
* =============================================================================
|
|
17276
|
-
*/const
|
|
17276
|
+
*/const kq={kernelName:it,backendName:"cpu",kernelFunc:
|
|
17277
17277
|
/**
|
|
17278
17278
|
* @license
|
|
17279
17279
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17306,7 +17306,7 @@ function(e){const{inputs:t,backend:n}=e,s=t;Jg(t,"addN");const r=s.map((e=>n.dat
|
|
|
17306
17306
|
* See the License for the specific language governing permissions and
|
|
17307
17307
|
* limitations under the License.
|
|
17308
17308
|
* =============================================================================
|
|
17309
|
-
*/const
|
|
17309
|
+
*/const vq={kernelName:ot,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a,keepDims:i}=s;Jg(r,"all");const o=Ne(a,r.shape);let u=o;const l=ol(u,r.shape.length);let c=r;null!=l&&(c=Nb({inputs:{x:r},backend:n,attrs:{perm:l}}),u=ll(u.length,r.shape.length)),il("all",u,c.shape.length);const[h,d]=rl(c.shape,u),p=be(d),f=Ue(be(h),c.dtype),m=n.data.get(c.dataId).values;for(let e=0;e<f.length;++e){const t=e*p;let n=m[t];for(let e=0;e<p;++e){const s=m[t+e];n=n&&s}f[e]=n}null!=l&&n.disposeIntermediateTensorInfo(c);const g=n.makeTensorInfo(h,c.dtype,f);if(i){const e=dq({inputs:{x:g},backend:n,attrs:{shape:al(h,o)}});return n.disposeIntermediateTensorInfo(g),e}return g}};
|
|
17310
17310
|
/**
|
|
17311
17311
|
* @license
|
|
17312
17312
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17322,7 +17322,7 @@ function(e){const{inputs:t,backend:n}=e,s=t;Jg(t,"addN");const r=s.map((e=>n.dat
|
|
|
17322
17322
|
* See the License for the specific language governing permissions and
|
|
17323
17323
|
* limitations under the License.
|
|
17324
17324
|
* =============================================================================
|
|
17325
|
-
*/const
|
|
17325
|
+
*/const Iq={kernelName:ut,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a,keepDims:i}=s;Jg(r,"any");const o=Ne(a,r.shape);let u=o;const l=ol(u,r.shape.length);let c=r;null!=l&&(c=Nb({inputs:{x:r},backend:n,attrs:{perm:l}}),u=ll(u.length,r.shape.length)),il("any",u,c.shape.length);const[h,d]=rl(c.shape,u),p=be(d),f=Ue(be(h),c.dtype),m=n.data.get(c.dataId).values;for(let e=0;e<f.length;++e){const t=e*p;let n=m[t];for(let e=0;e<p;++e){const s=m[t+e];n=n||s}f[e]=n}null!=l&&n.disposeIntermediateTensorInfo(c);const g=n.makeTensorInfo(h,c.dtype,f);if(i){const e=dq({inputs:{x:g},backend:n,attrs:{shape:al(h,o)}});return n.disposeIntermediateTensorInfo(g),e}return g}};
|
|
17326
17326
|
/**
|
|
17327
17327
|
* @license
|
|
17328
17328
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17338,7 +17338,7 @@ function(e){const{inputs:t,backend:n}=e,s=t;Jg(t,"addN");const r=s.map((e=>n.dat
|
|
|
17338
17338
|
* See the License for the specific language governing permissions and
|
|
17339
17339
|
* limitations under the License.
|
|
17340
17340
|
* =============================================================================
|
|
17341
|
-
*/const
|
|
17341
|
+
*/const Sq={kernelName:lt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a}=s;Jg(r,"argMax");let i=Ne(a,r.shape);const o=ol(i,r.shape.length);let u=r;const l=[];null!=o&&(u=Nb({inputs:{x:r},backend:n,attrs:{perm:o}}),l.push(u),i=ll(i.length,u.shape.length)),i=[i[0]],il("argMax",i,u.shape.length);const[c,h]=rl(u.shape,i),d=Ue(be(c),"int32"),p=be(h),f=n.data.get(u.dataId).values;for(let e=0;e<d.length;++e){const t=e*p;let n=f[t],s=0;for(let e=0;e<p;++e){const r=f[t+e];r>n&&(n=r,s=e)}d[e]=s}return l.forEach((e=>n.disposeIntermediateTensorInfo(e))),n.makeTensorInfo(c,"int32",d)}};
|
|
17342
17342
|
/**
|
|
17343
17343
|
* @license
|
|
17344
17344
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17354,7 +17354,7 @@ function(e){const{inputs:t,backend:n}=e,s=t;Jg(t,"addN");const r=s.map((e=>n.dat
|
|
|
17354
17354
|
* See the License for the specific language governing permissions and
|
|
17355
17355
|
* limitations under the License.
|
|
17356
17356
|
* =============================================================================
|
|
17357
|
-
*/const
|
|
17357
|
+
*/const Cq={kernelName:ct,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a}=s;Jg(r,"argMin");let i=Ne(a,r.shape);const o=ol(i,r.shape.length);let u=r;const l=[];null!=o&&(u=Nb({inputs:{x:r},backend:n,attrs:{perm:o}}),l.push(u),i=ll(i.length,u.shape.length)),i=[i[0]],il("argMin",i,u.shape.length);const[c,h]=rl(u.shape,i),d=Ue(be(c),"int32"),p=be(h),f=n.data.get(u.dataId).values;for(let e=0;e<d.length;++e){const t=e*p;let n=f[t],s=0;for(let e=0;e<p;++e){const r=f[t+e];r<n&&(n=r,s=e)}d[e]=s}return l.forEach((e=>n.disposeIntermediateTensorInfo(e))),n.makeTensorInfo(c,"int32",d)}},Nq=Sy(ht,(e=>Math.asin(e))),Tq={kernelName:ht,backendName:"cpu",kernelFunc:Nq},$q=Sy(dt,(e=>Math.asinh(e))),Rq={kernelName:dt,backendName:"cpu",kernelFunc:$q},Eq=Sy(pt,(e=>Math.atan(e))),Aq={kernelName:pt,backendName:"cpu",kernelFunc:Eq},_q=ty(((e,t)=>Math.atan2(e,t))),Fq=dy(mt,_q),Dq={kernelName:mt,backendName:"cpu",kernelFunc:Fq},Mq=Sy(ft,(e=>Math.atanh(e))),Oq={kernelName:ft,backendName:"cpu",kernelFunc:Mq};
|
|
17358
17358
|
/**
|
|
17359
17359
|
* @license
|
|
17360
17360
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17387,7 +17387,7 @@ function(e){const{inputs:t,backend:n}=e,s=t;Jg(t,"addN");const r=s.map((e=>n.dat
|
|
|
17387
17387
|
* limitations under the License.
|
|
17388
17388
|
* =============================================================================
|
|
17389
17389
|
*/
|
|
17390
|
-
function
|
|
17390
|
+
function Lq(e,t,n,s,r,a){const i=r.strideHeight,o=r.strideWidth,u=r.dilationHeight,l=r.dilationWidth,c=r.effectiveFilterHeight,h=r.effectiveFilterWidth,d=r.padInfo.top,p=r.padInfo.left,f="max"===a?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,m=ko(r.outShape,n),g=m.values,y=r.outShape[1]*r.outShape[2]*r.outShape[3],b=r.outShape[2]*r.outShape[3],x=r.outShape[3];for(let t=0;t<r.batchSize;++t){const n=t*y,m=t*s[0];for(let t=0;t<r.inChannels;++t)for(let y=0;y<r.outHeight;++y){const w=y*i-d,k=Math.max(0,w),v=Math.min(r.inHeight,c+w),I=n+y*b;for(let n=0;n<r.outWidth;++n){const i=n*o-p,c=Math.max(0,i),d=Math.min(r.inWidth,h+i);let y=f,b=0,w=0;for(let n=k;n<v;n+=u){const r=m+n*s[1];for(let n=c;n<d;n+=l){const i=e[r+n*s[2]+t];"max"===a&&i>y?y=i:"avg"===a&&(b+=i,w++)}if(isNaN(y))break}g[I+n*x+t]="avg"===a?b/w:y}}}return m}function Pq(e,t,n,s,r=!1,a=!1){const i=ko(s.outShape,"int32"),o=s.strideHeight,u=s.strideWidth,l=s.dilationHeight,c=s.dilationWidth,h=s.effectiveFilterHeight,d=s.effectiveFilterWidth,p=s.padInfo.top,f=s.padInfo.left,m=ko(t,n,e);for(let e=0;e<s.batchSize;++e)for(let t=0;t<s.inChannels;++t)for(let n=0;n<s.outHeight;++n){const g=n*o-p;let y=g;for(;y<0;)y+=l;const b=Math.min(s.inHeight,h+g);for(let o=0;o<s.outWidth;++o){const h=o*u-f;let p=h;for(;p<0;)p+=c;const x=Math.min(s.inWidth,d+h);let w=Number.NEGATIVE_INFINITY,k=-1;for(let n=y;n<b;n+=l){const i=n-g;for(let o=p;o<x;o+=c){const u=o-h,l=m.get(e,n,o,t);l>w&&(w=l,k=r?a?((e*s.inHeight+n)*s.inWidth+o)*s.inChannels+t:(n*s.inWidth+o)*s.inChannels+t:i*d+u)}}i.set(k,e,n,o,t)}}return i}function zq(e,t,n,s,r,a){const i=r.strideDepth,o=r.strideHeight,u=r.strideWidth,l=r.dilationDepth,c=r.dilationHeight,h=r.dilationWidth,d=r.effectiveFilterDepth,p=r.effectiveFilterHeight,f=r.effectiveFilterWidth,m=r.padInfo.front,g=r.padInfo.top,y=r.padInfo.left,b="max"===a?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,x=ko(r.outShape,n),w=x.values,k=r.outShape[1]*r.outShape[2]*r.outShape[3]*r.outShape[4],v=r.outShape[2]*r.outShape[3]*r.outShape[4],I=r.outShape[3]*r.outShape[4],S=r.outShape[4];for(let t=0;t<r.batchSize;++t){const n=t*k,x=t*s[0];for(let t=0;t<r.inChannels;++t)for(let k=0;k<r.outDepth;++k){const C=k*i-m;let N=C;for(;N<0;)N+=l;const T=Math.min(r.inDepth,d+C),$=n+k*v;for(let n=0;n<r.outHeight;++n){const i=n*o-g;let d=i;for(;d<0;)d+=c;const m=Math.min(r.inHeight,p+i),k=$+n*I;for(let n=0;n<r.outWidth;++n){const i=n*u-y;let o=i;for(;o<0;)o+=h;const p=Math.min(r.inWidth,f+i),g=k+n*S;let v=b,I=0,C=0;for(let n=N;n<T;n+=l){const r=x+n*s[1];for(let n=d;n<m;n+=c){const i=r+n*s[2];for(let n=o;n<p;n+=h){const r=e[i+n*s[3]+t];if("max"===a&&r>v?v=r:"avg"===a&&(I+=r,C++),isNaN(v))break}if(isNaN(v))break}if(isNaN(v))break}w[g+t]="avg"===a?I/Math.max(C,1):v}}}}return x}const Bq={kernelName:gt,backendName:"cpu",kernelFunc:
|
|
17391
17391
|
/**
|
|
17392
17392
|
* @license
|
|
17393
17393
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17404,7 +17404,7 @@ function Mq(e,t,n,s,r,a){const i=r.strideHeight,o=r.strideWidth,u=r.dilationHeig
|
|
|
17404
17404
|
* limitations under the License.
|
|
17405
17405
|
* =============================================================================
|
|
17406
17406
|
*/
|
|
17407
|
-
function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{filterSize:a,strides:i,pad:o,dimRoundingMode:u}=s;me(Zo(i,1),(()=>`Error in avgPool: Either strides or dilations must be 1. Got strides ${i} and dilations '1'`));const l=Vo(r.shape,a,i,1,o,u);let c;if(1===l.filterWidth&&1===l.filterHeight&&we(l.inShape,l.outShape))c=ay({inputs:{x:r},backend:n});else{const e=n.data.get(r.dataId).values,t=Le(r.shape),s=
|
|
17407
|
+
function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{filterSize:a,strides:i,pad:o,dimRoundingMode:u}=s;me(Zo(i,1),(()=>`Error in avgPool: Either strides or dilations must be 1. Got strides ${i} and dilations '1'`));const l=Vo(r.shape,a,i,1,o,u);let c;if(1===l.filterWidth&&1===l.filterHeight&&we(l.inShape,l.outShape))c=ay({inputs:{x:r},backend:n});else{const e=n.data.get(r.dataId).values,t=Le(r.shape),s=Lq(e,r.shape,r.dtype,t,l,"avg");c=n.makeTensorInfo(l.outShape,r.dtype,s.values)}return c}};
|
|
17408
17408
|
/**
|
|
17409
17409
|
* @license
|
|
17410
17410
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17420,7 +17420,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{fi
|
|
|
17420
17420
|
* See the License for the specific language governing permissions and
|
|
17421
17421
|
* limitations under the License.
|
|
17422
17422
|
* =============================================================================
|
|
17423
|
-
*/const
|
|
17423
|
+
*/const Wq={kernelName:bt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{filterSize:a,strides:i,pad:o,dimRoundingMode:u,dataFormat:l}=s;Jg(r,"avgPool3d");const c=Go(r.shape,a,i,1,o,u,l),h=zq(n.data.get(r.dataId).values,r.shape,r.dtype,Le(r.shape),c,"avg");return n.makeTensorInfo(h.shape,"float32",h.values)}};
|
|
17424
17424
|
/**
|
|
17425
17425
|
* @license
|
|
17426
17426
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17436,7 +17436,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{fi
|
|
|
17436
17436
|
* See the License for the specific language governing permissions and
|
|
17437
17437
|
* limitations under the License.
|
|
17438
17438
|
* =============================================================================
|
|
17439
|
-
*/const
|
|
17439
|
+
*/const Uq={kernelName:xt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{dy:r,input:a}=t,{filterSize:i,strides:o,pad:u,dimRoundingMode:l}=s;Jg([r,a],"avgPool3DGrad");const c=Go(a.shape,i,o,1,u,l),h=c.strideDepth,d=c.strideHeight,p=c.strideWidth,f=c.filterDepth,m=c.filterHeight,g=c.filterWidth,y=c.dilationDepth,b=c.dilationHeight,x=c.dilationWidth,w=c.effectiveFilterDepth,k=c.effectiveFilterHeight,v=c.effectiveFilterWidth,I=w-1-c.padInfo.front,S=v-1-c.padInfo.left,C=k-1-c.padInfo.top,N=ko(a.shape,"float32"),T=1/(f*m*g),$=n.bufferSync(r);for(let e=0;e<c.batchSize;++e)for(let t=0;t<c.inChannels;++t)for(let n=0;n<c.inDepth;++n)for(let s=0;s<c.inHeight;++s)for(let r=0;r<c.inWidth;++r){const a=n-I,i=s-C,o=r-S;let u=0;for(let n=0;n<w;n+=y){const s=(a+n)/h;if(!(s<0||s>=c.outDepth||Math.floor(s)!==s))for(let n=0;n<k;n+=b){const r=(i+n)/d;if(!(r<0||r>=c.outHeight||Math.floor(r)!==r))for(let n=0;n<v;n+=x){const a=(o+n)/p;if(a<0||a>=c.outWidth||Math.floor(a)!==a)continue;u+=$.get(e,s,r,a,t)}}}N.set(u*T,e,n,s,r,t)}return n.makeTensorInfo(N.shape,N.dtype,N.values)}};
|
|
17440
17440
|
/**
|
|
17441
17441
|
* @license
|
|
17442
17442
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17452,7 +17452,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{fi
|
|
|
17452
17452
|
* See the License for the specific language governing permissions and
|
|
17453
17453
|
* limitations under the License.
|
|
17454
17454
|
* =============================================================================
|
|
17455
|
-
*/const
|
|
17455
|
+
*/const Vq={kernelName:yt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{dy:r,input:a}=t,i=a;Jg([r,a],"avgPoolGrad");const{filterSize:o,strides:u,pad:l}=s,c=Vo(i.shape,o,u,1,l),h=c.strideHeight,d=c.strideWidth,p=c.filterHeight,f=c.filterWidth,m=c.dilationHeight,g=c.dilationWidth,y=c.effectiveFilterHeight,b=c.effectiveFilterWidth,x=b-1-c.padInfo.left,w=y-1-c.padInfo.top,k=ko(i.shape,"float32"),v=1/(p*f),I=n.data.get(r.dataId).values,S=ko(r.shape,"float32",I);for(let e=0;e<c.batchSize;++e)for(let t=0;t<c.inChannels;++t)for(let n=0;n<c.inHeight;++n)for(let s=0;s<c.inWidth;++s){const r=n-w,a=s-x;let i=0;for(let n=0;n<y;n+=m){const s=(r+n)/h;if(!(s<0||s>=c.outHeight||Math.floor(s)!==s))for(let n=0;n<b;n+=g){const r=(a+n)/d;if(r<0||r>=c.outWidth||Math.floor(r)!==r)continue;i+=S.get(e,s,r,t)}}k.set(i*v,e,n,s,t)}return n.makeTensorInfo(k.shape,k.dtype,k.values)}};
|
|
17456
17456
|
/**
|
|
17457
17457
|
* @license
|
|
17458
17458
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17468,7 +17468,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{fi
|
|
|
17468
17468
|
* See the License for the specific language governing permissions and
|
|
17469
17469
|
* limitations under the License.
|
|
17470
17470
|
* =============================================================================
|
|
17471
|
-
*/const
|
|
17471
|
+
*/const Gq={kernelName:pn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,scale:a,offset:i,mean:o,variance:u}=t;me(o.shape.length===u.shape.length,(()=>"Batch normalization gradient requires mean and variance to have equal ranks.")),me(null==i||o.shape.length===i.shape.length,(()=>"Batch normalization gradient requires mean and offset to have equal ranks.")),me(null==a||o.shape.length===a.shape.length,(()=>"Batch normalization gradient requires mean and scale to have equal ranks.")),Jg([r,o,u,a,i],"batchNorm");let{varianceEpsilon:l}=s;null==l&&(l=.001);const c=n.data.get(r.dataId).values,h=n.data.get(o.dataId).values,d=n.data.get(u.dataId).values,p=a?n.data.get(a.dataId).values:new Float32Array([1]),f=i?n.data.get(i.dataId).values:new Float32Array([0]),m=new Float32Array(c.length),g=f.length,y=p.length,b=d.length,x=h.length;let w=0,k=0,v=0,I=0;for(let e=0;e<c.length;++e)m[e]=f[w++]+(c[e]-h[k++])*p[v++]/Math.sqrt(d[I++]+l),w>=g&&(w=0),k>=x&&(k=0),v>=y&&(v=0),I>=b&&(I=0);return n.makeTensorInfo(r.shape,r.dtype,m)}};
|
|
17472
17472
|
/**
|
|
17473
17473
|
* @license
|
|
17474
17474
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17484,7 +17484,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{fi
|
|
|
17484
17484
|
* See the License for the specific language governing permissions and
|
|
17485
17485
|
* limitations under the License.
|
|
17486
17486
|
* =============================================================================
|
|
17487
|
-
*/const
|
|
17487
|
+
*/const Hq={kernelName:kt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,crops:i}=s;Jg([r],"batchToSpaceND");const o=a.reduce(((e,t)=>e*t)),u=Af(r.shape,a,o),l=_f(u.length,a.length),c=Ff(r.shape,a,o),h=Df(i,a.length),d=Mf(c,i,a.length),p=dq({inputs:{x:r},backend:n,attrs:{shape:u}}),f=Nb({inputs:{x:p},backend:n,attrs:{perm:l}}),m=dq({inputs:{x:f},backend:n,attrs:{shape:c}}),g=Yb({inputs:{x:m},backend:n,attrs:{begin:h,size:d}});return n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(f),n.disposeIntermediateTensorInfo(m),g}};
|
|
17488
17488
|
/**
|
|
17489
17489
|
* @license
|
|
17490
17490
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17500,7 +17500,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{fi
|
|
|
17500
17500
|
* See the License for the specific language governing permissions and
|
|
17501
17501
|
* limitations under the License.
|
|
17502
17502
|
* =============================================================================
|
|
17503
|
-
*/const
|
|
17503
|
+
*/const qq={kernelName:vt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,weights:a}=t,{size:i}=s,o=by(n.data.get(r.dataId).values,n.data.get(a.dataId).values,a.dtype,a.shape,i);return n.makeTensorInfo([i],a.dtype,o)}};
|
|
17504
17504
|
/**
|
|
17505
17505
|
* @license
|
|
17506
17506
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -17516,7 +17516,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{fi
|
|
|
17516
17516
|
* See the License for the specific language governing permissions and
|
|
17517
17517
|
* limitations under the License.
|
|
17518
17518
|
* =============================================================================
|
|
17519
|
-
*/const
|
|
17519
|
+
*/const jq={kernelName:St,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{s0:s,s1:r}=t,a=n.data.get(s.dataId).values,i=n.data.get(r.dataId).values,o=qu(Array.from(a),Array.from(i));return n.makeTensorInfo([o.length],"int32",Int32Array.from(o))}},Xq=Sy(Tt,((e,t)=>{const n=t;return e>n.clipValueMax?n.clipValueMax:e<n.clipValueMin?n.clipValueMin:e})),Kq={kernelName:Tt,backendName:"cpu",kernelFunc:Xq},Yq={kernelName:Rt,backendName:"cpu",kernelFunc:e=>{const{x:t}=e.inputs,n=e.backend,s=new Float32Array(be(t.shape)),r=n.data.get(t.dataId),a=r.complexTensorInfos.real,i=r.complexTensorInfos.imag,o=n.data.get(a.dataId).values,u=n.data.get(i.dataId).values;for(let e=0;e<o.length;e++){const t=o[e],n=u[e];s[e]=Math.hypot(t,n)}return n.makeOutput(s,t.shape,"float32")}};
|
|
17520
17520
|
/**
|
|
17521
17521
|
* @license
|
|
17522
17522
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17549,7 +17549,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"avgPool");const{fi
|
|
|
17549
17549
|
* limitations under the License.
|
|
17550
17550
|
* =============================================================================
|
|
17551
17551
|
*/
|
|
17552
|
-
function
|
|
17552
|
+
function Qq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).complexTensorInfos.imag,a=n.data.get(r.dataId).values;return n.makeTensorInfo(r.shape,r.dtype,a)}const Jq={kernelName:wn,backendName:"cpu",kernelFunc:Qq};
|
|
17553
17553
|
/**
|
|
17554
17554
|
* @license
|
|
17555
17555
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17565,7 +17565,7 @@ function Kq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).co
|
|
|
17565
17565
|
* See the License for the specific language governing permissions and
|
|
17566
17566
|
* limitations under the License.
|
|
17567
17567
|
* =============================================================================
|
|
17568
|
-
*/function
|
|
17568
|
+
*/function Zq(e){const{inputs:t,backend:n,attrs:s}=e,{axis:r}=s,a=Ne(r,t[0].shape)[0],i=t.map((e=>e.shape));kf(i,a);let o=vf(t.map((e=>e.shape)),a);if(0===be(o))return n.makeTensorInfo(o,t[0].dtype,[]);const u=t.filter((e=>be(e.shape)>0));if(1===u.length)return ay({inputs:{x:u[0]},backend:n});if("complex64"===u[0].dtype){const e=u.map((e=>oy({inputs:{input:e},backend:n}))),t=u.map((e=>Qq({inputs:{input:e},backend:n}))),s=Zq({inputs:e,backend:n,attrs:{axis:a}}),r=Zq({inputs:t,backend:n,attrs:{axis:a}}),i=ny({inputs:{real:s,imag:r},backend:n});return e.forEach((e=>n.disposeIntermediateTensorInfo(e))),t.forEach((e=>n.disposeIntermediateTensorInfo(e))),n.disposeIntermediateTensorInfo(s),n.disposeIntermediateTensorInfo(r),i}const l=u.map((e=>{const t=be(e.shape.slice(a));return dq({inputs:{x:e},backend:n,attrs:{shape:[-1,t]}})})),c=l.map((e=>({vals:n.data.get(e.dataId).values,shape:e.shape})));o=vf(l.map((e=>e.shape)),1);const h=1===l[0].shape[0],d=Ry(c,o,t[0].dtype,h),p=vf(u.map((e=>e.shape)),a),f=n.makeTensorInfo(p,t[0].dtype,d);return l.forEach((e=>n.disposeIntermediateTensorInfo(e))),f}const ej={kernelName:Et,backendName:"cpu",kernelFunc:Zq};
|
|
17569
17569
|
/**
|
|
17570
17570
|
* @license
|
|
17571
17571
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17581,7 +17581,7 @@ function Kq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).co
|
|
|
17581
17581
|
* See the License for the specific language governing permissions and
|
|
17582
17582
|
* limitations under the License.
|
|
17583
17583
|
* =============================================================================
|
|
17584
|
-
*/function
|
|
17584
|
+
*/function tj(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,filter:a}=t,{strides:i,pad:o,dataFormat:u,dilations:l,dimRoundingMode:c}=s;Jg([r,a],"conv2d");const h=tu(u),d=Ho(r.shape,a.shape,i,l,o,c,!1,h),p=d.filterHeight,f=d.filterWidth,m=d.dilationHeight,g=d.dilationWidth,y=d.padInfo.left,b=d.padInfo.top,x="channelsLast"===d.dataFormat,w=new Ra(d.outShape,r.dtype),k=Le(r.shape),v=Le(a.shape),I=k[0],S=x?k[1]:k[2],C=x?k[2]:1,N=x?1:k[1],T=w.strides[0],$=x?w.strides[1]:w.strides[2],R=x?w.strides[2]:1,E=x?1:w.strides[1],A=n.data.get(r.dataId).values,_=n.data.get(a.dataId).values,F=w.values;for(let e=0;e<d.batchSize;++e){const t=e*I,n=e*T;for(let e=0;e<d.outHeight;++e){const s=n+e*$,r=e*d.strideHeight-b;for(let e=0;e<p;++e){const n=r+e*m;if(n<0||n>=d.inHeight)continue;const a=e*v[0],i=t+n*S;for(let e=0;e<d.outWidth;++e){const t=s+e*R,n=e*d.strideWidth-y;for(let e=0;e<f;++e){const s=n+e*g;if(s<0||s>=d.inWidth)continue;const r=i+s*C;let o=a+e*v[1];for(let e=0;e<d.inChannels;++e){const n=A[r+e*N];for(let e=0;e<d.outChannels;++e)F[t+e*E]+=n*_[o+e];o+=d.outChannels}}}}}}return n.makeTensorInfo(w.shape,w.dtype,F)}const nj={kernelName:At,backendName:"cpu",kernelFunc:tj};
|
|
17585
17585
|
/**
|
|
17586
17586
|
* @license
|
|
17587
17587
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17597,7 +17597,7 @@ function Kq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).co
|
|
|
17597
17597
|
* See the License for the specific language governing permissions and
|
|
17598
17598
|
* limitations under the License.
|
|
17599
17599
|
* =============================================================================
|
|
17600
|
-
*/const
|
|
17600
|
+
*/const sj={kernelName:_t,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,dy:a}=t,{strides:i,pad:o,dataFormat:u,dimRoundingMode:l,filterShape:c}=s;Jg([r,a],"conv2dBackpropFilter");const h=tu(u),d=Ho(r.shape,c,i,1,o,l,!1,h),{strideHeight:p,strideWidth:f,filterHeight:m,filterWidth:g}=d,y="channelsLast"===d.dataFormat,b=new Ra(d.filterShape,"float32"),x=d.padInfo.left,w=d.padInfo.top,k=n.data.get(r.dataId).values,v=n.data.get(a.dataId).values,I=new Ra(r.shape,r.dtype,k),S=new Ra(a.shape,a.dtype,v);for(let e=0;e<m;++e){const t=Math.max(0,Math.ceil((w-e)/p)),n=Math.min(d.outHeight,(d.inHeight+w-e)/p);for(let s=0;s<g;++s){const r=Math.max(0,Math.ceil((x-s)/f)),a=Math.min(d.outWidth,(d.inWidth+x-s)/f);for(let i=0;i<d.inChannels;++i)for(let o=0;o<d.outChannels;++o){let u=0;for(let l=0;l<d.batchSize;++l)for(let c=t;c<n;++c){const t=e+c*p-w;for(let e=r;e<a;++e){const n=s+e*f-x;u+=y?I.get(l,t,n,i)*S.get(l,c,e,o):I.get(l,i,t,n)*S.get(l,o,c,e)}}b.set(u,e,s,i,o)}}}return n.makeTensorInfo(b.shape,b.dtype,b.values)}};
|
|
17601
17601
|
/**
|
|
17602
17602
|
* @license
|
|
17603
17603
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17613,7 +17613,7 @@ function Kq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).co
|
|
|
17613
17613
|
* See the License for the specific language governing permissions and
|
|
17614
17614
|
* limitations under the License.
|
|
17615
17615
|
* =============================================================================
|
|
17616
|
-
*/const
|
|
17616
|
+
*/const rj={kernelName:Ft,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{dy:r,filter:a}=t,{inputShape:i,strides:o,pad:u,dataFormat:l,dimRoundingMode:c}=s;Jg([r,a],"conv2dBackpropInput");const h=Le(a.shape),d=Le(r.shape);let p=tu(l);const f=Ho(i,a.shape,o,1,u,c,!1,p),m=new Ra(f.inShape,"float32"),g=m.values,y=n.data.get(r.dataId).values,b=n.data.get(a.dataId).values,[x,w,k]=h,{batchSize:v,filterHeight:I,filterWidth:S,inChannels:C,inHeight:N,inWidth:T,outChannels:$,outHeight:R,outWidth:E,strideHeight:A,strideWidth:_}=f;p=f.dataFormat;const F=I-1-f.padInfo.top,D=S-1-f.padInfo.left,M="channelsLast"===p,O=m.strides[0],L=M?m.strides[1]:m.strides[2],P=M?m.strides[2]:1,z=M?1:m.strides[1],B=d[0],W=M?d[1]:d[2],U=M?d[2]:1,V=M?1:d[1];for(let e=0;e<v;++e)for(let t=0;t<C;++t)for(let n=0;n<N;++n){const s=n-F,r=Math.max(0,Math.ceil(s/A)),a=Math.min(R,(I+s)/A);for(let i=0;i<T;++i){const o=i-D,u=Math.max(0,Math.ceil(o/_)),l=Math.min(E,(S+o)/_);let c=0;for(let n=r;n<a;++n){const r=n*A-s;for(let s=u;s<l;++s){const a=B*e+W*n+U*s,i=x*(I-1-r)+w*(S-1-(s*_-o))+k*t;for(let e=0;e<$;++e){c+=y[a+V*e]*b[i+e]}}}g[O*e+L*n+P*i+z*t]=c}}return n.makeTensorInfo(m.shape,m.dtype,m.values)}};
|
|
17617
17617
|
/**
|
|
17618
17618
|
* @license
|
|
17619
17619
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17629,7 +17629,7 @@ function Kq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).co
|
|
|
17629
17629
|
* See the License for the specific language governing permissions and
|
|
17630
17630
|
* limitations under the License.
|
|
17631
17631
|
* =============================================================================
|
|
17632
|
-
*/const
|
|
17632
|
+
*/const aj={kernelName:Dt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,filter:a}=t,{strides:i,pad:o,dilations:u}=s;Jg([r,a],"conv3d");const l=qo(r.shape,a.shape,i,u,o),{filterDepth:c,filterHeight:h,filterWidth:d,dilationDepth:p,dilationHeight:f,dilationWidth:m,padInfo:g}=l,y=g.front,b=g.left,x=g.top,w=new Ra(l.outShape,r.dtype),k=n.data.get(r.dataId).values,v=n.data.get(a.dataId).values,I=w.values,S=Le(r.shape),C=Le(a.shape);for(let e=0;e<l.batchSize;++e){const t=e*S[0],n=e*w.strides[0];for(let e=0;e<l.outDepth;++e){const s=n+e*w.strides[1],r=e*l.strideDepth-y;for(let e=0;e<c;++e){const n=r+e*p;if(n<0||n>=l.inDepth)continue;const a=e*C[0],i=t+n*S[1];for(let e=0;e<l.outHeight;++e){const t=s+e*w.strides[2],n=e*l.strideHeight-x;for(let e=0;e<h;++e){const s=n+e*f;if(s<0||s>=l.inHeight)continue;const r=a+e*C[1],o=i+s*S[2];for(let e=0;e<l.outWidth;++e){const n=t+e*l.outChannels,s=e*l.strideWidth-b;for(let e=0;e<d;++e){const t=s+e*m;if(t<0||t>=l.inWidth)continue;const a=r+e*C[2],i=o+t*l.inChannels;let u=a;for(let e=0;e<l.inChannels;++e){const t=k[i+e];for(let e=0;e<l.outChannels;++e)I[n+e]+=t*v[u+e];u+=l.outChannels}}}}}}}}return n.makeTensorInfo(w.shape,w.dtype,w.values)}};
|
|
17633
17633
|
/**
|
|
17634
17634
|
* @license
|
|
17635
17635
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17645,7 +17645,7 @@ function Kq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).co
|
|
|
17645
17645
|
* See the License for the specific language governing permissions and
|
|
17646
17646
|
* limitations under the License.
|
|
17647
17647
|
* =============================================================================
|
|
17648
|
-
*/const
|
|
17648
|
+
*/const ij={kernelName:Mt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,dy:a}=t,{strides:i,pad:o,filterShape:u}=s;Jg([r,a],"conv3dBackpropFilterV2");const l=Le(r.shape),c=Le(a.shape),h=qo(r.shape,u,i,1,o),d=h.strideDepth,p=h.strideHeight,f=h.strideWidth,m=h.filterDepth,g=h.filterHeight,y=h.filterWidth,b=new Ra(h.filterShape,"float32"),x=b.values,[w,k,v,I]=b.strides,S=n.data.get(a.dataId).values,[C,N,T,$]=c,R=n.data.get(r.dataId).values,[E,A,_,F]=l,D=h.padInfo.front,M=h.padInfo.left,O=h.padInfo.top;for(let e=0;e<m;++e){const t=Math.max(0,Math.ceil((D-e)/d)),n=Math.min(h.outDepth,(h.inDepth+D-e)/d),s=e*w;for(let r=0;r<g;++r){const a=Math.max(0,Math.ceil((O-r)/p)),i=Math.min(h.outHeight,(h.inHeight+O-r)/p),o=r*k+s;for(let s=0;s<y;++s){const u=Math.max(0,Math.ceil((M-s)/f)),l=Math.min(h.outWidth,(h.inWidth+M-s)/f),c=s*v+o;for(let o=0;o<h.inChannels;++o){const m=o*I+c;for(let c=0;c<h.outChannels;++c){let g=0;for(let m=0;m<h.batchSize;++m){const h=m*E,y=m*C;for(let m=t;m<n;++m){const t=(e+m*d-D)*A+h,n=m*N+y;for(let e=a;e<i;++e){const a=(r+e*p-O)*_+t,i=e*T+n;for(let e=u;e<l;++e){const t=e*$+i;g+=R[(s+e*f-M)*F+a+o]*S[t+c]}}}}x[m+c]=g}}}}}return n.makeTensorInfo(b.shape,b.dtype,b.values)}};
|
|
17649
17649
|
/**
|
|
17650
17650
|
* @license
|
|
17651
17651
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17661,7 +17661,7 @@ function Kq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).co
|
|
|
17661
17661
|
* See the License for the specific language governing permissions and
|
|
17662
17662
|
* limitations under the License.
|
|
17663
17663
|
* =============================================================================
|
|
17664
|
-
*/const
|
|
17664
|
+
*/const oj={kernelName:Ot,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{dy:r,filter:a}=t,{pad:i,strides:o,inputShape:u}=s;Jg([r],"conv3dBackpropInputV2");const l=Le(r.shape),c=Le(a.shape),h=qo(u,a.shape,o,1,i),d=new Ra(h.inShape,"float32"),p=d.values,[f,m,g,y]=d.strides,b=n.data.get(r.dataId).values,[x,w,k,v]=l,I=n.data.get(a.dataId).values,[S,C,N,T]=c,{batchSize:$,filterDepth:R,filterHeight:E,filterWidth:A,inChannels:_,inDepth:F,inHeight:D,inWidth:M,outChannels:O,outDepth:L,outHeight:P,outWidth:z,strideDepth:B,strideHeight:W,strideWidth:U}=h,V=R-1-h.padInfo.front,G=E-1-h.padInfo.top,H=A-1-h.padInfo.left;for(let e=0;e<$;++e)for(let t=0;t<_;++t)for(let n=0;n<F;++n){const s=n-V,r=Math.max(0,Math.ceil(s/B)),a=Math.min(L,(R+s)/B);for(let i=0;i<D;++i){const o=i-G,u=Math.max(0,Math.ceil(o/W)),l=Math.min(P,(E+o)/W);for(let c=0;c<M;++c){const h=c-H,d=Math.max(0,Math.ceil(h/U)),$=Math.min(z,(A+h)/U);let _=0;for(let n=r;n<a;++n){const r=n*B-s;for(let s=u;s<l;++s){const a=s*W-o;for(let i=d;i<$;++i){const o=x*e+w*n+k*s+v*i,u=S*(R-1-r)+C*(E-1-a)+N*(A-1-(i*U-h))+T*t;for(let e=0;e<O;++e){_+=b[o+e]*I[u+e]}}}}p[f*e+m*n+g*i+y*c+t]=_}}}return n.makeTensorInfo(d.shape,d.dtype,d.values)}},uj=Sy(Lt,(e=>Math.cos(e))),lj={kernelName:Lt,backendName:"cpu",kernelFunc:uj},cj=Sy(Pt,(e=>Math.cosh(e))),hj={kernelName:Pt,backendName:"cpu",kernelFunc:cj};
|
|
17665
17665
|
/**
|
|
17666
17666
|
* @license
|
|
17667
17667
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17677,7 +17677,7 @@ function Kq(e){const{inputs:t,backend:n}=e,{input:s}=t,r=n.data.get(s.dataId).co
|
|
|
17677
17677
|
* See the License for the specific language governing permissions and
|
|
17678
17678
|
* limitations under the License.
|
|
17679
17679
|
* =============================================================================
|
|
17680
|
-
*/const
|
|
17680
|
+
*/const dj={kernelName:Wt,backendName:"cpu",kernelFunc:
|
|
17681
17681
|
/**
|
|
17682
17682
|
* @license
|
|
17683
17683
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17710,7 +17710,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17710
17710
|
* See the License for the specific language governing permissions and
|
|
17711
17711
|
* limitations under the License.
|
|
17712
17712
|
* =============================================================================
|
|
17713
|
-
*/const
|
|
17713
|
+
*/const pj={kernelName:zt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a,exclusive:i,reverse:o}=s;Jg(r,"cumprod");const u=ol([a],r.shape.length);let l=r;null!=u&&(l=Nb({inputs:{x:r},backend:n,attrs:{perm:u}}));const c=ll(1,r.shape.length)[0];if(c!==l.shape.length-1)throw new Error(`backend.cumprod in CPU expects an inner-most axis=${l.shape.length-1} but got axis=${c}`);const h=Wa(l.dtype,"int32"),d=We(be(l.shape),h),p=n.data.get(l.dataId).values,f=l.shape[l.shape.length-1],m=o?(e,t)=>e+f-t-1:(e,t)=>e+t;for(let e=0;e<p.length;e+=f)for(let t=0;t<f;t++){const n=m(e,t);if(0===t)d[n]=i?1:p[n];else{const s=m(e,t-1);d[n]=i?p[s]*d[s]:p[n]*d[s]}}const g=n.makeTensorInfo(l.shape,h,d);if(null!=u){const e=Nb({inputs:{x:g},backend:n,attrs:{perm:ul(u)}});return n.disposeIntermediateTensorInfo(g),n.disposeIntermediateTensorInfo(l),e}return g}};
|
|
17714
17714
|
/**
|
|
17715
17715
|
* @license
|
|
17716
17716
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17726,7 +17726,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17726
17726
|
* See the License for the specific language governing permissions and
|
|
17727
17727
|
* limitations under the License.
|
|
17728
17728
|
* =============================================================================
|
|
17729
|
-
*/const
|
|
17729
|
+
*/const fj={kernelName:Bt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a,exclusive:i,reverse:o}=s;Jg(r,"cumsum");const u=ol([a],r.shape.length);let l=r;null!=u&&(l=Nb({inputs:{x:r},backend:n,attrs:{perm:u}}));const c=ll(1,r.shape.length)[0];if(c!==l.shape.length-1)throw new Error(`backend.cumsum in CPU expects an inner-most axis=${l.shape.length-1} but got axis=${c}`);const h=Wa(l.dtype,"int32"),d=Ue(be(l.shape),h),p=n.data.get(l.dataId).values,f=l.shape[l.shape.length-1],m=o?(e,t)=>e+f-t-1:(e,t)=>e+t;for(let e=0;e<p.length;e+=f)for(let t=0;t<f;t++){const n=m(e,t);if(0===t)d[n]=i?0:p[n];else{const s=m(e,t-1);d[n]=i?p[s]+d[s]:p[n]+d[s]}}const g=n.makeTensorInfo(l.shape,h,d);if(null!=u){const e=Nb({inputs:{x:g},backend:n,attrs:{perm:ul(u)}});return n.disposeIntermediateTensorInfo(g),n.disposeIntermediateTensorInfo(l),e}return g}};
|
|
17730
17730
|
/**
|
|
17731
17731
|
* @license
|
|
17732
17732
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17742,7 +17742,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17742
17742
|
* See the License for the specific language governing permissions and
|
|
17743
17743
|
* limitations under the License.
|
|
17744
17744
|
* =============================================================================
|
|
17745
|
-
*/const
|
|
17745
|
+
*/const mj={kernelName:Ut,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,weights:a}=t,{size:i,binaryOutput:o}=s;if(1===r.shape.length){const e=by(n.data.get(r.dataId).values,n.data.get(a.dataId).values,a.dtype,a.shape,i);return n.makeTensorInfo([i],a.dtype,e)}if(2===r.shape.length){const e=xy(n.bufferSync(r),n.bufferSync(a),i,o);return n.makeTensorInfo(e.shape,a.dtype,e.values)}throw new Error(`Error in denseBincount: input must be at most rank 2, but got rank${r.shape.length}.`)}};
|
|
17746
17746
|
/**
|
|
17747
17747
|
* @license
|
|
17748
17748
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17758,7 +17758,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17758
17758
|
* See the License for the specific language governing permissions and
|
|
17759
17759
|
* limitations under the License.
|
|
17760
17760
|
* =============================================================================
|
|
17761
|
-
*/const
|
|
17761
|
+
*/const gj={kernelName:Vt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockSize:a,dataFormat:i}=s;me("NHWC"===i,(()=>`Only NHWC dataFormat supported on CPU for depthToSpace. Got ${i}`));const o=r.shape[0],u=r.shape[1],l=r.shape[2],c=r.shape[3],h=u*a,d=l*a,p=c/(a*a),f=n.data.get(r.dataId).values,m=new Float32Array(o*h*d*p);let g=0;for(let e=0;e<o;++e)for(let t=0;t<h;++t){const n=Math.floor(t/a),s=t%a;for(let t=0;t<d;++t){const r=Math.floor(t/a),i=(s*a+t%a)*p;for(let t=0;t<p;++t){const s=t+i+c*(r+l*(n+u*e));m[g++]=f[s]}}}return n.makeTensorInfo([o,h,d,p],r.dtype,m)}};
|
|
17762
17762
|
/**
|
|
17763
17763
|
* @license
|
|
17764
17764
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17774,7 +17774,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17774
17774
|
* See the License for the specific language governing permissions and
|
|
17775
17775
|
* limitations under the License.
|
|
17776
17776
|
* =============================================================================
|
|
17777
|
-
*/function
|
|
17777
|
+
*/function yj(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,filter:a}=t,{strides:i,pad:o,dilations:u,dimRoundingMode:l}=s;Jg([r,a],"depthwiseConv2DNative");const c=Le(r.shape),h=Le(a.shape);let d=u;null==d&&(d=[1,1]),me(Zo(i,d),(()=>`Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides ${i} and dilations '${d}'`));const p=Ho(r.shape,a.shape,i,d,o,l,!0),{filterHeight:f,filterWidth:m,dilationHeight:g,dilationWidth:y,padInfo:b}=p,x=b.left,w=b.top,k=p.outChannels/p.inChannels,v=new Ra(p.outShape,r.dtype),I=n.data.get(r.dataId).values,S=n.data.get(a.dataId).values,C=v.values;for(let e=0;e<p.batchSize;++e){const t=e*c[0],n=e*v.strides[0];for(let e=0;e<p.outHeight;++e){const s=n+e*v.strides[1],r=e*p.strideHeight-w;for(let e=0;e<f;++e){const n=r+e*g;if(n<0||n>=p.inHeight)continue;const a=e*h[0],i=t+n*c[1];for(let e=0;e<p.outWidth;++e){const t=s+e*v.strides[2],n=e*p.strideWidth-x;for(let e=0;e<m;++e){const s=n+e*y;if(s<0||s>=p.inWidth)continue;const r=a+e*h[1],o=i+s*p.inChannels;let u=t,l=r;for(let e=0;e<p.inChannels;++e){const t=I[o+e];for(let e=0;e<k;++e)C[u+e]+=t*S[l+e];u+=k,l+=k}}}}}}return n.makeTensorInfo(v.shape,v.dtype,v.values)}const bj={kernelName:Gt,backendName:"cpu",kernelFunc:yj};
|
|
17778
17778
|
/**
|
|
17779
17779
|
* @license
|
|
17780
17780
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17790,7 +17790,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17790
17790
|
* See the License for the specific language governing permissions and
|
|
17791
17791
|
* limitations under the License.
|
|
17792
17792
|
* =============================================================================
|
|
17793
|
-
*/const
|
|
17793
|
+
*/const xj={kernelName:Ht,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,dy:a}=t,{strides:i,dilations:o,pad:u,dimRoundingMode:l,filterShape:c}=s;Jg([r,a],"depthwiseConv2dNativeBackpropFilter");const h=Ho(r.shape,c,i,o,u,l,!0),{strideHeight:d,strideWidth:p,filterHeight:f,filterWidth:m}=h,g=new Ra(h.filterShape,"float32"),y=h.padInfo.left,b=h.padInfo.top,x=h.outChannels/h.inChannels,w=n.data.get(r.dataId).values,k=new Ra(r.shape,r.dtype,w),v=n.data.get(a.dataId).values,I=new Ra(a.shape,a.dtype,v);for(let e=0;e<f;++e){const t=Math.max(0,Math.ceil((b-e)/d)),n=Math.min(h.outHeight,(h.inHeight+b-e)/d);for(let s=0;s<m;++s){const r=Math.max(0,Math.ceil((y-s)/p)),a=Math.min(h.outWidth,(h.inWidth+y-s)/p);for(let i=0;i<h.outChannels;++i){const o=Math.trunc(i/x),u=i%x;let l=0;for(let u=0;u<h.batchSize;++u)for(let c=t;c<n;++c){const t=e+c*d-b;for(let e=r;e<a;++e){const n=s+e*p-y;l+=k.get(u,t,n,o)*I.get(u,c,e,i)}}g.set(l,e,s,o,u)}}}return n.makeTensorInfo(g.shape,g.dtype,g.values)}};
|
|
17794
17794
|
/**
|
|
17795
17795
|
* @license
|
|
17796
17796
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17806,7 +17806,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17806
17806
|
* See the License for the specific language governing permissions and
|
|
17807
17807
|
* limitations under the License.
|
|
17808
17808
|
* =============================================================================
|
|
17809
|
-
*/const
|
|
17809
|
+
*/const wj={kernelName:qt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{dy:r,filter:a}=t,{strides:i,dilations:o,pad:u,dimRoundingMode:l,inputShape:c}=s;Jg([r,a],"depthwiseConv2DNativeBackpropInput");const h=Le(r.shape),d=Le(a.shape),p=Ho(c,a.shape,i,o,u,l,!0),f=new Ra(p.inShape,"float32"),m=f.values,[g,y,b]=f.strides,x=n.data.get(r.dataId).values,[w,k,v]=h,I=n.data.get(a.dataId).values,[S,C,N]=d,{batchSize:T,filterHeight:$,filterWidth:R,inChannels:E,inHeight:A,inWidth:_,outChannels:F,outHeight:D,outWidth:M,strideHeight:O,strideWidth:L}=p,P=$-1-p.padInfo.top,z=R-1-p.padInfo.left,B=F/E;for(let e=0;e<T;++e)for(let t=0;t<E;++t)for(let n=0;n<A;++n){const s=n-P,r=Math.max(0,Math.ceil(s/O)),a=Math.min(D,($+s)/O);for(let i=0;i<_;++i){const o=i-z,u=Math.max(0,Math.ceil(o/L)),l=Math.min(M,(R+o)/L);let c=0;for(let n=r;n<a;++n){const r=n*O-s;for(let s=u;s<l;++s){const a=w*e+k*n+v*s,i=S*($-1-r)+C*(R-1-(s*L-o))+N*t;for(let e=0;e<B;++e){c+=x[a+(t*B+e)]*I[i+e]}}}m[g*e+y*n+b*i+t]=c}}return n.makeTensorInfo(f.shape,f.dtype,f.values)}};
|
|
17810
17810
|
/**
|
|
17811
17811
|
* @license
|
|
17812
17812
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17822,7 +17822,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17822
17822
|
* See the License for the specific language governing permissions and
|
|
17823
17823
|
* limitations under the License.
|
|
17824
17824
|
* =============================================================================
|
|
17825
|
-
*/const
|
|
17825
|
+
*/const kj={kernelName:jt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{x:s}=t,r=be(s.shape),a=n.data.get(s.dataId).values,i=ko([r,r],s.dtype),o=i.values;for(let e=0;e<a.length;e++)o[e*r+e]=a[e];const u=[...s.shape,...s.shape];return n.makeTensorInfo(u,i.dtype,i.values)}},vj={kernelName:Xt,backendName:"cpu",kernelFunc:({inputs:e,backend:t,attrs:n})=>{const{x:s,filter:r}=e,{strides:a,pad:i,dilations:o}=n,u=t,l=u.data.get(s.dataId).values,c=s.shape.length,h=u.data.get(r.dataId).values,d=r.shape.length,{batchSize:p,inHeight:f,inWidth:m,inChannels:g,outHeight:y,outWidth:b,padInfo:x,strideHeight:w,strideWidth:k,filterHeight:v,filterWidth:I,dilationHeight:S,dilationWidth:C,outShape:N}=Uo(s.shape,r.shape,a,i,"NHWC",o),T=be(N),$=N.length,R=Re(s.dtype,T);for(let e=0;e<p;++e)for(let t=0;t<y;++t){const n=t*w-x.top;for(let a=0;a<b;++a){const i=a*k-x.left;for(let o=0;o<g;++o){let u=Number.MIN_SAFE_INTEGER;for(let t=0;t<v;++t){const a=n+t*S;if(a>=0&&a<f)for(let n=0;n<I;++n){const p=i+n*C;if(p>=0&&p<m){const i=He([e,a,p,o],c,Le(s.shape)),f=He([t,n,o],d,Le(r.shape)),m=l[i]+h[f];m>u&&(u=m)}}}R[He([e,t,a,o],$,Le(N))]=u}}}return{dataId:u.write(da(R,s.dtype),N,s.dtype),shape:N,dtype:s.dtype}}},Ij={kernelName:Yt,backendName:"cpu",kernelFunc:({inputs:e,backend:t,attrs:n})=>{const{x:s,filter:r,dy:a}=e,{strides:i,pad:o,dilations:u}=n,l=t,c=ze(s.shape,l.data.get(s.dataId).values),h=ze(r.shape,l.data.get(r.dataId).values),{batchSize:d,inHeight:p,inWidth:f,inChannels:m,outHeight:g,outWidth:y,padInfo:b,strideHeight:x,strideWidth:w,filterHeight:k,filterWidth:v,dilationHeight:I,dilationWidth:S,outShape:C}=Uo(s.shape,r.shape,i,o,"NHWC",u);me(a.rank===C.length,(()=>`Error in ${Yt}, dy must have the same rank as output ${C.length}, but got ${a.rank}`));const N=ze(C,l.data.get(a.dataId).values),T=Ve(r.shape,r.dtype);for(let e=0;e<d;++e)for(let t=0;t<g;++t){const n=t*x-b.top;for(let s=0;s<y;++s){const r=s*w-b.left;for(let a=0;a<m;++a){let i=Number.MIN_SAFE_INTEGER,o=0,u=0;for(let t=0;t<k;++t){const s=n+t*I;if(s>=0&&s<p)for(let n=0;n<v;++n){const l=r+n*S;if(l>=0&&l<f){const r=c[e][s][l][a]+h[t][n][a];r>i&&(i=r,o=t,u=n)}}}T[o][u][a]+=N[e][t][s][a]}}}return{dataId:l.write(da(T,s.dtype),r.shape,r.dtype),shape:r.shape,dtype:r.dtype}}},Sj={kernelName:Kt,backendName:"cpu",kernelFunc:({inputs:e,backend:t,attrs:n})=>{const{x:s,filter:r,dy:a}=e,{strides:i,pad:o,dilations:u}=n,l=t,c=ze(s.shape,l.data.get(s.dataId).values),h=ze(r.shape,l.data.get(r.dataId).values),{batchSize:d,inHeight:p,inWidth:f,inChannels:m,outHeight:g,outWidth:y,padInfo:b,strideHeight:x,strideWidth:w,filterHeight:k,filterWidth:v,dilationHeight:I,dilationWidth:S,outShape:C}=Uo(s.shape,r.shape,i,o,"NHWC",u);me(a.rank===C.length,(()=>`Error in ${Kt}, dy must have the same rank as output ${C.length}, but got ${a.rank}`));const N=ze(C,l.data.get(a.dataId).values),T=Ve(s.shape,s.dtype);for(let e=0;e<d;++e)for(let t=0;t<g;++t){const n=t*x-b.top;for(let s=0;s<y;++s){const r=s*w-b.left;for(let a=0;a<m;++a){let i=Number.MIN_SAFE_INTEGER,o=n<0?0:n,u=r<0?0:r;for(let t=0;t<k;++t){const s=n+t*I;if(s>=0&&s<p)for(let n=0;n<v;++n){const l=r+n*S;if(l>=0&&l<f){const r=c[e][s][l][a]+h[t][n][a];r>i&&(i=r,o=s,u=l)}}}T[e][o][u][a]+=N[e][t][s][a]}}}return{dataId:l.write(da(T,s.dtype),s.shape,s.dtype),shape:s.shape,dtype:s.dtype}}};
|
|
17826
17826
|
/**
|
|
17827
17827
|
* @license
|
|
17828
17828
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17838,7 +17838,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r,boxes:a,boxInd:i}=t,{cr
|
|
|
17838
17838
|
* See the License for the specific language governing permissions and
|
|
17839
17839
|
* limitations under the License.
|
|
17840
17840
|
* =============================================================================
|
|
17841
|
-
*/const
|
|
17841
|
+
*/const Cj={kernelName:Qt,backendName:"cpu",kernelFunc:
|
|
17842
17842
|
/**
|
|
17843
17843
|
* @license
|
|
17844
17844
|
* Copyright 2023 Google LLC.
|
|
@@ -17871,7 +17871,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r}=t,{canvas:a,options:i}
|
|
|
17871
17871
|
* See the License for the specific language governing permissions and
|
|
17872
17872
|
* limitations under the License.
|
|
17873
17873
|
* =============================================================================
|
|
17874
|
-
*/function
|
|
17874
|
+
*/function Nj(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a,keepDims:i}=s;let o;Jg(r,"sum"),o="bool"===r.dtype?cy({inputs:{x:r},backend:n,attrs:{dtype:"int32"}}):ay({inputs:{x:r},backend:n});const u=o.shape.length,l=Ne(a,o.shape),c=ol(l,u);let h=l,d=o;null!=c&&(d=Nb({inputs:{x:o},backend:n,attrs:{perm:c}}),h=ll(h.length,u)),il("sum",h,d.shape.length);const[p,f]=rl(d.shape,h);let m=ry(n,p,Wa(d.dtype,"int32"));const g=be(f),y=n.data.get(m.dataId).values,b=n.data.get(d.dataId).values;for(let e=0;e<y.length;++e){const t=e*g;let n=0;for(let e=0;e<g;++e)n+=b[t+e];y[e]=n}if(i){const e=m;m=dq({inputs:{x:m},backend:n,attrs:{shape:al(m.shape,l)}}),n.disposeIntermediateTensorInfo(e)}return n.disposeIntermediateTensorInfo(o),null!=c&&n.disposeIntermediateTensorInfo(d),m}const Tj={kernelName:Ms,backendName:"cpu",kernelFunc:Nj};
|
|
17875
17875
|
/**
|
|
17876
17876
|
* @license
|
|
17877
17877
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -17887,7 +17887,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r}=t,{canvas:a,options:i}
|
|
|
17887
17887
|
* See the License for the specific language governing permissions and
|
|
17888
17888
|
* limitations under the License.
|
|
17889
17889
|
* =============================================================================
|
|
17890
|
-
*/const
|
|
17890
|
+
*/const $j={kernelName:Zt,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{equation:r}=s,a=t,{allDims:i,summedDims:o,idDims:u}=nm(r,a.length);rm(i.length,u,a);const{path:l,steps:c}=am(o,u),h=c.length;let d=null,p=i.length;const f=[];for(let e=0;e<h;++e){for(const t of c[e]){const{permutationIndices:e,expandDims:s}=sm(p,u[t]);let r;im(e)?r=a[t]:(r=Nb({inputs:{x:a[t]},backend:n,attrs:{perm:e}}),f.push(r));const i=r.shape.slice();for(let e=0;e<s.length;++e)i.splice(s[e],0,1);we(r.shape,i)||(r=dq({inputs:{x:r},backend:n,attrs:{shape:i}}),f.push(r)),null===d?d=r:(d=bb({inputs:{a:r,b:d},backend:n}),f.push(d))}e<h-1&&(l[e]>=0&&(d=Nj({inputs:{x:d},backend:n,attrs:{axis:l[e]-(i.length-p),keepDims:!1}}),f.push(d)),p--)}for(const e of f)e!==d&&n.disposeIntermediateTensorInfo(e);return d}};
|
|
17891
17891
|
/**
|
|
17892
17892
|
* @license
|
|
17893
17893
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17903,7 +17903,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r}=t,{canvas:a,options:i}
|
|
|
17903
17903
|
* See the License for the specific language governing permissions and
|
|
17904
17904
|
* limitations under the License.
|
|
17905
17905
|
* =============================================================================
|
|
17906
|
-
*/const
|
|
17906
|
+
*/const Rj={kernelName:tn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{dy:s,y:r}=t;Jg([s,r],"eluGrad");const a=new Float32Array(be(r.shape)),i=n.data.get(r.dataId).values,o=n.data.get(s.dataId).values;for(let e=0;e<i.length;++e){const t=i[e];a[e]=t>=0?o[e]:o[e]*(t+1)}return n.makeTensorInfo(r.shape,"float32",a)}},Ej=Pf,Aj=zf,_j=Bf,Fj=Wf,Dj=Uf,Mj=Vf,Oj=Sy(nn,(e=>{const t=Math.sign(e),n=Math.abs(e),s=1/(1+Ej*n);return t*(1-((((Mj*s+Dj)*s+Fj)*s+_j)*s+Aj)*s*Math.exp(-n*n))})),Lj={kernelName:nn,backendName:"cpu",kernelFunc:Oj};
|
|
17907
17907
|
/**
|
|
17908
17908
|
* @license
|
|
17909
17909
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17936,7 +17936,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{image:r}=t,{canvas:a,options:i}
|
|
|
17936
17936
|
* limitations under the License.
|
|
17937
17937
|
* =============================================================================
|
|
17938
17938
|
*/
|
|
17939
|
-
function
|
|
17939
|
+
function Pj(e){const{inputs:t,backend:n,attrs:s}=e,{input:r}=t,{dim:a}=s,i=r.shape.length,o=r.shape.slice();let u=a;return a<0&&(me(-(i+1)<=a,(()=>`Axis must be in the interval [${-(i+1)}, ${i}]`)),u=i+a+1),o.splice(u,0,1),dq({inputs:{x:r},backend:n,attrs:{shape:o}})}const zj={kernelName:an,backendName:"cpu",kernelFunc:Pj},Bj=ty(((e,t)=>e/t)),Wj=dy(Jt,Bj),Uj={kernelName:Jt,backendName:"cpu",kernelFunc:Wj};
|
|
17940
17940
|
/**
|
|
17941
17941
|
* @license
|
|
17942
17942
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17969,7 +17969,7 @@ function Oj(e){const{inputs:t,backend:n,attrs:s}=e,{input:r}=t,{dim:a}=s,i=r.sha
|
|
|
17969
17969
|
* limitations under the License.
|
|
17970
17970
|
* =============================================================================
|
|
17971
17971
|
*/
|
|
17972
|
-
function
|
|
17972
|
+
function Vj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.complexTensorInfos.real,u=i.complexTensorInfos.imag,l=[r,a],c=be(l),h=$e("float32",c),d=$e("float32",c);for(let e=0;e<r;e++){const s=Yb({inputs:{x:o},backend:n,attrs:{begin:[e,0],size:[1,a]}}),r=Yb({inputs:{x:u},backend:n,attrs:{begin:[e,0],size:[1,a]}}),i=ny({inputs:{real:s,imag:r},backend:n}),{real:l,imag:c}=Gj(i,t,n),p=Gf(l,c);for(let t=0;t<a;t++){const n=Xf(p,t);h[e*a+t]=n.real,d[e*a+t]=n.imag}n.disposeIntermediateTensorInfo(s),n.disposeIntermediateTensorInfo(r),n.disposeIntermediateTensorInfo(i)}const p=n.makeTensorInfo(l,"float32",h),f=n.makeTensorInfo(l,"float32",d),m=ny({inputs:{real:p,imag:f},backend:n});return n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(f),m}function Gj(e,t,n){const s=be(e.shape),r=n.data.get(e.dataId),a=n.data.get(r.complexTensorInfos.real.dataId).values,i=n.data.get(r.complexTensorInfos.imag.dataId).values;if((o=s)&o-1){const e=function(e,t,n){const s=new Float32Array(2*t);for(let r=0;r<t;r++){let a=0,i=0;for(let s=0;s<t;s++){const o=Qf(r*s,t,n),u=Xf(e,s);a+=u.real*o.real-u.imag*o.imag,i+=u.real*o.imag+u.imag*o.real}n&&(a/=t,i/=t),Kf(s,a,i,r)}return s}
|
|
17973
17973
|
/**
|
|
17974
17974
|
* @license
|
|
17975
17975
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17985,7 +17985,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
17985
17985
|
* See the License for the specific language governing permissions and
|
|
17986
17986
|
* limitations under the License.
|
|
17987
17987
|
* =============================================================================
|
|
17988
|
-
*/(Gf(a,i),s,t);return Hf(e)}{const r=
|
|
17988
|
+
*/(Gf(a,i),s,t);return Hf(e)}{const r=Hj(a,i,s,t,n),o=[e.shape[0],e.shape[1]];if(t){const e=n.makeTensorInfo(o,"float32",r.real),t=n.makeTensorInfo(o,"float32",r.imag),a=n.makeTensorInfo([],"float32",ha(s,"float32")),i=ay({inputs:{x:a},backend:n}),u=Uj.kernelFunc({inputs:{a:e,b:a},backend:n}),l=Uj.kernelFunc({inputs:{a:t,b:i},backend:n}),c=n.data.get(u.dataId).values,h=n.data.get(l.dataId).values;return n.disposeIntermediateTensorInfo(e),n.disposeIntermediateTensorInfo(t),n.disposeIntermediateTensorInfo(a),n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(u),n.disposeIntermediateTensorInfo(l),{real:c,imag:h}}return r}var o}function Hj(e,t,n,s,r){if(1===n)return{real:e,imag:t};const a=Gf(e,t),i=n/2,o=qf(a),u=o.real,l=o.imag,c=[u.length],h=r.makeTensorInfo(c,"float32",u),d=r.makeTensorInfo(c,"float32",l),p=ny({inputs:{real:h,imag:d},backend:r}),f=jf(a),m=f.real,g=f.imag,y=[m.length],b=r.makeTensorInfo(y,"float32",m),x=r.makeTensorInfo(y,"float32",g),w=ny({inputs:{real:b,imag:x},backend:r}),k=Hj(u,l,i,s,r),v=k.real,I=k.imag,S=[v.length],C=r.makeTensorInfo(S,"float32",v),N=r.makeTensorInfo(S,"float32",I),T=ny({inputs:{real:C,imag:N},backend:r}),$=Hj(m,g,i,s,r),R=$.real,E=$.imag,A=[R.length],_=r.makeTensorInfo(A,"float32",R),F=r.makeTensorInfo(A,"float32",E),D=ny({inputs:{real:_,imag:F},backend:r}),M=Yf(n,s),O=[M.real.length],L=r.makeTensorInfo(O,"float32",M.real),P=r.makeTensorInfo(O,"float32",M.imag),z=ny({inputs:{real:L,imag:P},backend:r}),B=bb({inputs:{a:z,b:D},backend:r}),W=gy({inputs:{a:T,b:B},backend:r}),U=bx({inputs:{a:T,b:B},backend:r}),V=oy({inputs:{input:W},backend:r}),G=oy({inputs:{input:U},backend:r}),H=Qq({inputs:{input:W},backend:r}),q=Qq({inputs:{input:U},backend:r}),j=Zq({inputs:[V,G],backend:r,attrs:{axis:0}}),X=Zq({inputs:[H,q],backend:r,attrs:{axis:0}}),K=r.data.get(j.dataId).values,Y=r.data.get(X.dataId).values;return r.disposeIntermediateTensorInfo(h),r.disposeIntermediateTensorInfo(d),r.disposeIntermediateTensorInfo(p),r.disposeIntermediateTensorInfo(b),r.disposeIntermediateTensorInfo(x),r.disposeIntermediateTensorInfo(w),r.disposeIntermediateTensorInfo(C),r.disposeIntermediateTensorInfo(N),r.disposeIntermediateTensorInfo(T),r.disposeIntermediateTensorInfo(_),r.disposeIntermediateTensorInfo(F),r.disposeIntermediateTensorInfo(D),r.disposeIntermediateTensorInfo(L),r.disposeIntermediateTensorInfo(P),r.disposeIntermediateTensorInfo(z),r.disposeIntermediateTensorInfo(B),r.disposeIntermediateTensorInfo(W),r.disposeIntermediateTensorInfo(U),r.disposeIntermediateTensorInfo(V),r.disposeIntermediateTensorInfo(H),r.disposeIntermediateTensorInfo(G),r.disposeIntermediateTensorInfo(q),r.disposeIntermediateTensorInfo(j),r.disposeIntermediateTensorInfo(X),{real:K,imag:Y}}const qj={kernelName:un,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{input:s}=t,r=be(s.shape),a=s.shape[s.shape.length-1],i=dq({inputs:{x:s},backend:n,attrs:{shape:[r/a,a]}}),o=Vj(i,!1,n),u=dq({inputs:{x:o},backend:n,attrs:{shape:s.shape}});return n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(o),u}};
|
|
17989
17989
|
/**
|
|
17990
17990
|
* @license
|
|
17991
17991
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18001,7 +18001,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18001
18001
|
* See the License for the specific language governing permissions and
|
|
18002
18002
|
* limitations under the License.
|
|
18003
18003
|
* =============================================================================
|
|
18004
|
-
*/function
|
|
18004
|
+
*/function jj(e){const{backend:t,attrs:n}=e,{shape:s,value:r,dtype:a}=n,i=a||De(r),o=Re(i,be(s));return function(e,t,n){e.fill(t)}
|
|
18005
18005
|
/**
|
|
18006
18006
|
* @license
|
|
18007
18007
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18017,7 +18017,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18017
18017
|
* See the License for the specific language governing permissions and
|
|
18018
18018
|
* limitations under the License.
|
|
18019
18019
|
* =============================================================================
|
|
18020
|
-
*/(o,r),t.makeTensorInfo(s,i,o)}const
|
|
18020
|
+
*/(o,r),t.makeTensorInfo(s,i,o)}const Xj={kernelName:ln,backendName:"cpu",kernelFunc:jj};const Kj={kernelName:cn,backendName:"cpu",kernelFunc:({inputs:e,attrs:t,backend:n})=>{const{image:s}=e,r=n,a=$e(s.dtype,be(s.shape)),[i,o,u,l]=s.shape,c=r.data.get(s.dataId).values;for(let e=0;e<i;e++){const t=e*u*o*l;for(let e=0;e<o;e++){const n=e*(u*l);for(let e=0;e<u;e++){const s=e*l;for(let r=0;r<l;r++){const i=Math.round(u-e-1),o=t+n+s+r;let h=c[o];if(i>=0&&i<u){h=c[t+n+i*l+r]}a[o]=h}}}}return{dataId:r.write(a,s.shape,s.dtype),shape:s.shape,dtype:s.dtype}}};
|
|
18021
18021
|
/**
|
|
18022
18022
|
* @license
|
|
18023
18023
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18033,7 +18033,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18033
18033
|
* See the License for the specific language governing permissions and
|
|
18034
18034
|
* limitations under the License.
|
|
18035
18035
|
* =============================================================================
|
|
18036
|
-
*/const
|
|
18036
|
+
*/const Yj={kernelName:dr,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,filter:a,bias:i,preluActivationWeights:o}=t,{strides:u,pad:l,dataFormat:c,dilations:h,dimRoundingMode:d,activation:p,leakyreluAlpha:f}=s;let m=tj({inputs:{x:r,filter:a},backend:n,attrs:{strides:u,pad:l,dataFormat:c,dilations:h,dimRoundingMode:d}});if(i){const e=m;if("NCHW"===c&&1===i.shape.length&&1!==i.shape[0]){const e=dq({inputs:{x:i},backend:n,attrs:{shape:[i.shape[0],1,1]}});m=gy({inputs:{a:m,b:e},backend:n}),n.disposeIntermediateTensorInfo(e)}else m=gy({inputs:{a:m,b:i},backend:n});n.disposeIntermediateTensorInfo(e)}if(p){const e=m;if("NCHW"===c&&"prelu"===p&&1===o.shape.length&&1!==o.shape[0]){const e=dq({inputs:{x:o},backend:n,attrs:{shape:[o.shape[0],1,1]}});m=hq(n,m,p,e,f),n.disposeIntermediateTensorInfo(e)}else m=hq(n,m,p,o,f);n.disposeIntermediateTensorInfo(e)}return m}};
|
|
18037
18037
|
/**
|
|
18038
18038
|
* @license
|
|
18039
18039
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18049,7 +18049,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18049
18049
|
* See the License for the specific language governing permissions and
|
|
18050
18050
|
* limitations under the License.
|
|
18051
18051
|
* =============================================================================
|
|
18052
|
-
*/const
|
|
18052
|
+
*/const Qj={kernelName:pr,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,filter:a,bias:i,preluActivationWeights:o}=t,{strides:u,pad:l,dataFormat:c,dilations:h,dimRoundingMode:d,activation:p,leakyreluAlpha:f}=s;let m=yj({inputs:{x:r,filter:a},backend:n,attrs:{strides:u,pad:l,dataFormat:c,dilations:h,dimRoundingMode:d}});if(i){const e=m;m=gy({inputs:{a:m,b:i},backend:n}),n.disposeIntermediateTensorInfo(e)}if(p){const e=m;m=hq(n,m,p,o,f),n.disposeIntermediateTensorInfo(e)}return m}};
|
|
18053
18053
|
/**
|
|
18054
18054
|
* @license
|
|
18055
18055
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18065,7 +18065,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18065
18065
|
* See the License for the specific language governing permissions and
|
|
18066
18066
|
* limitations under the License.
|
|
18067
18067
|
* =============================================================================
|
|
18068
|
-
*/const
|
|
18068
|
+
*/const Jj={kernelName:mn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{params:s,indices:r}=t,a=be(s.shape),i=r.shape,o=i[i.length-1],[u,l,c,h]=Jp(s,r);if(0===l)return n.makeTensorInfo(u,s.dtype,[]);const d=Hy(n.data.get(r.dataId).values,n.bufferSync(s),s.dtype,l,o,c,h,s.shape,a);return n.makeTensorInfo(u,s.dtype,d.values)}};
|
|
18069
18069
|
/**
|
|
18070
18070
|
* @license
|
|
18071
18071
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18081,7 +18081,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18081
18081
|
* See the License for the specific language governing permissions and
|
|
18082
18082
|
* limitations under the License.
|
|
18083
18083
|
* =============================================================================
|
|
18084
|
-
*/const
|
|
18084
|
+
*/const Zj={kernelName:fn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,indices:a}=t,{axis:i,batchDims:o}=s;Jg([r,a],"gatherV2");const u=Ne(i,r.shape)[0],l=n.data.get(a.dataId).values,c=r.shape[u];for(let e=0;e<l.length;++e){const t=l[e];me(t<=c-1&&t>=0,(()=>`GatherV2: the index value ${t} is not in [0, ${c-1}]`))}let h=o;null==o&&(h=0);const d=be(a.shape),p=Im(r,a,u,h),f=dq({inputs:{x:r},backend:n,attrs:{shape:[p.batchSize,p.outerSize,p.dimSize,p.sliceSize]}}),m=dq({inputs:{x:a},backend:n,attrs:{shape:[p.batchSize,d/p.batchSize]}}),g=[p.batchSize,p.outerSize,d/p.batchSize,p.sliceSize],y=n.bufferSync(m),b=qy(n.bufferSync(f),y,g);return n.disposeIntermediateTensorInfo(f),n.disposeIntermediateTensorInfo(m),n.makeTensorInfo(p.outputShape,b.dtype,b.values)}};
|
|
18085
18085
|
/**
|
|
18086
18086
|
* @license
|
|
18087
18087
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18097,7 +18097,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18097
18097
|
* See the License for the specific language governing permissions and
|
|
18098
18098
|
* limitations under the License.
|
|
18099
18099
|
* =============================================================================
|
|
18100
|
-
*/const
|
|
18100
|
+
*/const eX={kernelName:xn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{input:s}=t,r=be(s.shape),a=s.shape[s.shape.length-1],i=dq({inputs:{x:s},backend:n,attrs:{shape:[r/a,a]}}),o=Vj(i,!0,n),u=dq({inputs:{x:o},backend:n,attrs:{shape:s.shape}});return n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(o),u}},tX=Sy(kn,(e=>Number.isFinite(e)?1:0),"bool"),nX={kernelName:kn,backendName:"cpu",kernelFunc:tX},sX=Sy(vn,(e=>Math.abs(e)===1/0?1:0),"bool"),rX={kernelName:vn,backendName:"cpu",kernelFunc:sX},aX=Sy(In,(e=>Number.isNaN(e)?1:0),"bool"),iX={kernelName:In,backendName:"cpu",kernelFunc:aX};
|
|
18101
18101
|
/**
|
|
18102
18102
|
* @license
|
|
18103
18103
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18113,7 +18113,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18113
18113
|
* See the License for the specific language governing permissions and
|
|
18114
18114
|
* limitations under the License.
|
|
18115
18115
|
* =============================================================================
|
|
18116
|
-
*/const
|
|
18116
|
+
*/const oX={kernelName:Tn,backendName:"cpu",kernelFunc:
|
|
18117
18117
|
/**
|
|
18118
18118
|
* @license
|
|
18119
18119
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18130,7 +18130,7 @@ function Wj(e,t,n){const s=e.shape,r=s[0],a=s[1],i=n.data.get(e.dataId),o=i.comp
|
|
|
18130
18130
|
* limitations under the License.
|
|
18131
18131
|
* =============================================================================
|
|
18132
18132
|
*/
|
|
18133
|
-
function(e){const{backend:t,attrs:n}=e,{start:s,stop:r,num:a}=n,i=ab(s,r,a);return t.makeTensorInfo([i.length],"float32",i)}},
|
|
18133
|
+
function(e){const{backend:t,attrs:n}=e,{start:s,stop:r,num:a}=n,i=ab(s,r,a);return t.makeTensorInfo([i.length],"float32",i)}},uX=Sy(Rn,(e=>Math.log1p(e))),lX={kernelName:Rn,backendName:"cpu",kernelFunc:uX},cX=ty(((e,t)=>e&&t)),hX=dy(En,cX,null,"bool"),dX={kernelName:En,backendName:"cpu",kernelFunc:hX},pX=Sy(An,(e=>e?0:1),"bool"),fX={kernelName:An,backendName:"cpu",kernelFunc:pX},mX=ty(((e,t)=>e||t)),gX=dy(_n,mX,null,"bool"),yX={kernelName:_n,backendName:"cpu",kernelFunc:gX};
|
|
18134
18134
|
/**
|
|
18135
18135
|
* @license
|
|
18136
18136
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18146,7 +18146,7 @@ function(e){const{backend:t,attrs:n}=e,{start:s,stop:r,num:a}=n,i=ab(s,r,a);retu
|
|
|
18146
18146
|
* See the License for the specific language governing permissions and
|
|
18147
18147
|
* limitations under the License.
|
|
18148
18148
|
* =============================================================================
|
|
18149
|
-
*/const
|
|
18149
|
+
*/const bX={kernelName:Fn,backendName:"cpu",kernelFunc:
|
|
18150
18150
|
/**
|
|
18151
18151
|
* @license
|
|
18152
18152
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18179,7 +18179,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{depthRadius:a,bias:i,al
|
|
|
18179
18179
|
* See the License for the specific language governing permissions and
|
|
18180
18180
|
* limitations under the License.
|
|
18181
18181
|
* =============================================================================
|
|
18182
|
-
*/const
|
|
18182
|
+
*/const xX={kernelName:Dn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,y:a,dy:i}=t,{depthRadius:o,bias:u,alpha:l,beta:c}=s;Jg(i,"LRNGrad");const h=be(i.shape),d=i.shape[3],p=n.data.get(i.dataId).values,f=n.data.get(r.dataId).values,m=n.data.get(a.dataId).values,g=new Float32Array(h),y=h;for(let e=0;e<y;e++){const t=e%d,n=e-t+Math.max(0,t-o),s=e-t+Math.min(d,t+o+1);let r=0;for(let e=n;e<s;e++)r+=Math.pow(f[e],2);r=l*r+u;for(let t=n;t<s;t++){let n=-2*l*c*f[t]*m[e]/r;e===t&&(n+=Math.pow(r,-c)),n*=p[e],g[t]+=n}}return n.makeTensorInfo(i.shape,r.dtype,g)}};
|
|
18183
18183
|
/**
|
|
18184
18184
|
* @license
|
|
18185
18185
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18195,7 +18195,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{depthRadius:a,bias:i,al
|
|
|
18195
18195
|
* See the License for the specific language governing permissions and
|
|
18196
18196
|
* limitations under the License.
|
|
18197
18197
|
* =============================================================================
|
|
18198
|
-
*/function
|
|
18198
|
+
*/function wX(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{reductionIndices:a,keepDims:i}=s,o=n;let u=r.shape;const l=u.length,c=Ne(a,u);let h=c;const d=ol(h,l);let p=o.data.get(r.dataId).values;if(null!=d){const e=new Array(l);for(let t=0;t<e.length;t++)e[t]=u[d[t]];p=Cb(p,u,r.dtype,d,e),h=ll(h.length,l),u=e}Jg(r,"max"),il("max",h,l);const[f,m]=rl(u,h),g=lb(p,be(m),f,r.dtype),y=o.write(g,f,r.dtype);let b=f;if(i){b=al(f,c)}return{dataId:y,shape:b,dtype:r.dtype}}const kX={kernelName:Mn,backendName:"cpu",kernelFunc:wX};
|
|
18199
18199
|
/**
|
|
18200
18200
|
* @license
|
|
18201
18201
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18211,7 +18211,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{depthRadius:a,bias:i,al
|
|
|
18211
18211
|
* See the License for the specific language governing permissions and
|
|
18212
18212
|
* limitations under the License.
|
|
18213
18213
|
* =============================================================================
|
|
18214
|
-
*/const
|
|
18214
|
+
*/const vX={kernelName:Ln,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t;Jg(r,"maxPool");const{filterSize:a,strides:i,pad:o,dimRoundingMode:u}=s;me(Zo(i,1),(()=>`Error in maxPool: Either strides or dilations must be 1. Got strides ${i} and dilations '1'`));const l=Vo(r.shape,a,i,1,o,u);let c;if(1===l.filterWidth&&1===l.filterHeight&&we(l.inShape,l.outShape))c=ay({inputs:{x:r},backend:n});else{const e=n.data.get(r.dataId).values,t=Le(r.shape),s=Lq(e,r.shape,r.dtype,t,l,"max");c=n.makeTensorInfo(l.outShape,r.dtype,s.values)}return c}};
|
|
18215
18215
|
/**
|
|
18216
18216
|
* @license
|
|
18217
18217
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18227,7 +18227,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{depthRadius:a,bias:i,al
|
|
|
18227
18227
|
* See the License for the specific language governing permissions and
|
|
18228
18228
|
* limitations under the License.
|
|
18229
18229
|
* =============================================================================
|
|
18230
|
-
*/const
|
|
18230
|
+
*/const IX={kernelName:zn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{filterSize:a,strides:i,pad:o,dimRoundingMode:u,dataFormat:l}=s;Jg(r,"maxPool3d");const c=Go(r.shape,a,i,1,o,u,l),h=zq(n.data.get(r.dataId).values,r.shape,r.dtype,Le(r.shape),c,"max");return n.makeTensorInfo(h.shape,"float32",h.values)}};
|
|
18231
18231
|
/**
|
|
18232
18232
|
* @license
|
|
18233
18233
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18243,7 +18243,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{depthRadius:a,bias:i,al
|
|
|
18243
18243
|
* See the License for the specific language governing permissions and
|
|
18244
18244
|
* limitations under the License.
|
|
18245
18245
|
* =============================================================================
|
|
18246
|
-
*/const
|
|
18246
|
+
*/const SX={kernelName:Bn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{dy:r,input:a}=t,{filterSize:i,strides:o,pad:u,dimRoundingMode:l}=s;Jg([r,a],"maxPool3DGrad");const c=Go(a.shape,i,o,1,u,l),h=function(e,t){const n=ko(t.outShape,"int32"),s=t.strideDepth,r=t.strideHeight,a=t.strideWidth,i=t.dilationDepth,o=t.dilationHeight,u=t.dilationWidth,l=t.effectiveFilterDepth,c=t.effectiveFilterHeight,h=t.effectiveFilterWidth,d=t.padInfo.front,p=t.padInfo.top,f=t.padInfo.left;for(let m=0;m<t.batchSize;++m)for(let g=0;g<t.inChannels;++g)for(let y=0;y<t.outDepth;++y){const b=y*s-d;let x=b;for(;x<0;)x+=i;const w=Math.min(t.inDepth,l+b);for(let s=0;s<t.outHeight;++s){const l=s*r-p;let d=l;for(;d<0;)d+=o;const k=Math.min(t.inHeight,c+l);for(let r=0;r<t.outWidth;++r){const p=r*a-f;let v=p;for(;v<0;)v+=u;const I=Math.min(t.inWidth,h+p);let S=Number.NEGATIVE_INFINITY,C=-1;for(let t=x;t<w;t+=i){const n=t-b;for(let s=d;s<k;s+=o){const r=s-l;for(let a=v;a<I;a+=u){const i=a-p,o=e.get(m,t,s,a,g);o>=S&&(S=o,C=n*c*h+r*c+i)}}}n.set(C,m,y,s,r,g)}}}return n}(n.bufferSync(a),c),d=c.strideDepth,p=c.strideHeight,f=c.strideWidth,m=c.dilationDepth,g=c.dilationHeight,y=c.dilationWidth,b=c.effectiveFilterDepth,x=c.effectiveFilterHeight,w=c.effectiveFilterWidth,k=b-1-c.padInfo.front,v=w-1-c.padInfo.left,I=x-1-c.padInfo.top,S=ko(a.shape,"float32"),C=n.bufferSync(r);for(let e=0;e<c.batchSize;++e)for(let t=0;t<c.inChannels;++t)for(let n=0;n<c.inDepth;++n)for(let s=0;s<c.inHeight;++s)for(let r=0;r<c.inWidth;++r){const a=n-k,i=s-I,o=r-v;let u=0;for(let n=0;n<b;n+=m){const s=(a+n)/d;if(!(s<0||s>=c.outDepth||Math.floor(s)!==s))for(let r=0;r<x;r+=g){const a=(i+r)/p;if(!(a<0||a>=c.outHeight||Math.floor(a)!==a))for(let i=0;i<w;i+=y){const l=(o+i)/f;if(l<0||l>=c.outWidth||Math.floor(l)!==l)continue;const d=b*x*w-1-h.get(e,s,a,l,t)===n*x*w+r*w+i?1:0;if(0===d)continue;u+=C.get(e,s,a,l,t)*d}}}S.set(u,e,n,s,r,t)}return n.makeTensorInfo(S.shape,S.dtype,S.values)}};
|
|
18247
18247
|
/**
|
|
18248
18248
|
* @license
|
|
18249
18249
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18259,7 +18259,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{depthRadius:a,bias:i,al
|
|
|
18259
18259
|
* See the License for the specific language governing permissions and
|
|
18260
18260
|
* limitations under the License.
|
|
18261
18261
|
* =============================================================================
|
|
18262
|
-
*/const
|
|
18262
|
+
*/const CX={kernelName:Pn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{dy:r,input:a,output:i}=t,o=a;Jg([a,i],"maxPoolGrad");const{filterSize:u,strides:l,pad:c,dimRoundingMode:h}=s,d=Vo(o.shape,u,l,1,c,h),p=n.data.get(o.dataId).values,f=ko(d.outShape,o.dtype,Pq(p,o.shape,o.dtype,d).values),m=d.strideHeight,g=d.strideWidth,y=d.dilationHeight,b=d.dilationWidth,x=d.effectiveFilterHeight,w=d.effectiveFilterWidth,k=w-1-d.padInfo.left,v=x-1-d.padInfo.top,I=ko(o.shape,"float32"),S=n.data.get(r.dataId).values,C=ko(r.shape,"float32",S);for(let e=0;e<d.batchSize;++e)for(let t=0;t<d.inChannels;++t)for(let n=0;n<d.inHeight;++n)for(let s=0;s<d.inWidth;++s){const r=n-v,a=s-k;let i=0;for(let n=0;n<x;n+=y){const s=(r+n)/m;if(!(s<0||s>=d.outHeight||Math.floor(s)!==s))for(let r=0;r<w;r+=b){const o=(a+r)/g;if(o<0||o>=d.outWidth||Math.floor(o)!==o)continue;const u=x*w-1-f.get(e,s,o,t)===n*w+r?1:0;if(0===u)continue;i+=C.get(e,s,o,t)*u}}I.set(i,e,n,s,t)}return n.makeTensorInfo(I.shape,I.dtype,I.values)}};
|
|
18263
18263
|
/**
|
|
18264
18264
|
* @license
|
|
18265
18265
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18292,7 +18292,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{depthRadius:a,bias:i,al
|
|
|
18292
18292
|
* limitations under the License.
|
|
18293
18293
|
* =============================================================================
|
|
18294
18294
|
*/
|
|
18295
|
-
const
|
|
18295
|
+
const NX={kernelName:Wn,backendName:"cpu",kernelFunc:({inputs:e,attrs:t,backend:n})=>{const{x:s}=e,{filterSize:r,strides:a,pad:i,includeBatchInIndex:o}=t,u=n;Jg(s,"MaxPoolWithArgmax");const l=u.data.get(s.dataId).values,c=Vo(s.shape,r,a,[1,1],i),[h,d]=function(e,t,n,s,r){const a=Lq(e,0,n,Le(t),r,"max"),i=Pq(e,t,n,r,!0,s);return[a.values,i.values]}(l,s.shape,s.dtype,o,c),p=u.write(h,c.outShape,s.dtype),f=u.write(d,c.outShape,s.dtype);return[{dataId:p,shape:c.outShape,dtype:s.dtype},{dataId:f,shape:c.outShape,dtype:"int32"}]}};
|
|
18296
18296
|
/**
|
|
18297
18297
|
* @license
|
|
18298
18298
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18308,7 +18308,7 @@ const SX={kernelName:Wn,backendName:"cpu",kernelFunc:({inputs:e,attrs:t,backend:
|
|
|
18308
18308
|
* See the License for the specific language governing permissions and
|
|
18309
18309
|
* limitations under the License.
|
|
18310
18310
|
* =============================================================================
|
|
18311
|
-
*/const
|
|
18311
|
+
*/const TX={kernelName:Un,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a,keepDims:i}=s,o=Ne(a,r.shape),u=be(rl(r.shape,o)[1]),l=[],c=n.makeTensorInfo([],"float32",new Float32Array([u]));l.push(c);const h=cy({inputs:{x:r},backend:n,attrs:{dtype:"float32"}});l.push(h);const d=Wj({inputs:{a:h,b:c},backend:n});l.push(d);const p=Nj({inputs:{x:d},backend:n,attrs:{axis:a,keepDims:i}});return l.forEach((e=>n.disposeIntermediateTensorInfo(e))),p}};
|
|
18312
18312
|
/**
|
|
18313
18313
|
* @license
|
|
18314
18314
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18324,7 +18324,7 @@ const SX={kernelName:Wn,backendName:"cpu",kernelFunc:({inputs:e,attrs:t,backend:
|
|
|
18324
18324
|
* See the License for the specific language governing permissions and
|
|
18325
18325
|
* limitations under the License.
|
|
18326
18326
|
* =============================================================================
|
|
18327
|
-
*/const
|
|
18327
|
+
*/const $X={kernelName:Vn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{axis:a,keepDims:i}=s;Jg(r,"min");const o=Ne(a,r.shape);let u=o;const l=ol(u,r.shape.length);let c=r;null!=l&&(c=Nb({inputs:{x:r},backend:n,attrs:{perm:l}}),u=ll(u.length,r.shape.length)),il("min",u,c.shape.length);const[h,d]=rl(c.shape,u),p=be(d),f=Ue(be(h),c.dtype),m=n.data.get(c.dataId).values;for(let e=0;e<f.length;++e){const t=e*p;let n=m[t];for(let e=0;e<p;++e){const s=m[t+e];(Number.isNaN(s)||s<n)&&(n=s)}f[e]=n}null!=l&&n.disposeIntermediateTensorInfo(c);const g=n.makeTensorInfo(h,c.dtype,f);if(i){const e=dq({inputs:{x:g},backend:n,attrs:{shape:al(h,o)}});return n.disposeIntermediateTensorInfo(g),e}return g}};
|
|
18328
18328
|
/**
|
|
18329
18329
|
* @license
|
|
18330
18330
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18340,7 +18340,7 @@ const SX={kernelName:Wn,backendName:"cpu",kernelFunc:({inputs:e,attrs:t,backend:
|
|
|
18340
18340
|
* See the License for the specific language governing permissions and
|
|
18341
18341
|
* limitations under the License.
|
|
18342
18342
|
* =============================================================================
|
|
18343
|
-
*/const
|
|
18343
|
+
*/const RX={kernelName:Hn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{paddings:a,mode:i}=s;Jg(r,"mirrorPad");const o=a.map(((e,t)=>e[0]+r.shape[t]+e[1])),u=a.map((e=>e[0])),l=a.map(((e,t)=>e[0]+r.shape[t])),c="reflect"===i?0:1,h=n.data.get(r.dataId).values,d=r.shape.length,p=Le(r.shape),f=be(o),m=o.length,g=Le(o),y=$e(r.dtype,f);for(let e=0;e<f;e++){let t=qe(e,m,g);for(let e=0;e<m;e++)t[e]<u[e]?t[e]=2*u[e]-t[e]-c:t[e]>=l[e]&&(t[e]=2*(l[e]-1)-t[e]+c);t=t.map(((e,t)=>e-u[t]));const n=He(t,d,p);y[e]=h[n]}return{dataId:n.write(y,o,r.dtype),shape:o,dtype:r.dtype}}},EX=ty(((e,t)=>{const n=e%t;return e<0&&t<0||e>=0&&t>=0?n:(n+t)%t})),AX=dy(qn,EX),_X={kernelName:qn,backendName:"cpu",kernelFunc:AX};
|
|
18344
18344
|
/**
|
|
18345
18345
|
* @license
|
|
18346
18346
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18373,7 +18373,7 @@ const SX={kernelName:Wn,backendName:"cpu",kernelFunc:({inputs:e,attrs:t,backend:
|
|
|
18373
18373
|
* limitations under the License.
|
|
18374
18374
|
* =============================================================================
|
|
18375
18375
|
*/
|
|
18376
|
-
function
|
|
18376
|
+
function FX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.shape.length;let o=a;if(-1===o&&(o=i-1),o!==i-1)throw Error(`Softmax along a non-last dimension is not yet supported. Logits was rank ${i} and dim was ${o}`);const u=Ne([o],r.shape),l=wX({inputs:{x:r},backend:n,attrs:{reductionIndices:u,keepDims:!1}}),c=al(l.shape,u),h=dq({inputs:{x:l},backend:n,attrs:{shape:c}}),d=bx({inputs:{a:r,b:h},backend:n}),p=Dy({inputs:{x:d},backend:n}),f=Nj({inputs:{x:p},backend:n,attrs:{axis:u,keepDims:!1}}),m=dq({inputs:{x:f},backend:n,attrs:{shape:c}}),g=Wj({inputs:{a:p,b:m},backend:n});return n.disposeIntermediateTensorInfo(l),n.disposeIntermediateTensorInfo(h),n.disposeIntermediateTensorInfo(d),n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(f),n.disposeIntermediateTensorInfo(m),g}const DX={kernelName:Ps,backendName:"cpu",kernelFunc:FX};
|
|
18377
18377
|
/**
|
|
18378
18378
|
* @license
|
|
18379
18379
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18389,7 +18389,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18389
18389
|
* See the License for the specific language governing permissions and
|
|
18390
18390
|
* limitations under the License.
|
|
18391
18391
|
* =============================================================================
|
|
18392
|
-
*/const
|
|
18392
|
+
*/const MX={kernelName:jn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{numSamples:a,seed:i,normalized:o}=s;Jg(r,"multinomial");const u=o?r:FX({inputs:{logits:r},backend:n,attrs:{dim:-1}}),l=u.shape[0],c=u.shape[1],h=n.data.get(u.dataId).values,d=[l,a],p=Ue(be(d),"int32");for(let e=0;e<l;++e){const t=e*c,n=new Float32Array(c-1);n[0]=h[t];for(let e=1;e<n.length;++e)n[e]=n[e-1]+h[t+e];const s=Kc.alea(i.toString()),r=e*a;for(let e=0;e<a;++e){const t=s();p[r+e]=n.length;for(let s=0;s<n.length;s++)if(t<n[s]){p[r+e]=s;break}}}return o||n.disposeIntermediateTensorInfo(u),n.makeTensorInfo(d,"int32",p)}},OX=Fd;
|
|
18393
18393
|
/**
|
|
18394
18394
|
* @license
|
|
18395
18395
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18405,7 +18405,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18405
18405
|
* See the License for the specific language governing permissions and
|
|
18406
18406
|
* limitations under the License.
|
|
18407
18407
|
* =============================================================================
|
|
18408
|
-
*/const
|
|
18408
|
+
*/const LX={kernelName:Qn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{boxes:r,scores:a}=t,{maxOutputSize:i,iouThreshold:o,scoreThreshold:u}=s;Jg(r,"NonMaxSuppression");const l=n.data.get(r.dataId).values,c=n.data.get(a.dataId).values,{selectedIndices:h}=OX(l,c,i,o,u);return n.makeTensorInfo([h.length],"int32",new Int32Array(h))}},PX=Dd;
|
|
18409
18409
|
/**
|
|
18410
18410
|
* @license
|
|
18411
18411
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18421,7 +18421,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18421
18421
|
* See the License for the specific language governing permissions and
|
|
18422
18422
|
* limitations under the License.
|
|
18423
18423
|
* =============================================================================
|
|
18424
|
-
*/const
|
|
18424
|
+
*/const zX={kernelName:Jn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{boxes:r,scores:a}=t,{maxOutputSize:i,iouThreshold:o,scoreThreshold:u,padToMaxOutputSize:l}=s;Jg(r,"NonMaxSuppressionPadded");const c=n.data.get(r.dataId).values,h=n.data.get(a.dataId).values,{selectedIndices:d,validOutputs:p}=PX(c,h,i,o,u,l);return[n.makeTensorInfo([d.length],"int32",new Int32Array(d)),n.makeTensorInfo([],"int32",new Int32Array([p]))]}},BX=Md;
|
|
18425
18425
|
/**
|
|
18426
18426
|
* @license
|
|
18427
18427
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -18437,7 +18437,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18437
18437
|
* See the License for the specific language governing permissions and
|
|
18438
18438
|
* limitations under the License.
|
|
18439
18439
|
* =============================================================================
|
|
18440
|
-
*/const
|
|
18440
|
+
*/const WX={kernelName:Zn,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{boxes:r,scores:a}=t,{maxOutputSize:i,iouThreshold:o,scoreThreshold:u,softNmsSigma:l}=s;Jg(r,"NonMaxSuppressionWithScore");const c=n.data.get(r.dataId).values,h=n.data.get(a.dataId).values,d=i,p=o,f=u,m=l,{selectedIndices:g,selectedScores:y}=BX(c,h,d,p,f,m);return[n.makeTensorInfo([g.length],"int32",new Int32Array(g)),n.makeTensorInfo([y.length],"float32",new Float32Array(y))]}};
|
|
18441
18441
|
/**
|
|
18442
18442
|
* @license
|
|
18443
18443
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18453,7 +18453,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18453
18453
|
* See the License for the specific language governing permissions and
|
|
18454
18454
|
* limitations under the License.
|
|
18455
18455
|
* =============================================================================
|
|
18456
|
-
*/const
|
|
18456
|
+
*/const UX={kernelName:ts,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{indices:r}=t,{dtype:a,depth:i,onValue:o,offValue:u}=s;Jg(r,"oneHot");const l=be(r.shape),c=new Float32Array(l*i);c.fill(u);const h=n.data.get(r.dataId).values;for(let e=0;e<l;++e)h[e]>=0&&h[e]<i&&(c[e*i+h[e]]=o);return n.makeTensorInfo([...r.shape,i],a,c)}};
|
|
18457
18457
|
/**
|
|
18458
18458
|
* @license
|
|
18459
18459
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18469,7 +18469,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18469
18469
|
* See the License for the specific language governing permissions and
|
|
18470
18470
|
* limitations under the License.
|
|
18471
18471
|
* =============================================================================
|
|
18472
|
-
*/function
|
|
18472
|
+
*/function VX(e){const{inputs:t,backend:n}=e,{x:s}=t;if("string"===s.dtype)throw new Error("zerosLike is not supported for string tensors");if("complex64"===s.dtype){const e=oy({inputs:{input:s},backend:n}),t=VX({inputs:{x:e},backend:n}),r=Qq({inputs:{input:s},backend:n}),a=VX({inputs:{x:r},backend:n}),i=ny({inputs:{real:t,imag:a},backend:n});return n.disposeIntermediateTensorInfo(e),n.disposeIntermediateTensorInfo(t),n.disposeIntermediateTensorInfo(r),n.disposeIntermediateTensorInfo(a),i}return jj({backend:n,attrs:{shape:s.shape,value:0,dtype:s.dtype}})}const GX={kernelName:or,backendName:"cpu",kernelFunc:VX};
|
|
18473
18473
|
/**
|
|
18474
18474
|
* @license
|
|
18475
18475
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18485,7 +18485,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18485
18485
|
* See the License for the specific language governing permissions and
|
|
18486
18486
|
* limitations under the License.
|
|
18487
18487
|
* =============================================================================
|
|
18488
|
-
*/const
|
|
18488
|
+
*/const HX={kernelName:es,backendName:"cpu",kernelFunc:function e(t){const{inputs:n,backend:s}=t,{x:r}=n;if("string"===r.dtype)throw new Error("onesLike is not supported for string tensors");if("complex64"===r.dtype){const t=oy({inputs:{input:r},backend:s}),n=e({inputs:{x:t},backend:s}),a=Qq({inputs:{input:r},backend:s}),i=VX({inputs:{x:a},backend:s}),o=ny({inputs:{real:n,imag:i},backend:s});return s.disposeIntermediateTensorInfo(t),s.disposeIntermediateTensorInfo(n),s.disposeIntermediateTensorInfo(a),s.disposeIntermediateTensorInfo(i),o}return jj({backend:s,attrs:{shape:r.shape,value:1,dtype:r.dtype}})}};
|
|
18489
18489
|
/**
|
|
18490
18490
|
* @license
|
|
18491
18491
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18501,7 +18501,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18501
18501
|
* See the License for the specific language governing permissions and
|
|
18502
18502
|
* limitations under the License.
|
|
18503
18503
|
* =============================================================================
|
|
18504
|
-
*/function
|
|
18504
|
+
*/function qX(e){const{inputs:t,backend:n,attrs:s}=e,{axis:r}=s;if(1===t.length)return Pj({inputs:{input:t[0]},backend:n,attrs:{dim:r}});const a=t[0].shape,i=t[0].dtype;t.forEach((e=>{ge(a,e.shape,"All tensors passed to stack must have matching shapes"),me(i===e.dtype,(()=>"All tensors passed to stack must have matching dtypes"))}));const o=[],u=t.map((e=>{const t=Pj({inputs:{input:e},backend:n,attrs:{dim:r}});return o.push(t),t})),l=Zq({inputs:u,backend:n,attrs:{axis:r}});return o.forEach((e=>n.disposeIntermediateTensorInfo(e))),l}const jX={kernelName:ns,backendName:"cpu",kernelFunc:qX};
|
|
18505
18505
|
/**
|
|
18506
18506
|
* @license
|
|
18507
18507
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18517,7 +18517,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18517
18517
|
* See the License for the specific language governing permissions and
|
|
18518
18518
|
* limitations under the License.
|
|
18519
18519
|
* =============================================================================
|
|
18520
|
-
*/const
|
|
18520
|
+
*/const XX={kernelName:ss,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{paddings:a,constantValue:i}=s;Jg(r,"pad");const o=a.map(((e,t)=>e[0]+r.shape[t]+e[1])),u=a.map((e=>e[0])),l=n.data.get(r.dataId).values,c=be(r.shape),h=r.shape.length,d=Le(r.shape),p=be(o),f=o.length,m=Le(o),g=$e(r.dtype,p);0!==i&&g.fill(i);for(let e=0;e<c;e++){const t=qe(e,h,d).map(((e,t)=>e+u[t]));g[He(t,f,m)]=l[e]}return{dataId:n.write(g,o,r.dtype),shape:o,dtype:r.dtype}}},KX=ty(((e,t)=>Math.pow(e,t))),YX=dy(rs,KX),QX={kernelName:rs,backendName:"cpu",kernelFunc:YX};
|
|
18521
18521
|
/**
|
|
18522
18522
|
* @license
|
|
18523
18523
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18533,7 +18533,7 @@ function AX(e){const{inputs:t,backend:n,attrs:s}=e,{logits:r}=t,{dim:a}=s,i=r.sh
|
|
|
18533
18533
|
* See the License for the specific language governing permissions and
|
|
18534
18534
|
* limitations under the License.
|
|
18535
18535
|
* =============================================================================
|
|
18536
|
-
*/const
|
|
18536
|
+
*/const JX={kernelName:os,backendName:"cpu",kernelFunc:
|
|
18537
18537
|
/**
|
|
18538
18538
|
* @license
|
|
18539
18539
|
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
@@ -18566,7 +18566,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{paramsNestedSplits:r,paramsDens
|
|
|
18566
18566
|
* See the License for the specific language governing permissions and
|
|
18567
18567
|
* limitations under the License.
|
|
18568
18568
|
* =============================================================================
|
|
18569
|
-
*/const
|
|
18569
|
+
*/const ZX={kernelName:us,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{starts:s,limits:r,deltas:a}=t,i=n.data.get(s.dataId).values,o=n.data.get(r.dataId).values,u=n.data.get(a.dataId).values,[l,c]=Mb(i,s.shape,s.dtype,o,r.shape,u,a.shape);return[n.makeTensorInfo([l.length],"int32",l),n.makeTensorInfo([c.length],s.dtype,c)]}};
|
|
18570
18570
|
/**
|
|
18571
18571
|
* @license
|
|
18572
18572
|
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
@@ -18582,7 +18582,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{paramsNestedSplits:r,paramsDens
|
|
|
18582
18582
|
* See the License for the specific language governing permissions and
|
|
18583
18583
|
* limitations under the License.
|
|
18584
18584
|
* =============================================================================
|
|
18585
|
-
*/const
|
|
18585
|
+
*/const eK={kernelName:ls,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{shape:r,values:a,defaultValue:i,rowPartitionTensors:o}=t,{rowPartitionTypes:u}=s,l=n.data.get(r.dataId).values,c=n.data.get(a.dataId).values,h=n.data.get(i.dataId).values,d=o.map((e=>n.data.get(e.dataId).values)),p=o.map((e=>e.shape)),[f,m]=Bb(l,r.shape,c,a.shape,a.dtype,h,i.shape,d,p,u);return n.makeTensorInfo(f,a.dtype,m)}};
|
|
18586
18586
|
/**
|
|
18587
18587
|
* @license
|
|
18588
18588
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18598,7 +18598,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{paramsNestedSplits:r,paramsDens
|
|
|
18598
18598
|
* See the License for the specific language governing permissions and
|
|
18599
18599
|
* limitations under the License.
|
|
18600
18600
|
* =============================================================================
|
|
18601
|
-
*/const
|
|
18601
|
+
*/const tK={kernelName:cs,backendName:"cpu",kernelFunc:function(e){const{backend:t,attrs:n}=e,{start:s,stop:r,dtype:a,step:i}=n,o=Wb(s,r,i,a);return t.makeTensorInfo([o.length],a,o)}},nK=Sy(ds,(e=>1/e)),sK={kernelName:ds,backendName:"cpu",kernelFunc:nK};
|
|
18602
18602
|
/**
|
|
18603
18603
|
* @license
|
|
18604
18604
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18614,7 +18614,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{paramsNestedSplits:r,paramsDens
|
|
|
18614
18614
|
* See the License for the specific language governing permissions and
|
|
18615
18615
|
* limitations under the License.
|
|
18616
18616
|
* =============================================================================
|
|
18617
|
-
*/const
|
|
18617
|
+
*/const rK={kernelName:ys,backendName:"cpu",kernelFunc:
|
|
18618
18618
|
/**
|
|
18619
18619
|
* @license
|
|
18620
18620
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18647,7 +18647,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{images:r}=t,{alignCorners:a,hal
|
|
|
18647
18647
|
* See the License for the specific language governing permissions and
|
|
18648
18648
|
* limitations under the License.
|
|
18649
18649
|
* =============================================================================
|
|
18650
|
-
*/const
|
|
18650
|
+
*/const aK={kernelName:bs,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{images:r,dy:a}=t,{alignCorners:i}=s;Jg([a,r],"resizeBilinearGrad");const o=Le(r.shape),[u,l,c,h]=r.shape,[,d,p]=a.shape,f=new Float32Array(u*l*c*h),m=[i&&d>1?l-1:l,i&&p>1?c-1:c],g=[i&&d>1?d-1:d,i&&p>1?p-1:p],y=m[0]/g[0],b=m[1]/g[1],x=n.data.get(a.dataId).values;let w=0;for(let e=0;e<u;e++){const t=e*o[0];for(let e=0;e<d;e++){const n=e*y,s=Math.floor(n),r=Math.min(Math.ceil(n),l-1),a=t+s*o[1],i=t+r*o[1],u=n-s,d=1-u;for(let e=0;e<p;e++){const t=e*b,n=Math.floor(t),s=Math.min(Math.ceil(t),c-1),r=t-n,l=1-r,p=a+n*o[2],m=a+s*o[2],g=i+n*o[2],y=i+s*o[2],k=d*l,v=d*r,I=u*l,S=u*r;for(let e=0;e<h;e++){const t=x[w++];f[p+e]+=t*k,f[m+e]+=t*v,f[g+e]+=t*I,f[y+e]+=t*S}}}}return n.makeTensorInfo([u,c,l,h],"float32",f)}};
|
|
18651
18651
|
/**
|
|
18652
18652
|
* @license
|
|
18653
18653
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18663,7 +18663,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{images:r}=t,{alignCorners:a,hal
|
|
|
18663
18663
|
* See the License for the specific language governing permissions and
|
|
18664
18664
|
* limitations under the License.
|
|
18665
18665
|
* =============================================================================
|
|
18666
|
-
*/const
|
|
18666
|
+
*/const iK={kernelName:ms,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{images:r}=t,{alignCorners:a,halfPixelCenters:i,size:o}=s;Jg(r,"resizeNearestNeighbor");const u=Le(r.shape),[l,c]=o,[h,d,p,f]=r.shape,m=n.data.get(r.dataId).values,g=new Float32Array(h*l*c*f),y=[a&&l>1?d-1:d,a&&c>1?p-1:p],b=[a&&l>1?l-1:l,a&&c>1?c-1:c],x=y[0]/b[0],w=y[1]/b[1];let k=0;for(let e=0;e<h;e++){const t=e*u[0];for(let e=0;e<l;e++){const n=i?x*(e+.5):x*e;let s=Math.min(d-1,a?Math.round(n):Math.floor(n));i&&(s=Math.max(0,s));const r=t+s*u[1];for(let e=0;e<c;e++){const t=i?w*(e+.5):w*e;let n=Math.min(p-1,a?Math.round(t):Math.floor(t));i&&(n=Math.max(0,n));const s=r+n*u[2];for(let e=0;e<f;e++){const t=m[s+e];g[k++]=t}}}}return n.makeTensorInfo([h,l,c,f],r.dtype,g)}};
|
|
18667
18667
|
/**
|
|
18668
18668
|
* @license
|
|
18669
18669
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18679,7 +18679,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{images:r}=t,{alignCorners:a,hal
|
|
|
18679
18679
|
* See the License for the specific language governing permissions and
|
|
18680
18680
|
* limitations under the License.
|
|
18681
18681
|
* =============================================================================
|
|
18682
|
-
*/const
|
|
18682
|
+
*/const oK={kernelName:gs,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{images:r,dy:a}=t,{alignCorners:i}=s;Jg([a,r],"resizeNearestNeighborGrad");const o=Le(r.shape),u=Le(a.shape),[l,c,h,d]=r.shape,[,p,f]=a.shape,m=new Float32Array(l*c*h*d),g=n.data.get(a.dataId).values,y=[i&&p>1?c-1:c,i&&f>1?h-1:h],b=[i&&p>1?p-1:p,i&&f>1?f-1:f],x=y[0]/b[0],w=y[1]/b[1],k=1/x,v=1/w,I=2*Math.ceil(k)+2,S=2*Math.ceil(v)+2;for(let e=0;e<l;e++){const t=e*o[0];for(let e=0;e<c;e++){const n=t+e*o[1],s=Math.floor(e*k),r=Math.floor(s-I/2);for(let s=0;s<h;s++){const a=n+s*o[2],l=Math.floor(s*v),y=Math.floor(l-S/2);for(let n=0;n<d;n++){let o=0;for(let a=0;a<I;a++){const l=a+r;if(l<0||l>=p)continue;const d=t+l*u[1],m=l*x;if(e===Math.min(c-1,i?Math.round(m):Math.floor(m)))for(let e=0;e<S;e++){const t=e+y;if(t<0||t>=f)continue;const r=d+t*u[2],a=t*w;s===Math.min(h-1,i?Math.round(a):Math.floor(a))&&(o+=g[r+n])}}m[a+n]=o}}}}return n.makeTensorInfo(r.shape,r.dtype,m)}};
|
|
18683
18683
|
/**
|
|
18684
18684
|
* @license
|
|
18685
18685
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18695,7 +18695,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{images:r}=t,{alignCorners:a,hal
|
|
|
18695
18695
|
* See the License for the specific language governing permissions and
|
|
18696
18696
|
* limitations under the License.
|
|
18697
18697
|
* =============================================================================
|
|
18698
|
-
*/const
|
|
18698
|
+
*/const uK={kernelName:ws,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{dims:a}=s;Jg(r,"reverse");const i=r.shape.length,o=Ne(a,r.shape);if(0===i)return ay({inputs:{x:r},backend:n});const u=new Ra(r.shape,r.dtype),l=n.bufferSync(r);for(let e=0;e<u.size;e++){const t=u.indexToLoc(e),n=t.slice();o.forEach((e=>n[e]=r.shape[e]-1-n[e])),u.set(l.get(...n),...t)}return n.makeTensorInfo(u.shape,u.dtype,u.values)}},lK={kernelName:cr,backendName:"cpu",kernelFunc:({inputs:e,attrs:t,backend:n})=>{const{image:s}=e,{radians:r,fillValue:a,center:i}=t,o=n,u=$e(s.dtype,be(s.shape)),[l,c,h,d]=s.shape,[p,f]=Ef(i,c,h),m=Math.sin(r),g=Math.cos(r),y=o.data.get(s.dataId).values;for(let e=0;e<l;e++){const t=e*h*c*d;for(let e=0;e<c;e++){const n=e*(h*d);for(let s=0;s<h;s++){const r=s*d;for(let i=0;i<d;i++){const o=[l,e,s,i],b=o[2],x=o[1];let w=(b-p)*g-(x-f)*m,k=(b-p)*m+(x-f)*g;w=Math.round(w+p),k=Math.round(k+f);let v=a;if("number"!=typeof a&&(v=3===i?255:a[i]),w>=0&&w<h&&k>=0&&k<c){v=y[t+k*(h*d)+w*d+i]}u[t+n+r+i]=v}}}}return{dataId:o.write(u,s.shape,s.dtype),shape:s.shape,dtype:s.dtype}}},cK=Sy(ks,(e=>{const t=Math.floor(e);return e-t<.5?Math.floor(e):e-t>.5?Math.ceil(e):t%2==0?t:t+1})),hK={kernelName:ks,backendName:"cpu",kernelFunc:cK};
|
|
18699
18699
|
/**
|
|
18700
18700
|
* @license
|
|
18701
18701
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18711,7 +18711,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{images:r}=t,{alignCorners:a,hal
|
|
|
18711
18711
|
* See the License for the specific language governing permissions and
|
|
18712
18712
|
* limitations under the License.
|
|
18713
18713
|
* =============================================================================
|
|
18714
|
-
*/const
|
|
18714
|
+
*/const dK={kernelName:Is,backendName:"cpu",kernelFunc:
|
|
18715
18715
|
/**
|
|
18716
18716
|
* @license
|
|
18717
18717
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18744,7 +18744,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{indices:r,updates:a}=t,{shape:i
|
|
|
18744
18744
|
* See the License for the specific language governing permissions and
|
|
18745
18745
|
* limitations under the License.
|
|
18746
18746
|
* =============================================================================
|
|
18747
|
-
*/function
|
|
18747
|
+
*/function pK(e,t){let n=0,s=e.length,r=0;for(;n<s;)r=Math.floor((n+s)/2),e[r]<t?n=r+1:s=r;return s}function fK(e,t){let n=0,s=e.length,r=0;for(;n<s;)r=Math.floor((n+s)/2),e[r]<=t?n=r+1:s=r;return s}const mK={kernelName:Cs,backendName:"cpu",kernelFunc:
|
|
18748
18748
|
/**
|
|
18749
18749
|
* @license
|
|
18750
18750
|
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
@@ -18761,7 +18761,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{indices:r,updates:a}=t,{shape:i
|
|
|
18761
18761
|
* limitations under the License.
|
|
18762
18762
|
* =============================================================================
|
|
18763
18763
|
*/
|
|
18764
|
-
function(e){const{inputs:t,backend:n,attrs:s}=e,{sortedSequence:r,values:a}=t,{side:i}=s,o=function(e,t,n,s,r,a){const i=Re("int32",n*r);for(let o=0;o<n;++o){const n=e.slice(o*s,(o+1)*s),u=o*r;for(let e=0;e<r;++e)i[u+e]="left"===a?
|
|
18764
|
+
function(e){const{inputs:t,backend:n,attrs:s}=e,{sortedSequence:r,values:a}=t,{side:i}=s,o=function(e,t,n,s,r,a){const i=Re("int32",n*r);for(let o=0;o<n;++o){const n=e.slice(o*s,(o+1)*s),u=o*r;for(let e=0;e<r;++e)i[u+e]="left"===a?pK(n,t[e+u]):fK(n,t[e+u])}return i}(n.data.get(r.dataId).values,n.data.get(a.dataId).values,r.shape[0],r.shape[1],a.shape[1],i);return n.makeTensorInfo(a.shape,"int32",o)}};
|
|
18765
18765
|
/**
|
|
18766
18766
|
* @license
|
|
18767
18767
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18777,7 +18777,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{sortedSequence:r,values:a}=t,{s
|
|
|
18777
18777
|
* See the License for the specific language governing permissions and
|
|
18778
18778
|
* limitations under the License.
|
|
18779
18779
|
* =============================================================================
|
|
18780
|
-
*/const
|
|
18780
|
+
*/const gK={kernelName:Ns,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{condition:s,t:r,e:a}=t;Jg([s,r,a],"select");const i=s.shape.length,o=n.data.get(s.dataId).values,u=n.data.get(r.dataId).values,l=n.data.get(a.dataId).values,c=Wa(r.dtype,a.dtype),h=Ue(be(r.shape),c);let d=0;const p=0===i||i>1||1===r.shape.length?1:be(r.shape.slice(1));for(let e=0;e<o.length;e++)for(let t=0;t<p;t++)1===o[e]?h[d++]=u[e]:h[d++]=l[e];return n.makeTensorInfo(r.shape,c,h)}},yK=Of,bK=Lf,xK=Sy(Ts,(e=>e>=0?bK*e:yK*(Math.exp(e)-1))),wK={kernelName:Ts,backendName:"cpu",kernelFunc:xK},kK=Sy(As,(e=>e<0?-1:e>0?1:0)),vK={kernelName:As,backendName:"cpu",kernelFunc:kK},IK=Sy(Rs,(e=>Math.sin(e))),SK={kernelName:Rs,backendName:"cpu",kernelFunc:IK},CK=Sy(Es,(e=>Math.sinh(e))),NK={kernelName:Es,backendName:"cpu",kernelFunc:CK},TK=Math.log(1.1920928955078125e-7)+2,$K=Sy(Fs,(e=>{const t=e>-TK,n=e<TK,s=Math.exp(e);let r;return r=n?s:t?e:Math.log(1+s),r})),RK={kernelName:Fs,backendName:"cpu",kernelFunc:$K};
|
|
18781
18781
|
/**
|
|
18782
18782
|
* @license
|
|
18783
18783
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18793,7 +18793,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{sortedSequence:r,values:a}=t,{s
|
|
|
18793
18793
|
* See the License for the specific language governing permissions and
|
|
18794
18794
|
* limitations under the License.
|
|
18795
18795
|
* =============================================================================
|
|
18796
|
-
*/const
|
|
18796
|
+
*/const EK={kernelName:Os,backendName:"cpu",kernelFunc:
|
|
18797
18797
|
/**
|
|
18798
18798
|
* @license
|
|
18799
18799
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18810,7 +18810,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{sortedSequence:r,values:a}=t,{s
|
|
|
18810
18810
|
* limitations under the License.
|
|
18811
18811
|
* =============================================================================
|
|
18812
18812
|
*/
|
|
18813
|
-
function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i}=s;Jg([r],"spaceToBatchND");const o=be(a),u=[[0,0]];u.push(...i);for(let e=1+a.length;e<r.shape.length;++e)u.push([0,0]);const l=
|
|
18813
|
+
function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i}=s;Jg([r],"spaceToBatchND");const o=be(a),u=[[0,0]];u.push(...i);for(let e=1+a.length;e<r.shape.length;++e)u.push([0,0]);const l=XX.kernelFunc({inputs:{x:r},backend:n,attrs:{paddings:u,constantValue:0}}),c=Af(l.shape,a,o,!1),h=_f(c.length,a.length,!1),d=Ff(l.shape,a,o,!1),p=dq({inputs:{x:l},backend:n,attrs:{shape:c}}),f=Nb({inputs:{x:p},backend:n,attrs:{perm:h}}),m=dq({inputs:{x:f},backend:n,attrs:{shape:d}});return n.disposeIntermediateTensorInfo(l),n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(f),m}};
|
|
18814
18814
|
/**
|
|
18815
18815
|
* @license
|
|
18816
18816
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -18826,7 +18826,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i
|
|
|
18826
18826
|
* See the License for the specific language governing permissions and
|
|
18827
18827
|
* limitations under the License.
|
|
18828
18828
|
* =============================================================================
|
|
18829
|
-
*/const
|
|
18829
|
+
*/const AK={kernelName:zs,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{indices:s,values:r,denseShape:a,defaultValue:i}=t;if(1!==a.shape.length)throw new Error(`Dense shape must be a vector, saw:\n ${a.shape}`);if(2!==s.shape.length)throw new Error(`Indices must be a matrix, saw:\n ${s.shape}`);if(1!==r.shape.length)throw new Error(`Values must be a vector, saw:\n ${r.shape}`);if(0!==i.shape.length)throw new Error(`Default value must be a scalar, saw:\n ${i.shape}`);const o=n.data.get(s.dataId).values,u=n.data.get(r.dataId).values,l=n.data.get(a.dataId).values,c=n.data.get(i.dataId).values[0],[h,d,p,f,m]=Jb(o,s.shape,s.dtype,u,r.dtype,l,c);return[n.makeTensorInfo(d,s.dtype,h),n.makeTensorInfo([d[0]],r.dtype,p),n.makeTensorInfo([f.length],"bool",new Uint8Array(f.map((e=>Number(e))))),n.makeTensorInfo([m.length],s.dtype,new Int32Array(m))]}};
|
|
18830
18830
|
/**
|
|
18831
18831
|
* @license
|
|
18832
18832
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -18842,7 +18842,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i
|
|
|
18842
18842
|
* See the License for the specific language governing permissions and
|
|
18843
18843
|
* limitations under the License.
|
|
18844
18844
|
* =============================================================================
|
|
18845
|
-
*/const
|
|
18845
|
+
*/const _K={kernelName:Bs,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{inputIndices:s,inputShape:r,newShape:a}=t;if(2!==s.shape.length)throw new Error(`Input indices should be a matrix but received shape\n ${s.shape}`);if(1!==r.shape.length)throw new Error(`Input shape should be a vector but received shape\n ${r.shape}`);if(1!==a.shape.length)throw new Error(`Target shape should be a vector but received shape ${a.shape}`);const i=Array.from(n.data.get(r.dataId).values),o=n.data.get(s.dataId).values,u=Array.from(n.data.get(a.dataId).values),[l,c,h]=Zb(o,s.shape,s.dtype,i,u);return[n.makeTensorInfo(c,s.dtype,l),n.makeTensorInfo([h.length],a.dtype,new Int32Array(h))]}};
|
|
18846
18846
|
/**
|
|
18847
18847
|
* @license
|
|
18848
18848
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -18858,7 +18858,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i
|
|
|
18858
18858
|
* See the License for the specific language governing permissions and
|
|
18859
18859
|
* limitations under the License.
|
|
18860
18860
|
* =============================================================================
|
|
18861
|
-
*/const
|
|
18861
|
+
*/const FK={kernelName:Ws,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{data:s,indices:r,segmentIds:a}=t;if(s.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(1!==r.shape.length)throw new Error(`Indices should be a vector but received shape\n ${r.shape}`);if(1!==a.shape.length)throw new Error(`Segment ids should be a vector but received shape\n ${a.shape}`);if(r.shape[0]!==a.shape[0])throw new Error("segmentIds and indices should have same size.");const i=n.data.get(s.dataId).values,o=n.data.get(r.dataId).values,u=n.data.get(a.dataId).values,[l,c]=ex(i,s.shape,s.dtype,o,u,!0);return n.makeTensorInfo(c,s.dtype,l)}};
|
|
18862
18862
|
/**
|
|
18863
18863
|
* @license
|
|
18864
18864
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -18874,7 +18874,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i
|
|
|
18874
18874
|
* See the License for the specific language governing permissions and
|
|
18875
18875
|
* limitations under the License.
|
|
18876
18876
|
* =============================================================================
|
|
18877
|
-
*/const
|
|
18877
|
+
*/const DK={kernelName:Us,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n}=e,{data:s,indices:r,segmentIds:a}=t;if(s.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(1!==r.shape.length)throw new Error(`Indices should be a vector but received shape\n ${r.shape}`);if(1!==a.shape.length)throw new Error(`Segment ids should be a vector but received shape\n ${a.shape}`);if(r.shape[0]!==a.shape[0])throw new Error("segmentIds and indices should have same size.");const i=n.data.get(s.dataId).values,o=n.data.get(r.dataId).values,u=n.data.get(a.dataId).values,[l,c]=ex(i,s.shape,s.dtype,o,u);return n.makeTensorInfo(c,s.dtype,l)}};
|
|
18878
18878
|
/**
|
|
18879
18879
|
* @license
|
|
18880
18880
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18890,7 +18890,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i
|
|
|
18890
18890
|
* See the License for the specific language governing permissions and
|
|
18891
18891
|
* limitations under the License.
|
|
18892
18892
|
* =============================================================================
|
|
18893
|
-
*/const
|
|
18893
|
+
*/const MK={kernelName:Vs,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{sparseIndices:r,sparseValues:a,defaultValue:i}=t,{outputShape:o}=s,{sliceRank:u,numUpdates:l,sliceSize:c,strides:h,outputSize:d}=Vh(0,r,o),p=!1,f=n.bufferSync(r);let m;switch(a.dtype){case"bool":m=Hb(f,n.bufferSync(a),o,d,c,l,u,h,Boolean(n.data.get(i.dataId).values[0]),p);break;case"float32":m=Hb(f,n.bufferSync(a),o,d,c,l,u,h,n.data.get(i.dataId).values[0],p);break;case"int32":m=Hb(f,n.bufferSync(a),o,d,c,l,u,h,n.data.get(i.dataId).values[0],p);break;case"string":m=Hb(f,n.bufferSync(a),o,d,c,l,u,h,ma(n.data.get(i.dataId).values[0]),p);break;default:throw new Error(`Unsupported type ${a.dtype}`)}return n.makeTensorInfo(o,m.dtype,m.values)}};
|
|
18894
18894
|
/**
|
|
18895
18895
|
* @license
|
|
18896
18896
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18906,7 +18906,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i
|
|
|
18906
18906
|
* See the License for the specific language governing permissions and
|
|
18907
18907
|
* limitations under the License.
|
|
18908
18908
|
* =============================================================================
|
|
18909
|
-
*/const
|
|
18909
|
+
*/const OK={kernelName:Ls,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{numOrSizeSplits:a,axis:i}=s,o=Ne(i,r.shape)[0],u=um(r,a,o),l=new Array(r.shape.length).fill(0),c=r.shape.slice();return u.map((e=>{const t=[...c];t[o]=e;const s=Yb({inputs:{x:r},backend:n,attrs:{begin:l,size:t}});return l[o]+=e,s}))}},LK={kernelName:Hs,backendName:"cpu",kernelFunc:({inputs:e,backend:t})=>{const{x:n}=e,s=t;Jg(n,"square");const r=s.data.get(n.dataId).values,a=new Float32Array(r.length);for(let e=0;e<r.length;++e){const t=r[e];a[e]=t*t}return{dataId:s.write(a,n.shape,n.dtype),shape:n.shape,dtype:n.dtype}}},PK=Sy(ur,((e,t)=>{const n=t;return isNaN(e)?NaN:e>0?1:n.alpha})),zK={kernelName:ur,backendName:"cpu",kernelFunc:PK};
|
|
18910
18910
|
/**
|
|
18911
18911
|
* @license
|
|
18912
18912
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -18922,7 +18922,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i
|
|
|
18922
18922
|
* See the License for the specific language governing permissions and
|
|
18923
18923
|
* limitations under the License.
|
|
18924
18924
|
* =============================================================================
|
|
18925
|
-
*/const
|
|
18925
|
+
*/const BK={kernelName:js,backendName:"cpu",kernelFunc:
|
|
18926
18926
|
/**
|
|
18927
18927
|
* @license
|
|
18928
18928
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -18939,7 +18939,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{blockShape:a,paddings:i
|
|
|
18939
18939
|
* limitations under the License.
|
|
18940
18940
|
* =============================================================================
|
|
18941
18941
|
*/
|
|
18942
|
-
function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{begin:a,end:i,strides:o,beginMask:u,endMask:l,ellipsisMask:c,newAxisMask:h,shrinkAxisMask:d}=s;Jg(r,"stridedSlice");const{finalShapeSparse:p,finalShape:f,isIdentity:m,sliceDim0:g,isSimpleSlice:y,begin:b,end:x,strides:w}=mf(r.shape,a,i,o,u,l,c,h,d);let k;if(m)k=
|
|
18942
|
+
function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{begin:a,end:i,strides:o,beginMask:u,endMask:l,ellipsisMask:c,newAxisMask:h,shrinkAxisMask:d}=s;Jg(r,"stridedSlice");const{finalShapeSparse:p,finalShape:f,isIdentity:m,sliceDim0:g,isSimpleSlice:y,begin:b,end:x,strides:w}=mf(r.shape,a,i,o,u,l,c,h,d);let k;if(m)k=dq({inputs:{x:r},backend:n,attrs:{shape:f}});else if(g||y){me(r.shape.length>=1,(()=>`Input must have rank at least 1, got: ${r.shape.length}`));const e=nf(b,x,w),t=Yb({inputs:{x:r},backend:n,attrs:{begin:b,size:e}});k=dq({inputs:{x:t},backend:n,attrs:{shape:f}}),n.disposeIntermediateTensorInfo(t)}else{const e=cx(p,n.bufferSync(r),w,b);k=n.makeTensorInfo(f,e.dtype,e.values)}return k}};
|
|
18943
18943
|
/**
|
|
18944
18944
|
* @license
|
|
18945
18945
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -18955,7 +18955,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{begin:a,end:i,strides:o
|
|
|
18955
18955
|
* See the License for the specific language governing permissions and
|
|
18956
18956
|
* limitations under the License.
|
|
18957
18957
|
* =============================================================================
|
|
18958
|
-
*/const
|
|
18958
|
+
*/const WK={kernelName:Xs,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{separator:r,nGramWidths:a,leftPad:i,rightPad:o,padWidth:u,preserveShortSequences:l}=s,{data:c,dataSplits:h}=t,d=n.data.get(c.dataId).values,p=n.data.get(h.dataId).values,[f,m]=dx(d,p,r,a,i,o,u,l);return[n.makeTensorInfo([f.length],"string",f),n.makeTensorInfo(h.shape,"int32",m)]}};
|
|
18959
18959
|
/**
|
|
18960
18960
|
* @license
|
|
18961
18961
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -18971,7 +18971,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{begin:a,end:i,strides:o
|
|
|
18971
18971
|
* See the License for the specific language governing permissions and
|
|
18972
18972
|
* limitations under the License.
|
|
18973
18973
|
* =============================================================================
|
|
18974
|
-
*/const
|
|
18974
|
+
*/const UK={kernelName:Ks,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{skipEmpty:r}=s,{input:a,delimiter:i}=t;if("string"!==a.dtype)throw new Error("Input must be of datatype string");if(1!==a.shape.length)throw new Error(`Input must be a vector, got shape: ${a.shape}`);if(0!==i.shape.length)throw new Error(`Delimiter must be a scalar, got shape: ${i.shape}`);const o=n.data.get(a.dataId).values,u=n.data.get(i.dataId).values[0],[l,c,h]=fx(o,u,r),d=c.length;return[n.makeTensorInfo([d,2],"int32",l),n.makeTensorInfo([d],"string",c),n.makeTensorInfo([2],"int32",new Int32Array(h))]}};
|
|
18975
18975
|
/**
|
|
18976
18976
|
* @license
|
|
18977
18977
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -18987,7 +18987,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{begin:a,end:i,strides:o
|
|
|
18987
18987
|
* See the License for the specific language governing permissions and
|
|
18988
18988
|
* limitations under the License.
|
|
18989
18989
|
* =============================================================================
|
|
18990
|
-
*/const
|
|
18990
|
+
*/const VK={kernelName:Ys,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{numBuckets:r}=s,{input:a}=t;if("string"!==a.dtype)throw new Error("Input must be of datatype string");if(r<=0)throw new Error("Number of buckets must be at least 1");const i=mx(n.data.get(a.dataId).values,r);return n.makeTensorInfo(a.shape,"int32",i)}},GK=Sy(Js,(e=>Math.tan(e))),HK={kernelName:Js,backendName:"cpu",kernelFunc:GK},qK=Sy(Zs,(e=>Math.tanh(e)));
|
|
18991
18991
|
/**
|
|
18992
18992
|
* @license
|
|
18993
18993
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -19003,7 +19003,7 @@ function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{begin:a,end:i,strides:o
|
|
|
19003
19003
|
* See the License for the specific language governing permissions and
|
|
19004
19004
|
* limitations under the License.
|
|
19005
19005
|
* =============================================================================
|
|
19006
|
-
*/const
|
|
19006
|
+
*/const jK={kernelName:Ss,backendName:"cpu",kernelFunc:
|
|
19007
19007
|
/**
|
|
19008
19008
|
* @license
|
|
19009
19009
|
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
@@ -19036,7 +19036,7 @@ function(e){const{inputs:t,backend:n}=e,{tensor:s,indices:r,updates:a}=t,{sliceR
|
|
|
19036
19036
|
* See the License for the specific language governing permissions and
|
|
19037
19037
|
* limitations under the License.
|
|
19038
19038
|
* =============================================================================
|
|
19039
|
-
*/const
|
|
19039
|
+
*/const XK={kernelName:er,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{reps:a}=s;Jg(r,"tile");const i=wx(n.bufferSync(r),a);return n.makeTensorInfo(i.shape,i.dtype,i.values)}};
|
|
19040
19040
|
/**
|
|
19041
19041
|
* @license
|
|
19042
19042
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -19052,7 +19052,7 @@ function(e){const{inputs:t,backend:n}=e,{tensor:s,indices:r,updates:a}=t,{sliceR
|
|
|
19052
19052
|
* See the License for the specific language governing permissions and
|
|
19053
19053
|
* limitations under the License.
|
|
19054
19054
|
* =============================================================================
|
|
19055
|
-
*/const
|
|
19055
|
+
*/const KK={kernelName:tr,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r}=t,{k:a,sorted:i}=s;Jg(r,"topk");const o=n.data.get(r.dataId).values,[u,l]=Ix(o,r.shape,r.dtype,a,i);return[n.makeTensorInfo(u.shape,u.dtype,u.values),n.makeTensorInfo(l.shape,l.dtype,l.values)]}};
|
|
19056
19056
|
/**
|
|
19057
19057
|
* @license
|
|
19058
19058
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -19068,7 +19068,7 @@ function(e){const{inputs:t,backend:n}=e,{tensor:s,indices:r,updates:a}=t,{sliceR
|
|
|
19068
19068
|
* See the License for the specific language governing permissions and
|
|
19069
19069
|
* limitations under the License.
|
|
19070
19070
|
* =============================================================================
|
|
19071
|
-
*/const
|
|
19071
|
+
*/const YK={kernelName:nr,backendName:"cpu",kernelFunc:function(e){const{inputs:t,attrs:n,backend:s}=e,{image:r,transforms:a}=t,{interpolation:i,fillMode:o,fillValue:u,outputShape:l}=n,[c,h,d,p]=r.shape,[f,m]=null!=l?l:[h,d],g=[c,f,m,p],y=Le(r.shape),b=y[0],x=y[1],w=y[2],k=Le(g),v=k[0],I=k[1],S=k[2],C=$e(r.dtype,be(g));C.fill(u);const N=s.data.get(r.dataId).values,T=s.data.get(a.dataId).values;for(let e=0;e<c;++e){const t=1===a.shape[0]?T:T.subarray(8*e,8*e+8);for(let n=0;n<f;++n)for(let s=0;s<m;++s)for(let r=0;r<p;++r){let a;const l=t[6]*s+t[7]*n+1;if(0===l)continue;const c=(t[0]*s+t[1]*n+t[2])/l,p=(t[3]*s+t[4]*n+t[5])/l,f=QK(c,d,o),m=QK(p,h,o);switch(i){case"nearest":a=ZK(N,h,d,b,x,w,e,m,f,r,u);break;case"bilinear":a=eY(N,h,d,b,x,w,e,m,f,r,u);break;default:throw new Error(`Error in Transform: Expect 'nearest' or 'bilinear', but got ${i}`)}C[e*v+n*I+s*S+r]=a}return s.makeTensorInfo(g,r.dtype,C)}return{dataId:s.write(C,g,r.dtype),shape:r.shape,dtype:r.dtype}}};function QK(e,t,n){switch(n){case"reflect":return function(e,t){let n=e;if(n<0)if(t<=1)n=0;else{const e=2*t;n<e&&(n=e*Math.trunc(-n/e)+n),n=n<-t?n+e:-n-1}else if(n>t-1)if(t<=1)n=0;else{const e=2*t;n-=e*Math.trunc(n/e),n>=t&&(n=e-n-1)}return he(0,n,t-1)}(e,t);case"wrap":return function(e,t){let n=e;if(n<0)if(t<=1)n=0;else{const e=t-1;n+=t*(Math.trunc(-n/e)+1)}else if(n>t-1)if(t<=1)n=0;else{const e=t-1;n-=t*Math.trunc(n/e)}return he(0,n,t-1)}(e,t);case"nearest":return function(e,t){return he(0,e,t-1)}(e,t);default:return function(e,t){return e}(e)}}function JK(e,t,n,s,r,a,i,o,u,l,c){return 0<=o&&o<t&&0<=u&&u<n?e[i*s+o*r+u*a+l]:c}function ZK(e,t,n,s,r,a,i,o,u,l,c){return JK(e,t,n,s,r,a,i,Math.round(o),Math.round(u),l,c)}function eY(e,t,n,s,r,a,i,o,u,l,c){const h=Math.floor(o),d=Math.floor(u),p=h+1,f=d+1;return(p-o)*((f-u)*JK(e,t,n,s,r,a,i,h,d,l,c)+(u-d)*JK(e,t,n,s,r,a,i,h,f,l,c))+(o-h)*((f-u)*JK(e,t,n,s,r,a,i,p,d,l,c)+(u-d)*JK(e,t,n,s,r,a,i,p,f,l,c))}
|
|
19072
19072
|
/**
|
|
19073
19073
|
* @license
|
|
19074
19074
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -19084,7 +19084,7 @@ function(e){const{inputs:t,backend:n}=e,{tensor:s,indices:r,updates:a}=t,{sliceR
|
|
|
19084
19084
|
* See the License for the specific language governing permissions and
|
|
19085
19085
|
* limitations under the License.
|
|
19086
19086
|
* =============================================================================
|
|
19087
|
-
*/const
|
|
19087
|
+
*/const tY={kernelName:rr,backendName:"cpu",kernelFunc:function(e){const{inputs:t,attrs:n,backend:s}=e,{axis:r}=n,{x:a}=t;Jg(a,"unique");const i=s.data.get(a.dataId).values,{outputValues:o,outputShape:u,indices:l}=Sx(i,r,a.shape,a.dtype);return[s.makeTensorInfo(u,a.dtype,o),s.makeTensorInfo([l.length],"int32",l)]}};
|
|
19088
19088
|
/**
|
|
19089
19089
|
* @license
|
|
19090
19090
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -19100,7 +19100,7 @@ function(e){const{inputs:t,backend:n}=e,{tensor:s,indices:r,updates:a}=t,{sliceR
|
|
|
19100
19100
|
* See the License for the specific language governing permissions and
|
|
19101
19101
|
* limitations under the License.
|
|
19102
19102
|
* =============================================================================
|
|
19103
|
-
*/const
|
|
19103
|
+
*/const nY={kernelName:ar,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{value:r}=t;let{axis:a}=s;a<0&&(a+=r.shape.length);const i=r.shape.length,o=r.shape[a],u=new Array(i-1);let l=0;for(let e=0;e<i;e++)e!==a&&(u[l++]=r.shape[e]);const c=new Array(i).fill(0),h=r.shape.slice();h[a]=1;const d=new Array(o);for(let e=0;e<d.length;e++){c[a]=e;const t=Yb({inputs:{x:r},backend:n,attrs:{begin:c,size:h}});d[e]=dq({inputs:{x:t},backend:n,attrs:{shape:u}}),n.disposeIntermediateTensorInfo(t)}return d}};
|
|
19104
19104
|
/**
|
|
19105
19105
|
* @license
|
|
19106
19106
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -19116,7 +19116,7 @@ function(e){const{inputs:t,backend:n}=e,{tensor:s,indices:r,updates:a}=t,{sliceR
|
|
|
19116
19116
|
* See the License for the specific language governing permissions and
|
|
19117
19117
|
* limitations under the License.
|
|
19118
19118
|
* =============================================================================
|
|
19119
|
-
*/const
|
|
19119
|
+
*/const sY={kernelName:ir,backendName:"cpu",kernelFunc:function(e){const{inputs:t,backend:n,attrs:s}=e,{x:r,segmentIds:a}=t,{numSegments:i}=s;Jg(r,"unsortedSegmentSum");const o=[],u=[],l=r.shape.length-a.shape.length;let c=a;for(let e=0;e<l;++e){const t=Pj({inputs:{input:c},backend:n,attrs:{dim:e+1}});c=t,u.push(t)}for(let e=0;e<i;++e){const t=ha(e,"int32"),s=n.makeTensorInfo([],"int32",t),a=Ay({inputs:{a:s,b:c},backend:n}),i=cy({inputs:{x:a},backend:n,attrs:{dtype:"float32"}}),l=bb({inputs:{a:i,b:r},backend:n}),h=Nj({inputs:{x:l},backend:n,attrs:{axis:0,keepDims:!1}});o.push(h),u.push(s),u.push(a),u.push(i),u.push(l),u.push(h)}const h=qX({inputs:o,backend:n,attrs:{axis:0}});return u.forEach((e=>n.disposeIntermediateTensorInfo(e))),h}},rY=[gq,ey,bq,wq,yy,kq,vq,Iq,Sq,Cq,Tq,Rq,Aq,Dq,Oq,Bq,Wq,Uq,Vq,mq,Gq,Hq,qq,vy,jq,hy,$y,Kq,sy,Yq,ej,nj,sj,rj,aj,ij,oj,lj,hj,dj,pj,fj,mj,gj,bj,xj,wj,kj,vj,Ij,Sj,Cj,$j,tq,Rj,_y,Lj,My,zj,Py,qj,Xj,Kj,Wy,Gy,Yj,Qj,Jj,Zj,Ky,Jy,iy,eX,Jq,nX,rX,iX,sq,tb,rb,oX,ub,lX,dX,fX,yX,bX,xX,kX,db,vX,IX,SX,CX,NX,TX,$X,mb,RX,_X,MX,xb,kb,LX,zX,WX,Sb,UX,HX,jX,XX,QX,iq,Rb,JX,ZX,eK,tK,uy,Uj,sK,uq,cq,pq,rK,aK,iK,oK,uK,lK,hK,Gb,dK,mK,gK,wK,Xb,vK,SK,NK,Qb,DX,RK,EK,AK,_K,FK,DK,MK,OK,sx,LK,ix,lx,zK,BK,WK,UK,VK,xx,Tj,HK,{kernelName:Zs,backendName:"cpu",kernelFunc:qK},jK,XK,KK,YK,Tb,tY,nY,sY,GX];
|
|
19120
19120
|
/**
|
|
19121
19121
|
* @license
|
|
19122
19122
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -19132,4 +19132,4 @@ function(e){const{inputs:t,backend:n}=e,{tensor:s,indices:r,updates:a}=t,{sliceR
|
|
|
19132
19132
|
* See the License for the specific language governing permissions and
|
|
19133
19133
|
* limitations under the License.
|
|
19134
19134
|
* =============================================================================
|
|
19135
|
-
*/for(const e of nY)wr(e);var sY=Object.defineProperty,rY=(e,t,n)=>(((e,t,n)=>{t in e?sY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),aY=(e,t,n)=>new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));class iY{constructor(e,t){rY(this,"loadding",!1),rY(this,"tensorflowHModel",null),rY(this,"tensorflowVModel",null),rY(this,"modelType"),rY(this,"baseUrl"),rY(this,"horizontalModelUrl",""),rY(this,"verticalModelUrl",""),this.baseUrl=e,this.modelType=t,this.updateModelUrl(),this.loadModelByType()}updateModelUrl(){}loadModelByType(){return aY(this,null,(function*(){const e=this.modelType===i.Horizontal||this.modelType===i.Both,t=this.modelType===i.Vertical||this.modelType===i.Both;e&&this.loadHorizontalModel(),t&&this.loadVerticalModel()}))}loadHorizontalModel(){return aY(this,null,(function*(){if(""!==this.horizontalModelUrl&&!this.tensorflowHModel&&!this.loadding)try{this.loadding=!0,this.tensorflowHModel=yield XH(this.horizontalModelUrl)}catch(e){console.error("loaded model error."+e.message)}finally{this.loadding=!1}}))}loadVerticalModel(){return aY(this,null,(function*(){if(""!==this.verticalModelUrl&&!this.tensorflowVModel&&!this.loadding)try{this.loadding=!0,this.tensorflowVModel=yield XH(this.verticalModelUrl)}catch(e){console.error(e)}finally{this.loadding=!1}}))}execute(e,t,n,s){return null}}class oY extends iY{constructor(e,t){super(e,t),rY(this,"interfaceData")}updateModelUrl(){this.horizontalModelUrl=this.baseUrl+"models/segment/horizontal/model.json",this.verticalModelUrl=this.baseUrl+"models/segment/vertical/model.json"}execute(e,t,n,s){try{const s=Qp(e),r=s.toFloat(),a=kl(r);let i;if(t>=n){if(!this.tensorflowHModel)return this.loadHorizontalModel(),null;i=this.tensorflowHModel.execute(a)}else{if(!this.tensorflowVModel)return this.loadVerticalModel(),null;i=this.tensorflowVModel.execute(a)}const o=i.mul(255);let u=o.transpose([0,3,1,2]);const l=u.shape[2],c=u.shape[3];let h=u.slice([0,1,0,0],[1,1,l,c]),d=h.dataSync();return this.interfaceData=d,xi([h,u,o,i,a,r,s]),d}catch(e){return null}finally{mi(),xi()}}getInterfaceData(){return this.interfaceData}}class uY extends iY{constructor(e,t){super(e,t)}updateModelUrl(){this.horizontalModelUrl=this.baseUrl+"models/pose/horizontal/model.json",this.verticalModelUrl=this.baseUrl+"models/pose/vertical/model.json"}execute(e,t,n,s){try{let s,r=Qp(e,3),a=r.sub(127.5),i=a.div(128),o=kl(i);if(t>=n){if(!this.tensorflowHModel)return this.loadHorizontalModel(),null;s=this.tensorflowHModel.execute(o)}else{if(!this.tensorflowVModel)return this.loadVerticalModel(),null;s=this.tensorflowVModel.execute(o)}let u=s.transpose([0,3,1,2]),l=u.dataSync();return xi([r,a,i,o,u,s]),l}catch(e){return null}finally{mi(),xi()}}}class lY{static setTfBackend(e=b.Auto){switch(e){case b.WebGL:return this.setWebglBackend();case b.WebGPU:return this.setWebgpuBackend();default:return this.setBackendByAuto()}}static setWebgpuBackend(){return new Promise(((e,t)=>aY(this,null,(function*(){try{"navigator"in globalThis&&"gpu"in navigator?(yield ki("webgpu"),console.info("Inference using WebGPU.")):(yield ki("webgl"),console.info("Inference using WebGL.")),yield vi(),e()}catch(e){console.error("Loaded backend error: "+e.message),t(e)}}))))}static setWebglBackend(){return new Promise(((e,t)=>aY(this,null,(function*(){try{yield ki("webgl"),console.info("Inference using WebGL."),yield vi(),e()}catch(e){console.error("Loaded backend error: "+e.message),t(e)}}))))}static setBackendByAuto(){return new Promise(((e,t)=>aY(this,null,(function*(){try{(yield this.isMacSystem())?"navigator"in globalThis&&"gpu"in navigator?(yield ki("webgpu"),console.info("Inference using WebGPU on macOS.")):(yield ki("webgl"),console.info("Inference using WebGL on macOS.")):(yield ki("webgl"),console.info("Inference using WebGL.")),yield vi(),e()}catch(e){console.error("Loaded backend error: "+e.message),t(e)}}))))}static isMacSystem(){return new Promise((e=>{navigator.userAgentData?navigator.userAgentData.getHighEntropyValues(["platform"]).then((t=>{"macOS"===t.platform?e(!0):e(!1)})):/Mac|iMac|Macintosh/.test(navigator.userAgent)?e(!0):e(!1)}))}}var cY=Object.defineProperty,hY=(e,t,n)=>(((e,t,n)=>{t in e?cY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),dY=(e,t,n)=>new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));let pY=class extends ee{constructor(){super(),hY(this,"segmentInference"),hY(this,"poseInference")}setWasmUrl(e){let t=e||`${x}wasm/pro/`;super.setWasmUrl(t)}getWasmLoaderUrl(e){return e?()=>import("./queen-simd-pro-5ba58a81.js"):()=>import("./queen-pro-ab2bf928.js")}initTensorflow(){return dY(this,arguments,(function*(e=i.None){const t=this.getModelConfig().InferenceBackend;lY.setTfBackend(t).then((()=>{this.initSegmentTensorflow(e),this.initPoseTensorflow(e)}))}))}initSegmentTensorflow(){return dY(this,arguments,(function*(e=i.None){const t=e===i.None?this.getModelConfig().SegmentModel:e;this.segmentInference||(this.segmentInference=new oY(this.getWasmUrl(),t))}))}initPoseTensorflow(){return dY(this,arguments,(function*(e=i.None){const t=e===i.None?this.getModelConfig().PoseModel:e;this.poseInference||(this.poseInference=new uY(this.getWasmUrl(),t))}))}segmentInferenceExecute(e,t,n,s){return this.segmentInference?this.segmentInference.execute(e,t,n,s):(console.error("queen segment model is not loaded."),null)}poseInferenceExecute(e,t,n,s){return this.poseInference?this.poseInference.execute(e,t,n,s):(console.error("queen segment model is not loaded."),null)}getSegmentData(){return this.segmentInference?this.segmentInference.getInterfaceData():null}};hY(pY,"Assets",X),hY(pY,"kQueenBeautyType",a),hY(pY,"kQueenBeautyParams",o),hY(pY,"kBackgroundProcessType",d),hY(pY,"kQueenBeautyMakeupType",l),hY(pY,"kQueenBeautyFaceShapeType",c),hY(pY,"kQueenBeautyBlend",h),hY(pY,"kSegmentPerformanceMode",p),hY(pY,"kQueenBeautyBodyShapeType",u),hY(pY,"kQueenModelShapeType",i),hY(pY,"kBackendType",b);var fY=Object.defineProperty,mY=(e,t,n)=>(((e,t,n)=>{t in e?fY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),gY=(e,t,n)=>new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));class yY extends ee{constructor(){super(),mY(this,"segmentInference"),mY(this,"poseInference")}setWasmUrl(e){let t=e||`${x}wasm/full/`;super.setWasmUrl(t)}getWasmLoaderUrl(e){return e?()=>import("./queen-simd-full-ef25016f.js"):()=>import("./queen-full-018b0563.js")}initTensorflow(){return gY(this,arguments,(function*(e=i.None){const t=this.getModelConfig().InferenceBackend;lY.setTfBackend(t).then((()=>{this.initSegmentTensorflow(e),this.initPoseTensorflow(e)}))}))}initSegmentTensorflow(){return gY(this,arguments,(function*(e=i.None){const t=e===i.None?this.getModelConfig().SegmentModel:e;this.segmentInference||(this.segmentInference=new oY(this.getWasmUrl(),t))}))}initPoseTensorflow(){return gY(this,arguments,(function*(e=i.None){const t=e===i.None?this.getModelConfig().PoseModel:e;this.poseInference||(this.poseInference=new uY(this.getWasmUrl(),t))}))}segmentInferenceExecute(e,t,n,s){return this.segmentInference?this.segmentInference.execute(e,t,n,s):(console.error("queen segment model is not loaded."),null)}poseInferenceExecute(e,t,n,s){return this.poseInference?this.poseInference.execute(e,t,n,s):(console.error("queen segment model is not loaded."),null)}getSegmentData(){return this.segmentInference?this.segmentInference.getInterfaceData():null}}mY(yY,"Assets",X),mY(yY,"kQueenBeautyType",a),mY(yY,"kQueenBeautyParams",o),mY(yY,"kBackgroundProcessType",d),mY(yY,"kQueenBeautyMakeupType",l),mY(yY,"kQueenBeautyFaceShapeType",c),mY(yY,"kQueenBeautyBlend",h),mY(yY,"kSegmentPerformanceMode",p),mY(yY,"kQueenBeautyBodyShapeType",u),mY(yY,"kQueenModelShapeType",i),mY(yY,"kBackendType",b);var bY=Object.defineProperty,xY=(e,t,n)=>(((e,t,n)=>{t in e?bY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class wY{constructor(e=f.Advance,t=""){xY(this,"queenWorker"),xY(this,"rendering"),xY(this,"queenReady"),xY(this,"authState"),xY(this,"initializeCallback"),xY(this,"loaddingCallback"),xY(this,"imageDataRenderCallback"),xY(this,"imageBufferRenderCallback"),xY(this,"loadUrlCallback"),xY(this,"complateCallback"),xY(this,"renderComplateCallback"),xY(this,"stateCallback"),xY(this,"getParamsValueCallback"),xY(this,"getQueenConfigCallback"),xY(this,"renderMediaStreamCallback"),xY(this,"renderTexturepCallback"),xY(this,"wasmUrl"),xY(this,"webgl"),xY(this,"cacheHelper"),xY(this,"renderOffscreenCanvas"),xY(this,"arWriteReady"),xY(this,"queenVersion"),xY(this,"setGreenScreenWithUrl",(function(e,t,n=1,s,r,a){return new Promise(((i,o)=>{this.complateCallback=i;const u={t:m.SetGreenScreenWithUrl,b:e,u:t,h:n,s:s,m:r,p:a};this.queenWorker.postMessage(u)}))})),this.initializeCallback=e=>{},this.loaddingCallback=e=>{},this.imageDataRenderCallback=e=>{},this.imageBufferRenderCallback=(e,t,n)=>{},this.loadUrlCallback=e=>{},this.complateCallback=()=>{},this.renderComplateCallback=()=>{},this.stateCallback=e=>{},this.getParamsValueCallback=e=>{},this.getQueenConfigCallback=e=>{},this.renderMediaStreamCallback=()=>{},this.renderTexturepCallback=e=>{},this.queenVersion=e,this.wasmUrl="",this.queenReady=!1,this.cacheHelper=new K,this.arWriteReady=!1,this.rendering=!1,this.authState=!1,this.renderOffscreenCanvas=null,""===t?this.loadWorkerJsByRemote():this.loadWorkerByLocal(t)}loadWorkerJsByRemote(){const e=this;let t="";switch(this.queenVersion){case f.Lite:t=`${x}js/aliyun-queen-engine-worker-lite.worker.js`;break;case f.Pro:t=`${x}js/aliyun-queen-engine-worker-pro.worker.js`;break;case f.Full:t=`${x}js/aliyun-queen-engine-worker-full.worker.js`;break;default:t=`${x}js/aliyun-queen-engine-worker.worker.js`}this.loadResourceData(t,(function(e){}),(function(t){const n=new Blob([t],{type:"application/octet-stream"});e.queenWorker=new Worker(URL.createObjectURL(n)),e.updateWorkerListener()}),null)}loadWorkerByLocal(e){this.queenWorker=new Worker(e),this.updateWorkerListener()}updateWorkerListener(){this.queenWorker.addEventListener("message",(e=>{let t=e.data;switch(t.t){case g.Initialize:this.initializeCallback&&(this.queenReady=!0,this.authState=t.d,t.d||(this.clearResourceCache(),console.log("Queen SDK initialization failed.")),this.initializeCallback(t.d));break;case g.LoaddingProgress:this.loaddingCallback&&this.loaddingCallback(t.d);break;case g.RenderImageData:this.rendering=!1,this.imageDataRenderCallback&&this.imageDataRenderCallback(t.d);break;case g.RenderImageBuffer:this.rendering=!1,this.imageBufferRenderCallback&&this.imageBufferRenderCallback(t.d,t.w,t.h);break;case g.RenderTextureId:this.rendering=!1,this.renderTexturepCallback&&this.renderTexturepCallback(t.d);break;case g.GetQueenBeautyParams:this.getParamsValueCallback&&this.getParamsValueCallback(t.v);break;case g.GetQueenBeautyParamsConfig:this.getQueenConfigCallback&&this.getQueenConfigCallback(t.d);break;case g.LoadUrlComplate:this.loadUrlCallback&&this.loadUrlCallback(t.d);break;case g.Complate:this.complateCallback&&this.complateCallback();break;case g.RenderComplate:this.rendering=!1,this.renderComplateCallback&&this.renderComplateCallback();break;case g.State:this.stateCallback&&this.stateCallback(t.d);break;case g.RenderTimestamp:this.rendering=!1,this.renderMediaStreamCallback&&this.renderMediaStreamCallback()}}))}getQueenWorker(){return this.queenWorker}checkSupportSIMD(){try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,9,1,7,0,65,0,253,15,26,11]))}catch(e){return!1}}checkSupportMutiThread(){try{return(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch(e){return!1}}getFullWasmName(e){let t=e?"-simd":"";return this.getWasmUrl()+`queen${t}.wasm`}getFullBinName(){return this.getWasmUrl()+"queen.bin"}getWasmUrl(){return this.wasmUrl}setWasmUrl(e){let t="";switch(this.queenVersion){case f.Lite:t=`${x}wasm/lite/`;break;case f.Pro:t=`${x}wasm/pro/`;break;case f.Full:t=`${x}wasm/full/`;break;default:t=`${x}wasm/advance/`}this.wasmUrl=e||t}initializeWithUrl(e,t,n,s,r,a={}){this.setWasmUrl(e),this.init(t,n,s,r,a)}initialize(e,t,n,s,r={}){this.init(e,t,n,document.getElementById(s),r)}create(e){this.init(e.SdkLicenseKey,e.OnInit,void 0!==e.OnProgress?e.OnProgress:function(e){},e.RenderCanvas,{segment:e.SegmentModel,pose:e.PoseModel,backend:e.InferenceBackend})}init(e,t,n,s,r={}){""===this.wasmUrl&&this.setWasmUrl();const a=this,i=this.checkSupportSIMD(),o=this.getFullWasmName(i),u=this.getFullBinName();this.loadResourceData(o,n,(function(i){console.info("load wasm:",o),a.loadResourceData(u,n,(function(n){console.info("load assetUrl:",u),a.initializeWithBuffer(e,t,i,n,s,r)}),(function(){n(-1)}),1,2)}),(function(){n(-1)}),0,2)}initializeWithBuffer(e,t,n,s,r,a={}){null!=r&&(this.renderOffscreenCanvas=r.transferControlToOffscreen());const i={t:m.Initialize,k:e,u:this.wasmUrl,baseUrl:window.location.href,o:this.renderOffscreenCanvas,wasm:n,asset:s,config:a};this.initializeCallback=t,void 0!==this.renderOffscreenCanvas&&null!==this.renderOffscreenCanvas?this.queenWorker.postMessage(i,[this.renderOffscreenCanvas]):this.queenWorker.postMessage(i)}loadResourceData(e,t,n,s,r=0,a=1){this.cacheHelper.loadResourceData(e,t,n,s,r,a)}clearResourceCache(){this.cacheHelper.clearAssetsCache()}render(e,t,n,s){if(!this.queenReady||this.rendering)return void this.queenAssert();this.imageBufferRenderCallback=s;const r={t:m.Render,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(r,[e.buffer])}renderTextureId(e,t,n){return this.assertMessage(!1,"SDK does not support this API for worker mode. not support WebGLTexture transfer."),null}renderMediaObjectToRenderCanvas(e,t,n){return new Promise(((s,r)=>{this.queenReady&&!this.rendering||(this.queenAssert(),r()),this.renderComplateCallback=s;const a={t:m.RenderMediaObjectToTexture,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(a)}))}renderMediaObjectToTexture(e,t,n){return this.queenReady?(this.assertMessage(!1,"SDK does not support this API for Worker mode."),null):(this.queenAssert(),null)}renderWithMediaObject(e,t,n,s){if(!this.queenReady||this.rendering)return void this.queenAssert();this.imageBufferRenderCallback=s;const r={t:m.RenderWithMediaObject,d:e,w:t,h:n};this.rendering=!0,e instanceof ImageData||e instanceof VideoFrame?this.queenWorker.postMessage(r):this.queenWorker.postMessage(r,[e])}renderMediaStream(e,t,n,s){if(0===e.getVideoTracks().length)return console.warn("Input media stream does not contain a video track."),e;const r=e.getVideoTracks()[0],a=this.renderMediaStreamTrack(r,t,n,s);if(a){const e=new MediaStream;return e.addTrack(a),e}return e}renderMediaStreamTrack(e,t,n,s){if(!this.queenReady||this.rendering)return this.queenAssert(),e;if("undefined"!=typeof MediaStreamTrackProcessor&&"undefined"!=typeof MediaStreamTrackGenerator){s&&(this.renderMediaStreamCallback=s);const r=new MediaStreamTrackProcessor({track:e}).readable,a=new MediaStreamTrackGenerator({kind:"video"}),i=a.writable,o={t:m.MediaStreamRender,r:r,w:i,width:t,height:n};return this.rendering=!0,this.queenWorker.postMessage(o,[r,i]),a}return e}renderReadableStream(e,t,n,s,r){if(this.queenReady&&!this.rendering||this.queenAssert(),"undefined"!=typeof MediaStreamTrackProcessor&&"undefined"!=typeof MediaStreamTrackGenerator){r&&(this.renderMediaStreamCallback=r);const a={t:m.MediaStreamRender,r:e,w:t,width:n,height:s};this.rendering=!0,this.queenWorker.postMessage(a,[e,t])}}enableBokehBackground(e){this.enableBokehBackgroundByType(e,d.kBackgroundBlur)}enableTransparentBackground(e){this.enableBokehBackgroundByType(e,d.kBackgroundTransparent)}enableBokehBackgroundByType(e,t){const n={t:m.EnableBokehBackground,k:t,s:e};this.queenWorker.postMessage(n)}setEngineParams(e){const t={t:m.SetEngineParams,p:e};this.queenWorker.postMessage(t)}setSegmentBackgroundUrl(e){return new Promise(((t,n)=>{this.complateCallback=t;const s={t:m.SetSegmentBackgroundUrl,u:e};this.queenWorker.postMessage(s)}))}setSegmentBackgroundProcessType(e){const t={t:m.SetSegmentBackgroundProcessType,p:e};this.queenWorker.postMessage(t)}setAISegmentForegroundPadding(e){const t={t:m.SetAISegmentForegroundPadding,p:e};this.queenWorker.postMessage(t)}setPureColorBackgroundUrl(e,t=1,n){return new Promise(((s,r)=>{this.complateCallback=s;const a={t:m.SetPureColorBackgroundUrl,u:e,h:t,c:n};this.queenWorker.postMessage(a)}))}showQueenParamJson(){return new Promise(((e,t)=>{this.getQueenConfigCallback=e;const n={t:m.ShowQueenParamJson};this.queenWorker.postMessage(n)}))}showQueenParam(){return new Promise(((e,t)=>{this.getQueenConfigCallback=e;const n={t:m.ShowQueenParam};this.queenWorker.postMessage(n)}))}loadResourceFileWithUrl(e,t){return new Promise((function(n,s){this.loadUrlCallback=n;const r={t:m.LoadResourceFileWithUrl,u:e,z:t};this.queenWorker.postMessage(r)}))}loadResourceFileWithUrlSaveAs(e,t,n){return new Promise((function(s,r){this.loadUrlCallback=s;const a={t:m.LoadResourceFileWithUrlSaveAs,u:e,n:t,z:n};this.queenWorker.postMessage(a)}))}loadResourceFileWithData(e,t,n){return new Promise((function(s,r){this.loadUrlCallback=s;const a={t:m.LoadResourceFileWithData,b:e,n:t,z:n};this.queenWorker.postMessage(a)}))}checkResourceFile(e){return new Promise((function(t,n){this.stateCallback=t;const s={t:m.CheckResourceFile,n:e};this.queenWorker.postMessage(s)}))}setQueenBeautyType(e,t){const n={t:m.SetQueenBeautyType,p:e,s:t};this.queenWorker.postMessage(n)}setQueenBeautyParams(e,t){const n={t:m.SetQueenBeautyParams,p:e,v:t};this.queenWorker.postMessage(n)}getQueenBeautyParams(e){return new Promise((function(t,n){this.getParamsValueCallback=t;const s={t:m.GetQueenBeautyParams,p:e};this.queenWorker.postMessage(s)}))}setLutByType(e,t=.5){this.setQueenBeautyType(a.LUT,!0),this.setQueenBeautyParams(o.LUT,t);const n=j.getLutUrl(e);return this.setLutImageUrl(n)}setLutImageUrl(e){return new Promise(((t,n)=>{this.complateCallback=t;const s={t:m.SetLutImageUrl,p:e};this.queenWorker.postMessage(s)}))}setFaceShape(e,t){const n={t:m.SetFaceShape,p:e,v:t};this.queenWorker.postMessage(n)}setMakeupEyeBrow(e,t=h.LabMix){const[n,s]=j.getMakeupEyeBrowRes(e);return this.setMakeupWithPackage(l.EyeBrow,s,n,t)}setMackupEyeLash(e,t=h.LabMix){const n=j.getMakeupEyeLashUrl(e);return this.setMakeupWithUrl(l.Eyelash,n,t,20)}setMakeupEyeShadow(e,t=h.LabMix){const[n,s]=j.getMakeupEyeShadowRes(e);return this.setMakeupWithPackage(l.EyeShadow,s,n,t)}setMakeupEyeLiner(e,t=h.LabMix){const n=j.getMakeupEyeLinerUrl(e);return this.setMakeupWithUrl(l.Eyeliner,n,t,20)}setMakeupEyeBall(e,t=h.LabMix){const n=j.getMakeupEyeBallUrl(e);return this.setMakeupWithUrl(l.Eyeball,n,t,20)}setMakeupMouth(e,t=h.LabMix){const[n,s]=j.getMakeupMouthRes(e);return this.setMakeupWithPackage(l.EyeBrow,s,n,t)}setMakeupWhole(e,t=h.LabMix){const n=j.getMakeupWholeUrl(e);return this.setMakeupWithUrl(l.Whole,n,t,20)}setMakeupBlush(e,t=h.LabMix){const n=j.getMakeupBlushUrl(e);return this.setMakeupWithUrl(l.Blush,n,t,20)}setMakeupHighlight(e,t=h.LabMix){const n=j.getMakeupHighLightUrl(e);return this.setMakeupWithUrl(l.Highlight,n,t,20)}setMakeupWithUrl(e,t,n,s){return new Promise(((r,a)=>{this.complateCallback=r,void 0===s&&(s=20);const i={t:m.SetMakeupWithUrl,m:e,u:t,b:n,f:s};this.queenWorker.postMessage(i)}))}setMakeupWithPackage(e,t,n,s){return new Promise(((r,a)=>{this.complateCallback=r;const i={t:m.SetMakeupWithPackage,m:e,u:t,n:n,b:s};this.queenWorker.postMessage(i)}))}setMakeupWithType(e,t,n){return this.setMakeupWithTypeFps(e,t,n,20)}setMakeupWithTypeFps(e,t,n,s){const r={t:m.SetMakeupWithTypeFps,m:e,p:t,b:n,f:s};this.queenWorker.postMessage(r)}setMakeupFemaleAlpha(e,t){this.setMakeupAlphaWithType(e,!0,t)}setMakeupMaleAlpha(e,t){this.setMakeupAlphaWithType(e,!1,t)}setMakeupAlphaWithType(e,t,n){const s={t:m.SetMakeupAlphaWithType,m:e,f:t,a:n};this.queenWorker.postMessage(s)}setMakeupBlendWithType(e,t){const n={t:m.SetMakeupBlendWithType,m:e,b:t};this.queenWorker.postMessage(n)}resetAllMakeupType(){const e={t:m.ResetAllMakeupType};this.queenWorker.postMessage(e)}setBodyShape(e,t){const n={t:m.SetBodyShape,k:e,v:t};this.queenWorker.postMessage(n)}addMaterialWithType(e){const t=j.getStickerUrl(e);return this.addMaterialWithUrl(t)}addMaterialWithIndex(e){const t=j.getStickerUrlByIndex(e);return this.addMaterialWithUrl(t)}addMaterialWithUrl(e){return new Promise(((t,n)=>{this.complateCallback=t;const s={t:m.AddMaterialWithUrl,p:e};this.queenWorker.postMessage(s)}))}removeMaterialWithType(e){const t=j.getStickerUrl(e);this.removeMaterialWithUrl(t)}removeMaterialWithIndex(e){const t=j.getStickerUrlByIndex(e);this.removeMaterialWithUrl(t)}removeMaterialWithUrl(e){const t={t:m.RemoveMaterialWithUrl,p:e};this.queenWorker.postMessage(t)}showFaceDetectPoint(e){const t={t:m.ShowFaceDetectPoint,s:e};this.queenWorker.postMessage(t)}showMakeupLine(e){const t={t:m.ShowMakeupLine,s:e};this.queenWorker.postMessage(t)}showBodyDetectPoint(e){const t={t:m.ShowBodyDetectPoint,s:e};this.queenWorker.postMessage(t)}initArWriteResource(){const e=this,t=this.getWasmUrl()+"models/handmodels.bin";return new Promise((function(n,s){e.arWriteReady?n(!0):e.loadResourceData(t,(e=>{}),(function(e){const t={t:m.LoadQueenAssets,b:e};this.queenWorker.postMessage(t)}),(()=>{}),0,1)}))}setArWriting(e,t){const n={t:m.SetArWriting,s:e,m:t};this.queenWorker.postMessage(n)}cleanScreenArWriting(){const e={t:m.CleanScreenArWriting};this.queenWorker.postMessage(e)}setPowerSaving(e){const t={t:m.SetPowerSaving,s:e};this.queenWorker.postMessage(t)}animojiInitialize(e,t,n,s){return new Promise(((r,a)=>{this.complateCallback=r;const i={t:m.AnimojiInitialize,u:e,w:t,h:n,s:s};this.queenWorker.postMessage(i)}))}setAnimojiBackgroundWithMode(e,t){return new Promise(((n,s)=>{this.complateCallback=n;const r={t:m.SetAnimojiBackgroundWithMode,m:e,u:t};this.queenWorker.postMessage(r)}))}animojiRenderMediaObjectToRenderCanvas(e,t,n){return new Promise(((s,r)=>{this.queenReady&&!this.rendering||(this.queenAssert(),r()),this.renderComplateCallback=s;const a={t:m.AnimojiRenderMediaObjectToTexture,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(a)}))}animojiRender(e,t,n,s){if(!this.queenReady||this.rendering)return void this.queenAssert();this.imageBufferRenderCallback=s;const r={t:m.AnimojiRender,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(r,[e.buffer])}animojiRenderWithMediaObject(e,t,n,s){if(!this.queenReady||this.rendering)return void this.queenAssert();this.imageBufferRenderCallback=s;const r={t:m.AnimojiRenderWithMediaObject,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(r)}animojiRenderMediaObjectToTexture(e,t,n){return this.assertMessage(!1,"SDK does not support this API for Worker mode. not support WebGLTexture transfer."),null}animojiRenderTextureId(e,t,n){return this.assertMessage(!1,"SDK does not support this API for Worker mode. not support WebGLTexture transfer."),null}animojiResize(e){const t={t:m.AnimojiResize,s:e};this.queenWorker.postMessage(t)}animojiDestroy(){const e={t:m.AnimojiDestroy};this.queenWorker.postMessage(e)}engineDestory(){this.queenReady=!1,this.authState=!1;const e={t:m.EngineDestory};this.queenWorker.postMessage(e),this.queenWorker.terminate()}queenAssert(){this.queenReady||console.error("Queen Engine initialization failed."),this.authState||console.error("queen license authentication failed.")}assertMessage(e,t){e||console.error(t)}}xY(wY,"Assets",X),xY(wY,"kQueenBeautyType",a),xY(wY,"kQueenBeautyParams",o),xY(wY,"kBackgroundProcessType",d),xY(wY,"kQueenBeautyMakeupType",l),xY(wY,"kQueenBeautyFaceShapeType",c),xY(wY,"kQueenBeautyBlend",h),xY(wY,"kSegmentPerformanceMode",p),xY(wY,"kQueenModelShapeType",i),xY(wY,"kQueenBeautyBodyShapeType",u),xY(wY,"kQueenVersion",f);var kY=Object.defineProperty,vY=(e,t,n)=>(((e,t,n)=>{t in e?kY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class IY extends se{constructor(){super()}}vY(IY,"QueenEngineBase",ee),vY(IY,"QueenEngineLite",ie),vY(IY,"QueenEnginePro",pY),vY(IY,"QueenEngineFull",yY),vY(IY,"QueenEngineWorker",wY),vY(IY,"Assets",X),vY(IY,"kQueenBeautyType",a),vY(IY,"kQueenBeautyParams",o),vY(IY,"kBackgroundProcessType",d),vY(IY,"kQueenBeautyMakeupType",l),vY(IY,"kQueenBeautyFaceShapeType",c),vY(IY,"kQueenBeautyBlend",h),vY(IY,"kSegmentPerformanceMode",p),vY(IY,"kQueenModelShapeType",i),vY(IY,"kBackendType",b),vY(IY,"kQueenBeautyBodyShapeType",u),vY(IY,"kQueenVersion",f);var SY=Object.defineProperty,CY=(e,t,n)=>(((e,t,n)=>{t in e?SY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class NY extends e{constructor(){super("AliRtcBeauty"),CY(this,"engineReady",!1),CY(this,"_queenEngine"),CY(this,"canvas"),CY(this,"dirty",!1),CY(this,"lastFrameTimestamp",0),CY(this,"continuousStuckCount",0),this.zIndex=0}get initOptions(){return{licenseKey:""}}setOptions(e){const t=!!e.segmentBackgroundProcess?.enable,n=!!e.setSegmentBackgroundImage?.backgroundImgUrl;this.options={...this.options,...e},n?delete this.options.segmentBackgroundProcess:t&&delete this.options.setSegmentBackgroundImage,this.engineReady&&this.queenEngine?.setEngineParams(this.options)}async init(){await this.initQueen()}isSupported(){const e=!("undefined"==typeof TransformStream||"undefined"==typeof MediaStreamTrackProcessor||"undefined"==typeof MediaStreamTrackGenerator),t=!("undefined"==typeof OffscreenCanvas||"undefined"==typeof WebGL2RenderingContext),n=WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]));return e&&t&&n}async initQueen(){this.canvas=document.createElement("canvas");const{licenseKey:e=""}=this.options,t=new wY(f.Pro);return this._queenEngine=t,await new Promise((n=>{t.init(e,(()=>{this.engineReady=!0,this.emit("ready"),t.setEngineParams(this.options),n(t)}),(function(){}),this.canvas)})),t}shouldUpdate(e){return this.videoUpdated(e)||this.dirty}async process(e){if(!e.originVideoTrack)return this.clear(e),void e.updateVideoTrack();if(!this.queenEngine||!this.engineReady)return;this.dirty=!1;const t=this.queenEngine.renderMediaStreamTrack(e.originVideoTrack);t&&e.updateVideoTrack(t)}get queenEngine(){return this._queenEngine}clear(e){this.canvas=void 0,this.engineReady=!1,this._queenEngine=void 0,this.queenEngine?.engineDestory(),super.clear(e)}}export{NY as default};
|
|
19135
|
+
*/for(const e of rY)wr(e);var aY=Object.defineProperty,iY=(e,t,n)=>(((e,t,n)=>{t in e?aY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),oY=(e,t,n)=>new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));class uY{constructor(e,t){iY(this,"loadding",!1),iY(this,"tensorflowHModel",null),iY(this,"tensorflowVModel",null),iY(this,"modelType"),iY(this,"baseUrl"),iY(this,"horizontalModelUrl",""),iY(this,"verticalModelUrl",""),this.baseUrl=e,this.modelType=t,this.updateModelUrl(),this.loadModelByType()}updateModelUrl(){}loadModelByType(){return oY(this,null,(function*(){const e=this.modelType===i.Horizontal||this.modelType===i.Both,t=this.modelType===i.Vertical||this.modelType===i.Both;e&&this.loadHorizontalModel(),t&&this.loadVerticalModel()}))}loadHorizontalModel(){return oY(this,null,(function*(){if(""!==this.horizontalModelUrl&&!this.tensorflowHModel&&!this.loadding)try{this.loadding=!0,this.tensorflowHModel=yield YH(this.horizontalModelUrl)}catch(e){console.error("loaded model error."+e.message)}finally{this.loadding=!1}}))}loadVerticalModel(){return oY(this,null,(function*(){if(""!==this.verticalModelUrl&&!this.tensorflowVModel&&!this.loadding)try{this.loadding=!0,this.tensorflowVModel=yield YH(this.verticalModelUrl)}catch(e){console.error(e)}finally{this.loadding=!1}}))}execute(e,t,n,s){return null}}class lY extends uY{constructor(e,t){super(e,t),iY(this,"interfaceData")}updateModelUrl(){this.horizontalModelUrl=this.baseUrl+"models/segment/horizontal/model.json",this.verticalModelUrl=this.baseUrl+"models/segment/vertical/model.json"}execute(e,t,n,s){try{const s=Qp(e),r=s.toFloat(),a=kl(r);let i;if(t>=n){if(!this.tensorflowHModel)return this.loadHorizontalModel(),null;i=this.tensorflowHModel.execute(a)}else{if(!this.tensorflowVModel)return this.loadVerticalModel(),null;i=this.tensorflowVModel.execute(a)}const o=i.mul(255);let u=o.transpose([0,3,1,2]);const l=u.shape[2],c=u.shape[3];let h=u.slice([0,1,0,0],[1,1,l,c]),d=h.dataSync();return this.interfaceData=d,xi([h,u,o,i,a,r,s]),d}catch(e){return null}finally{mi(),xi()}}getInterfaceData(){return this.interfaceData}}class cY extends uY{constructor(e,t){super(e,t)}updateModelUrl(){this.horizontalModelUrl=this.baseUrl+"models/pose/horizontal/model.json",this.verticalModelUrl=this.baseUrl+"models/pose/vertical/model.json"}execute(e,t,n,s){try{let s,r=Qp(e,3),a=r.sub(127.5),i=a.div(128),o=kl(i);if(t>=n){if(!this.tensorflowHModel)return this.loadHorizontalModel(),null;s=this.tensorflowHModel.execute(o)}else{if(!this.tensorflowVModel)return this.loadVerticalModel(),null;s=this.tensorflowVModel.execute(o)}let u=s.transpose([0,3,1,2]),l=u.dataSync();return xi([r,a,i,o,u,s]),l}catch(e){return null}finally{mi(),xi()}}}class hY{static setTfBackend(e=b.Auto){switch(e){case b.WebGL:return this.setWebglBackend();case b.WebGPU:return this.setWebgpuBackend();default:return this.setBackendByAuto()}}static setWebgpuBackend(){return new Promise(((e,t)=>oY(this,null,(function*(){try{"navigator"in globalThis&&"gpu"in navigator?(yield ki("webgpu"),console.info("Inference using WebGPU.")):(yield ki("webgl"),console.info("Inference using WebGL.")),yield vi(),e()}catch(e){console.error("Loaded backend error: "+e.message),t(e)}}))))}static setWebglBackend(){return new Promise(((e,t)=>oY(this,null,(function*(){try{yield ki("webgl"),console.info("Inference using WebGL."),yield vi(),e()}catch(e){console.error("Loaded backend error: "+e.message),t(e)}}))))}static setBackendByAuto(){return new Promise(((e,t)=>oY(this,null,(function*(){try{(yield this.isMacSystem())?"navigator"in globalThis&&"gpu"in navigator?(yield ki("webgpu"),console.info("Inference using WebGPU on macOS.")):(yield ki("webgl"),console.info("Inference using WebGL on macOS.")):(yield ki("webgl"),console.info("Inference using WebGL.")),yield vi(),e()}catch(e){console.error("Loaded backend error: "+e.message),t(e)}}))))}static isMacSystem(){return new Promise((e=>{navigator.userAgentData?navigator.userAgentData.getHighEntropyValues(["platform"]).then((t=>{"macOS"===t.platform?e(!0):e(!1)})):/Mac|iMac|Macintosh/.test(navigator.userAgent)?e(!0):e(!1)}))}}var dY=Object.defineProperty,pY=(e,t,n)=>(((e,t,n)=>{t in e?dY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),fY=(e,t,n)=>new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));let mY=class extends ee{constructor(){super(),pY(this,"segmentInference"),pY(this,"poseInference")}setWasmUrl(e){let t=e||`${x}wasm/pro/`;super.setWasmUrl(t)}getWasmLoaderUrl(e){return e?()=>import("./queen-simd-pro-Dp0ynTmZ.js"):()=>import("./queen-pro-BF2LwKO0.js")}initTensorflow(){return fY(this,arguments,(function*(e=i.None){const t=this.getModelConfig().InferenceBackend;hY.setTfBackend(t).then((()=>{this.initSegmentTensorflow(e),this.initPoseTensorflow(e)}))}))}initSegmentTensorflow(){return fY(this,arguments,(function*(e=i.None){const t=e===i.None?this.getModelConfig().SegmentModel:e;this.segmentInference||(this.segmentInference=new lY(this.getWasmUrl(),t))}))}initPoseTensorflow(){return fY(this,arguments,(function*(e=i.None){const t=e===i.None?this.getModelConfig().PoseModel:e;this.poseInference||(this.poseInference=new cY(this.getWasmUrl(),t))}))}segmentInferenceExecute(e,t,n,s){return this.segmentInference?this.segmentInference.execute(e,t,n,s):(console.error("queen segment model is not loaded."),null)}poseInferenceExecute(e,t,n,s){return this.poseInference?this.poseInference.execute(e,t,n,s):(console.error("queen segment model is not loaded."),null)}getSegmentData(){return this.segmentInference?this.segmentInference.getInterfaceData():null}};pY(mY,"Assets",X),pY(mY,"kQueenBeautyType",a),pY(mY,"kQueenBeautyParams",o),pY(mY,"kBackgroundProcessType",d),pY(mY,"kQueenBeautyMakeupType",l),pY(mY,"kQueenBeautyFaceShapeType",c),pY(mY,"kQueenBeautyBlend",h),pY(mY,"kSegmentPerformanceMode",p),pY(mY,"kQueenBeautyBodyShapeType",u),pY(mY,"kQueenModelShapeType",i),pY(mY,"kBackendType",b);var gY=Object.defineProperty,yY=(e,t,n)=>(((e,t,n)=>{t in e?gY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n),bY=(e,t,n)=>new Promise(((s,r)=>{var a=e=>{try{o(n.next(e))}catch(e){r(e)}},i=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=e=>e.done?s(e.value):Promise.resolve(e.value).then(a,i);o((n=n.apply(e,t)).next())}));class xY extends ee{constructor(){super(),yY(this,"segmentInference"),yY(this,"poseInference")}setWasmUrl(e){let t=e||`${x}wasm/full/`;super.setWasmUrl(t)}getWasmLoaderUrl(e){return e?()=>import("./queen-simd-full-CgzwfIzl.js"):()=>import("./queen-full-DgUzXXaA.js")}initTensorflow(){return bY(this,arguments,(function*(e=i.None){const t=this.getModelConfig().InferenceBackend;hY.setTfBackend(t).then((()=>{this.initSegmentTensorflow(e),this.initPoseTensorflow(e)}))}))}initSegmentTensorflow(){return bY(this,arguments,(function*(e=i.None){const t=e===i.None?this.getModelConfig().SegmentModel:e;this.segmentInference||(this.segmentInference=new lY(this.getWasmUrl(),t))}))}initPoseTensorflow(){return bY(this,arguments,(function*(e=i.None){const t=e===i.None?this.getModelConfig().PoseModel:e;this.poseInference||(this.poseInference=new cY(this.getWasmUrl(),t))}))}segmentInferenceExecute(e,t,n,s){return this.segmentInference?this.segmentInference.execute(e,t,n,s):(console.error("queen segment model is not loaded."),null)}poseInferenceExecute(e,t,n,s){return this.poseInference?this.poseInference.execute(e,t,n,s):(console.error("queen segment model is not loaded."),null)}getSegmentData(){return this.segmentInference?this.segmentInference.getInterfaceData():null}}yY(xY,"Assets",X),yY(xY,"kQueenBeautyType",a),yY(xY,"kQueenBeautyParams",o),yY(xY,"kBackgroundProcessType",d),yY(xY,"kQueenBeautyMakeupType",l),yY(xY,"kQueenBeautyFaceShapeType",c),yY(xY,"kQueenBeautyBlend",h),yY(xY,"kSegmentPerformanceMode",p),yY(xY,"kQueenBeautyBodyShapeType",u),yY(xY,"kQueenModelShapeType",i),yY(xY,"kBackendType",b);var wY=Object.defineProperty,kY=(e,t,n)=>(((e,t,n)=>{t in e?wY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class vY{constructor(e=f.Advance,t=""){kY(this,"queenWorker"),kY(this,"rendering"),kY(this,"queenReady"),kY(this,"authState"),kY(this,"initializeCallback"),kY(this,"loaddingCallback"),kY(this,"imageDataRenderCallback"),kY(this,"imageBufferRenderCallback"),kY(this,"loadUrlCallback"),kY(this,"complateCallback"),kY(this,"renderComplateCallback"),kY(this,"stateCallback"),kY(this,"getParamsValueCallback"),kY(this,"getQueenConfigCallback"),kY(this,"renderMediaStreamCallback"),kY(this,"renderTexturepCallback"),kY(this,"wasmUrl"),kY(this,"webgl"),kY(this,"cacheHelper"),kY(this,"renderOffscreenCanvas"),kY(this,"arWriteReady"),kY(this,"queenVersion"),kY(this,"setGreenScreenWithUrl",(function(e,t,n=1,s,r,a){return new Promise(((i,o)=>{this.complateCallback=i;const u={t:m.SetGreenScreenWithUrl,b:e,u:t,h:n,s:s,m:r,p:a};this.queenWorker.postMessage(u)}))})),this.initializeCallback=e=>{},this.loaddingCallback=e=>{},this.imageDataRenderCallback=e=>{},this.imageBufferRenderCallback=(e,t,n)=>{},this.loadUrlCallback=e=>{},this.complateCallback=()=>{},this.renderComplateCallback=()=>{},this.stateCallback=e=>{},this.getParamsValueCallback=e=>{},this.getQueenConfigCallback=e=>{},this.renderMediaStreamCallback=()=>{},this.renderTexturepCallback=e=>{},this.queenVersion=e,this.wasmUrl="",this.queenReady=!1,this.cacheHelper=new K,this.arWriteReady=!1,this.rendering=!1,this.authState=!1,this.renderOffscreenCanvas=null,""===t?this.loadWorkerJsByRemote():this.loadWorkerByLocal(t)}loadWorkerJsByRemote(){const e=this;let t="";switch(this.queenVersion){case f.Lite:t=`${x}js/aliyun-queen-engine-worker-lite.worker.js`;break;case f.Pro:t=`${x}js/aliyun-queen-engine-worker-pro.worker.js`;break;case f.Full:t=`${x}js/aliyun-queen-engine-worker-full.worker.js`;break;default:t=`${x}js/aliyun-queen-engine-worker.worker.js`}this.loadResourceData(t,(function(e){}),(function(t){const n=new Blob([t],{type:"application/octet-stream"});e.queenWorker=new Worker(URL.createObjectURL(n)),e.updateWorkerListener()}),null)}loadWorkerByLocal(e){this.queenWorker=new Worker(e),this.updateWorkerListener()}updateWorkerListener(){this.queenWorker.addEventListener("message",(e=>{let t=e.data;switch(t.t){case g.Initialize:this.initializeCallback&&(this.queenReady=!0,this.authState=t.d,t.d||(this.clearResourceCache(),console.log("Queen SDK initialization failed.")),this.initializeCallback(t.d));break;case g.LoaddingProgress:this.loaddingCallback&&this.loaddingCallback(t.d);break;case g.RenderImageData:this.rendering=!1,this.imageDataRenderCallback&&this.imageDataRenderCallback(t.d);break;case g.RenderImageBuffer:this.rendering=!1,this.imageBufferRenderCallback&&this.imageBufferRenderCallback(t.d,t.w,t.h);break;case g.RenderTextureId:this.rendering=!1,this.renderTexturepCallback&&this.renderTexturepCallback(t.d);break;case g.GetQueenBeautyParams:this.getParamsValueCallback&&this.getParamsValueCallback(t.v);break;case g.GetQueenBeautyParamsConfig:this.getQueenConfigCallback&&this.getQueenConfigCallback(t.d);break;case g.LoadUrlComplate:this.loadUrlCallback&&this.loadUrlCallback(t.d);break;case g.Complate:this.complateCallback&&this.complateCallback();break;case g.RenderComplate:this.rendering=!1,this.renderComplateCallback&&this.renderComplateCallback();break;case g.State:this.stateCallback&&this.stateCallback(t.d);break;case g.RenderTimestamp:this.rendering=!1,this.renderMediaStreamCallback&&this.renderMediaStreamCallback()}}))}getQueenWorker(){return this.queenWorker}checkSupportSIMD(){try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,9,1,7,0,65,0,253,15,26,11]))}catch(e){return!1}}checkSupportMutiThread(){try{return(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch(e){return!1}}getFullWasmName(e){let t=e?"-simd":"";return this.getWasmUrl()+`queen${t}.wasm`}getFullBinName(){return this.getWasmUrl()+"queen.bin"}getWasmUrl(){return this.wasmUrl}setWasmUrl(e){let t="";switch(this.queenVersion){case f.Lite:t=`${x}wasm/lite/`;break;case f.Pro:t=`${x}wasm/pro/`;break;case f.Full:t=`${x}wasm/full/`;break;default:t=`${x}wasm/advance/`}this.wasmUrl=e||t}initializeWithUrl(e,t,n,s,r,a={}){this.setWasmUrl(e),this.init(t,n,s,r,a)}initialize(e,t,n,s,r={}){this.init(e,t,n,document.getElementById(s),r)}create(e){this.init(e.SdkLicenseKey,e.OnInit,void 0!==e.OnProgress?e.OnProgress:function(e){},e.RenderCanvas,{segment:e.SegmentModel,pose:e.PoseModel,backend:e.InferenceBackend})}init(e,t,n,s,r={}){""===this.wasmUrl&&this.setWasmUrl();const a=this,i=this.checkSupportSIMD(),o=this.getFullWasmName(i),u=this.getFullBinName();this.loadResourceData(o,n,(function(i){console.info("load wasm:",o),a.loadResourceData(u,n,(function(n){console.info("load assetUrl:",u),a.initializeWithBuffer(e,t,i,n,s,r)}),(function(){n(-1)}),1,2)}),(function(){n(-1)}),0,2)}initializeWithBuffer(e,t,n,s,r,a={}){null!=r&&(this.renderOffscreenCanvas=r.transferControlToOffscreen());const i={t:m.Initialize,k:e,u:this.wasmUrl,baseUrl:window.location.href,o:this.renderOffscreenCanvas,wasm:n,asset:s,config:a};this.initializeCallback=t,void 0!==this.renderOffscreenCanvas&&null!==this.renderOffscreenCanvas?this.queenWorker.postMessage(i,[this.renderOffscreenCanvas]):this.queenWorker.postMessage(i)}loadResourceData(e,t,n,s,r=0,a=1){this.cacheHelper.loadResourceData(e,t,n,s,r,a)}clearResourceCache(){this.cacheHelper.clearAssetsCache()}render(e,t,n,s){if(!this.queenReady||this.rendering)return void this.queenAssert();this.imageBufferRenderCallback=s;const r={t:m.Render,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(r,[e.buffer])}renderTextureId(e,t,n){return this.assertMessage(!1,"SDK does not support this API for worker mode. not support WebGLTexture transfer."),null}renderMediaObjectToRenderCanvas(e,t,n){return new Promise(((s,r)=>{this.queenReady&&!this.rendering||(this.queenAssert(),r()),this.renderComplateCallback=s;const a={t:m.RenderMediaObjectToTexture,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(a)}))}renderMediaObjectToTexture(e,t,n){return this.queenReady?(this.assertMessage(!1,"SDK does not support this API for Worker mode."),null):(this.queenAssert(),null)}renderWithMediaObject(e,t,n,s){if(!this.queenReady||this.rendering)return void this.queenAssert();this.imageBufferRenderCallback=s;const r={t:m.RenderWithMediaObject,d:e,w:t,h:n};this.rendering=!0,e instanceof ImageData||e instanceof VideoFrame?this.queenWorker.postMessage(r):this.queenWorker.postMessage(r,[e])}renderMediaStream(e,t,n,s){if(0===e.getVideoTracks().length)return console.warn("Input media stream does not contain a video track."),e;const r=e.getVideoTracks()[0],a=this.renderMediaStreamTrack(r,t,n,s);if(a){const e=new MediaStream;return e.addTrack(a),e}return e}renderMediaStreamTrack(e,t,n,s){if(!this.queenReady||this.rendering)return this.queenAssert(),e;if("undefined"!=typeof MediaStreamTrackProcessor&&"undefined"!=typeof MediaStreamTrackGenerator){s&&(this.renderMediaStreamCallback=s);const r=new MediaStreamTrackProcessor({track:e}).readable,a=new MediaStreamTrackGenerator({kind:"video"}),i=a.writable,o={t:m.MediaStreamRender,r:r,w:i,width:t,height:n};return this.rendering=!0,this.queenWorker.postMessage(o,[r,i]),a}return e}renderReadableStream(e,t,n,s,r){if(this.queenReady&&!this.rendering||this.queenAssert(),"undefined"!=typeof MediaStreamTrackProcessor&&"undefined"!=typeof MediaStreamTrackGenerator){r&&(this.renderMediaStreamCallback=r);const a={t:m.MediaStreamRender,r:e,w:t,width:n,height:s};this.rendering=!0,this.queenWorker.postMessage(a,[e,t])}}enableBokehBackground(e){this.enableBokehBackgroundByType(e,d.kBackgroundBlur)}enableTransparentBackground(e){this.enableBokehBackgroundByType(e,d.kBackgroundTransparent)}enableBokehBackgroundByType(e,t){const n={t:m.EnableBokehBackground,k:t,s:e};this.queenWorker.postMessage(n)}setEngineParams(e){const t={t:m.SetEngineParams,p:e};this.queenWorker.postMessage(t)}setSegmentBackgroundUrl(e){return new Promise(((t,n)=>{this.complateCallback=t;const s={t:m.SetSegmentBackgroundUrl,u:e};this.queenWorker.postMessage(s)}))}setSegmentBackgroundProcessType(e){const t={t:m.SetSegmentBackgroundProcessType,p:e};this.queenWorker.postMessage(t)}setAISegmentForegroundPadding(e){const t={t:m.SetAISegmentForegroundPadding,p:e};this.queenWorker.postMessage(t)}setPureColorBackgroundUrl(e,t=1,n){return new Promise(((s,r)=>{this.complateCallback=s;const a={t:m.SetPureColorBackgroundUrl,u:e,h:t,c:n};this.queenWorker.postMessage(a)}))}showQueenParamJson(){return new Promise(((e,t)=>{this.getQueenConfigCallback=e;const n={t:m.ShowQueenParamJson};this.queenWorker.postMessage(n)}))}showQueenParam(){return new Promise(((e,t)=>{this.getQueenConfigCallback=e;const n={t:m.ShowQueenParam};this.queenWorker.postMessage(n)}))}loadResourceFileWithUrl(e,t){return new Promise((function(n,s){this.loadUrlCallback=n;const r={t:m.LoadResourceFileWithUrl,u:e,z:t};this.queenWorker.postMessage(r)}))}loadResourceFileWithUrlSaveAs(e,t,n){return new Promise((function(s,r){this.loadUrlCallback=s;const a={t:m.LoadResourceFileWithUrlSaveAs,u:e,n:t,z:n};this.queenWorker.postMessage(a)}))}loadResourceFileWithData(e,t,n){return new Promise((function(s,r){this.loadUrlCallback=s;const a={t:m.LoadResourceFileWithData,b:e,n:t,z:n};this.queenWorker.postMessage(a)}))}checkResourceFile(e){return new Promise((function(t,n){this.stateCallback=t;const s={t:m.CheckResourceFile,n:e};this.queenWorker.postMessage(s)}))}setQueenBeautyType(e,t){const n={t:m.SetQueenBeautyType,p:e,s:t};this.queenWorker.postMessage(n)}setQueenBeautyParams(e,t){const n={t:m.SetQueenBeautyParams,p:e,v:t};this.queenWorker.postMessage(n)}getQueenBeautyParams(e){return new Promise((function(t,n){this.getParamsValueCallback=t;const s={t:m.GetQueenBeautyParams,p:e};this.queenWorker.postMessage(s)}))}setLutByType(e,t=.5){this.setQueenBeautyType(a.LUT,!0),this.setQueenBeautyParams(o.LUT,t);const n=j.getLutUrl(e);return this.setLutImageUrl(n)}setLutImageUrl(e){return new Promise(((t,n)=>{this.complateCallback=t;const s={t:m.SetLutImageUrl,p:e};this.queenWorker.postMessage(s)}))}setFaceShape(e,t){const n={t:m.SetFaceShape,p:e,v:t};this.queenWorker.postMessage(n)}setMakeupEyeBrow(e,t=h.LabMix){const[n,s]=j.getMakeupEyeBrowRes(e);return this.setMakeupWithPackage(l.EyeBrow,s,n,t)}setMackupEyeLash(e,t=h.LabMix){const n=j.getMakeupEyeLashUrl(e);return this.setMakeupWithUrl(l.Eyelash,n,t,20)}setMakeupEyeShadow(e,t=h.LabMix){const[n,s]=j.getMakeupEyeShadowRes(e);return this.setMakeupWithPackage(l.EyeShadow,s,n,t)}setMakeupEyeLiner(e,t=h.LabMix){const n=j.getMakeupEyeLinerUrl(e);return this.setMakeupWithUrl(l.Eyeliner,n,t,20)}setMakeupEyeBall(e,t=h.LabMix){const n=j.getMakeupEyeBallUrl(e);return this.setMakeupWithUrl(l.Eyeball,n,t,20)}setMakeupMouth(e,t=h.LabMix){const[n,s]=j.getMakeupMouthRes(e);return this.setMakeupWithPackage(l.EyeBrow,s,n,t)}setMakeupWhole(e,t=h.LabMix){const n=j.getMakeupWholeUrl(e);return this.setMakeupWithUrl(l.Whole,n,t,20)}setMakeupBlush(e,t=h.LabMix){const n=j.getMakeupBlushUrl(e);return this.setMakeupWithUrl(l.Blush,n,t,20)}setMakeupHighlight(e,t=h.LabMix){const n=j.getMakeupHighLightUrl(e);return this.setMakeupWithUrl(l.Highlight,n,t,20)}setMakeupWithUrl(e,t,n,s){return new Promise(((r,a)=>{this.complateCallback=r,void 0===s&&(s=20);const i={t:m.SetMakeupWithUrl,m:e,u:t,b:n,f:s};this.queenWorker.postMessage(i)}))}setMakeupWithPackage(e,t,n,s){return new Promise(((r,a)=>{this.complateCallback=r;const i={t:m.SetMakeupWithPackage,m:e,u:t,n:n,b:s};this.queenWorker.postMessage(i)}))}setMakeupWithType(e,t,n){return this.setMakeupWithTypeFps(e,t,n,20)}setMakeupWithTypeFps(e,t,n,s){const r={t:m.SetMakeupWithTypeFps,m:e,p:t,b:n,f:s};this.queenWorker.postMessage(r)}setMakeupFemaleAlpha(e,t){this.setMakeupAlphaWithType(e,!0,t)}setMakeupMaleAlpha(e,t){this.setMakeupAlphaWithType(e,!1,t)}setMakeupAlphaWithType(e,t,n){const s={t:m.SetMakeupAlphaWithType,m:e,f:t,a:n};this.queenWorker.postMessage(s)}setMakeupBlendWithType(e,t){const n={t:m.SetMakeupBlendWithType,m:e,b:t};this.queenWorker.postMessage(n)}resetAllMakeupType(){const e={t:m.ResetAllMakeupType};this.queenWorker.postMessage(e)}setBodyShape(e,t){const n={t:m.SetBodyShape,k:e,v:t};this.queenWorker.postMessage(n)}addMaterialWithType(e){const t=j.getStickerUrl(e);return this.addMaterialWithUrl(t)}addMaterialWithIndex(e){const t=j.getStickerUrlByIndex(e);return this.addMaterialWithUrl(t)}addMaterialWithUrl(e){return new Promise(((t,n)=>{this.complateCallback=t;const s={t:m.AddMaterialWithUrl,p:e};this.queenWorker.postMessage(s)}))}removeMaterialWithType(e){const t=j.getStickerUrl(e);this.removeMaterialWithUrl(t)}removeMaterialWithIndex(e){const t=j.getStickerUrlByIndex(e);this.removeMaterialWithUrl(t)}removeMaterialWithUrl(e){const t={t:m.RemoveMaterialWithUrl,p:e};this.queenWorker.postMessage(t)}showFaceDetectPoint(e){const t={t:m.ShowFaceDetectPoint,s:e};this.queenWorker.postMessage(t)}showMakeupLine(e){const t={t:m.ShowMakeupLine,s:e};this.queenWorker.postMessage(t)}showBodyDetectPoint(e){const t={t:m.ShowBodyDetectPoint,s:e};this.queenWorker.postMessage(t)}initArWriteResource(){const e=this,t=this.getWasmUrl()+"models/handmodels.bin";return new Promise((function(n,s){e.arWriteReady?n(!0):e.loadResourceData(t,(e=>{}),(function(e){const t={t:m.LoadQueenAssets,b:e};this.queenWorker.postMessage(t)}),(()=>{}),0,1)}))}setArWriting(e,t){const n={t:m.SetArWriting,s:e,m:t};this.queenWorker.postMessage(n)}cleanScreenArWriting(){const e={t:m.CleanScreenArWriting};this.queenWorker.postMessage(e)}setPowerSaving(e){const t={t:m.SetPowerSaving,s:e};this.queenWorker.postMessage(t)}animojiInitialize(e,t,n,s){return new Promise(((r,a)=>{this.complateCallback=r;const i={t:m.AnimojiInitialize,u:e,w:t,h:n,s:s};this.queenWorker.postMessage(i)}))}setAnimojiBackgroundWithMode(e,t){return new Promise(((n,s)=>{this.complateCallback=n;const r={t:m.SetAnimojiBackgroundWithMode,m:e,u:t};this.queenWorker.postMessage(r)}))}animojiRenderMediaObjectToRenderCanvas(e,t,n){return new Promise(((s,r)=>{this.queenReady&&!this.rendering||(this.queenAssert(),r()),this.renderComplateCallback=s;const a={t:m.AnimojiRenderMediaObjectToTexture,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(a)}))}animojiRender(e,t,n,s){if(!this.queenReady||this.rendering)return void this.queenAssert();this.imageBufferRenderCallback=s;const r={t:m.AnimojiRender,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(r,[e.buffer])}animojiRenderWithMediaObject(e,t,n,s){if(!this.queenReady||this.rendering)return void this.queenAssert();this.imageBufferRenderCallback=s;const r={t:m.AnimojiRenderWithMediaObject,d:e,w:t,h:n};this.rendering=!0,this.queenWorker.postMessage(r)}animojiRenderMediaObjectToTexture(e,t,n){return this.assertMessage(!1,"SDK does not support this API for Worker mode. not support WebGLTexture transfer."),null}animojiRenderTextureId(e,t,n){return this.assertMessage(!1,"SDK does not support this API for Worker mode. not support WebGLTexture transfer."),null}animojiResize(e){const t={t:m.AnimojiResize,s:e};this.queenWorker.postMessage(t)}animojiDestroy(){const e={t:m.AnimojiDestroy};this.queenWorker.postMessage(e)}engineDestory(){this.queenReady=!1,this.authState=!1;const e={t:m.EngineDestory};this.queenWorker.postMessage(e),this.queenWorker.terminate()}queenAssert(){this.queenReady||console.error("Queen Engine initialization failed."),this.authState||console.error("queen license authentication failed.")}assertMessage(e,t){e||console.error(t)}}kY(vY,"Assets",X),kY(vY,"kQueenBeautyType",a),kY(vY,"kQueenBeautyParams",o),kY(vY,"kBackgroundProcessType",d),kY(vY,"kQueenBeautyMakeupType",l),kY(vY,"kQueenBeautyFaceShapeType",c),kY(vY,"kQueenBeautyBlend",h),kY(vY,"kSegmentPerformanceMode",p),kY(vY,"kQueenModelShapeType",i),kY(vY,"kQueenBeautyBodyShapeType",u),kY(vY,"kQueenVersion",f);var IY=Object.defineProperty,SY=(e,t,n)=>(((e,t,n)=>{t in e?IY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class CY extends se{constructor(){super()}}SY(CY,"QueenEngineBase",ee),SY(CY,"QueenEngineLite",ie),SY(CY,"QueenEnginePro",mY),SY(CY,"QueenEngineFull",xY),SY(CY,"QueenEngineWorker",vY),SY(CY,"Assets",X),SY(CY,"kQueenBeautyType",a),SY(CY,"kQueenBeautyParams",o),SY(CY,"kBackgroundProcessType",d),SY(CY,"kQueenBeautyMakeupType",l),SY(CY,"kQueenBeautyFaceShapeType",c),SY(CY,"kQueenBeautyBlend",h),SY(CY,"kSegmentPerformanceMode",p),SY(CY,"kQueenModelShapeType",i),SY(CY,"kBackendType",b),SY(CY,"kQueenBeautyBodyShapeType",u),SY(CY,"kQueenVersion",f);var NY=Object.defineProperty,TY=(e,t,n)=>(((e,t,n)=>{t in e?NY(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,"symbol"!=typeof t?t+"":t,n),n);class $Y extends e{constructor(){super("AliRtcBeauty"),TY(this,"engineReady",!1),TY(this,"_queenEngine"),TY(this,"canvas"),TY(this,"dirty",!1),TY(this,"lastFrameTimestamp",0),TY(this,"continuousStuckCount",0),this.zIndex=0}get initOptions(){return{licenseKey:""}}setOptions(e){const t=!!e.segmentBackgroundProcess?.enable,n=!!e.setSegmentBackgroundImage?.backgroundImgUrl;this.options={...this.options,...e},n?delete this.options.segmentBackgroundProcess:t&&delete this.options.setSegmentBackgroundImage,this.engineReady&&this.queenEngine?.setEngineParams(this.options)}async init(){await this.initQueen()}isSupported(){const e=!("undefined"==typeof TransformStream||"undefined"==typeof MediaStreamTrackProcessor||"undefined"==typeof MediaStreamTrackGenerator),t=!("undefined"==typeof OffscreenCanvas||"undefined"==typeof WebGL2RenderingContext),n=WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]));return e&&t&&n}async initQueen(){this.canvas=document.createElement("canvas");const{licenseKey:e=""}=this.options,t=new vY(f.Pro);return this._queenEngine=t,await new Promise((n=>{t.init(e,(()=>{this.engineReady=!0,this.emit("ready"),t.setEngineParams(this.options),n(t)}),(function(){}),this.canvas)})),t}shouldUpdate(e){return this.videoUpdated(e)||this.dirty}async process(e){if(!e.originVideoTrack)return this.clear(e),void e.updateVideoTrack();if(!this.queenEngine||!this.engineReady)return;this.dirty=!1;const t=this.queenEngine.renderMediaStreamTrack(e.originVideoTrack);t&&e.updateVideoTrack(t)}get queenEngine(){return this._queenEngine}clear(e){this.canvas=void 0,this.engineReady=!1,this._queenEngine=void 0,this.queenEngine?.engineDestory(),super.clear(e)}}export{$Y as default};
|