zoukankan      html  css  js  c++  java
  • TF基础2

    1.常用API

    1.图,操作和张量
    tf.Graph,tf.Operation,tf.Tensor

    2.可视化
    TensorBoard

    3.变量作用域
    在TF中有两个作用域(scope),一个是name_scope,另一个是variable_scope.他们有什么区别呢?
    variable_scope主要是给variable_name加前缀,也可以给op_name加前缀;name_scope是给op_name加前缀。

    variable_scope变量作用域机制在TF中主要有两部分组成:

    v=tf.get_variable(name,shape,dtype,initializer)#通过所给的名字创建或是返回一个变量
    tf.variable_scope(<scope_name>)#为变量指定命名空间
    

    当tf.get_variable_scope().reuse==False时,variable_scope作用域只能用来创建新变量:

    with tf.variable_scope("foo"):
    v=tf.get_variable("v",[1])
    v2=tf.get_variable("v",[1])
    assert v.name=="foo/v:0"
    

    当tf.get_variable_scope().reuse==True时,variable_scope作用域可以共享变量:

    with tf.variable_scope("foo") as scope:
         v=tf.get_variable("v",[1])
    
    with tf.variable_scope("foo",reuse=True):
         v1=tf.get_variable("v",[1])
    assert v1==v
    
    

    获取变量作用域:可以直接通过tf.variable_scope()来获取变量作用域:

    with tf.variable_scope("foo") as scope:
         v=tf.get_variable("v",[1])
    with tf.variable_scope(foo_scope):
         w=tf.get_variable("w",[1])
    
    

    如果在开启一个变量作用域使用之前预先定义一个作用域,则会跳过当前变量的作用域,保持预先存在的作用域不变。
    变量作用域初始化,可以默认携带一个初始化器。

  • 相关阅读:
    刨析js代码执行机制
    H5离线缓存基础系列
    meta 详解
    如何成长为一名合格的web架构师?
    整理的互联网公司面试趋势
    http协议
    前端现在到底需要什么样的人才
    webpack 4.0 版本的简单使用
    vue的懒加载如何实现?
    Runtime的几个小例子(含Demo)
  • 原文地址:https://www.cnblogs.com/Ann21/p/10479371.html
Copyright © 2011-2022 走看看