V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
panins
V2EX  ›  TensorFlow

expand_dims 中的困惑

  •  
  •   panins · 2018-01-21 22:35:24 +08:00 · 3573 次点击
    这是一个创建于 2280 天前的主题,其中的信息可能已经有所发展或是发生改变。

    买了一《 tensorflow 机器学习实战指南》,自己学到了第六章,神经网络算法。

    但是有个简单例子小弟一时半会卡在这里,大家是否可以抽空指导一下。

    谢谢

    6.5 用 TENSORFLOW 实现神经网络常见层

    我的问题是定义卷积层函数的时候,书上说把 1D 扩展到 4D。

    为什么 input_4d = tf.expand_dims(input_3d, 3)第二个参数用了 3,而 input_1-3d 都是 0

    import tensorflow as tf
    import numpy as np
    sess = tf.Session()
    data_size = 25
    data_1d = np.random.normal(size=data_size)
    x_input_1d = tf.placeholder(dtype=tf.float32, shape=[data_size])
    
    
    def conv_layer_1d(input_1d, my_filter):
        # make 1d input into 4d
        input_2d = tf.expand_dims(input_1d, 0)
        input_3d = tf.expand_dims(input_2d, 0)
        input_4d = tf.expand_dims(input_3d, 3)
        # perform convolution
        convolution_output = tf.nn.conv2d(input_4d, filter=my_filter,
                                          strides=[1,1,1,1], padding="VALID")
        conv_output_1d = tf.squeeze(convolution_output)
        return(conv_output_1d)
    
    my_filter = tf.Variable(tf.random_normal(shape=[1,5,1,1]))
    my_convolution_output = conv_layer_1d(x_input_1d, my_filter)
    ......
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2198 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 446ms · UTC 00:24 · PVG 08:24 · LAX 17:24 · JFK 20:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.