推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
jinyu121
V2EX  ›  Python

TensorFlow 求助~

  •  
  •   jinyu121 · Jan 16, 2018 · 3794 views
    This topic created in 3215 days ago, the information mentioned may be changed or developed.

    现在有两个 Tensor (注意是 Tensor,而不是 Variable 或者 Placeholder )

    index: [None, 10] dtype=tf.int
    data: [None, 10, 4] dtype=tf.float32
    

    我想做另外一个 Tensor

    result: [None, 1000, 4] dtype=tf.float32
    

    想实现的内容是

    result[index, :] = data
    

    求各位有什么好的解决方案么?

    注意第一维( Batch 维)是 None~,注意已知的是两个 Tensor

    自己的各种想法都被卡在了这个 Tensor 和 None 上了。

    6 replies  •  2018-01-16 18:52:34 +08:00
    ivechan
    ivechan
    Jan 16, 2018
    1
    我觉得你需要的是 SparseTensor.
    ipwx
    ipwx
    Jan 16, 2018
    2
    我怎么觉得维度对不上啊? index: [?, 10],但是 result [?, 1000],怎么对的?
    qce7
    qce7
    Jan 16, 2018
    3
    弱弱的问一下:result[index, :] = data, 这个是切片语法吗,index 是一个 Tensor 不是 int 类型没关系的吗
    jinyu121
    jinyu121
    OP
    Jan 16, 2018
    4
    @ivechan SparseTensor 卡在了第一维 None 上
    @ipwx 想象一下 index 长度是 10,result 长度是 1000,除了 result[index]之外,其余值都是 0
    @qce7 是切片……是 Tensor ……但是 TensorFlow 不支持切片当左值

    目前绕过方案,那个 None 是从 Dataset 里面带出来的,所以用`dataset = dataset.apply(tf.contrib.data.batch_and_drop_remainder(batch_size))` 可以把 None 搞掉。之后用`scatter_nd`或者`scatter_nd_update`来搞。 @ivechan 的 SparseTensor 也是一个不错的选择。
    ballshapesdsd
    ballshapesdsd
    Jan 16, 2018
    5
    楼主是自己做的项目还是工作用的
    rogerchen
    rogerchen
    Jan 16, 2018 via iPhone
    6
    取下标请认准 gather scatter
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2678 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:11 · PVG 21:11 · LAX 05:11 · JFK 08:11
    ♥ Do have faith in what you're doing.