V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2018-01-16 14:57:28 +08:00 · 2848 次点击
    这是一个创建于 2285 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现在有两个 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 条回复    2018-01-16 18:52:34 +08:00
    ivechan
        1
    ivechan  
       2018-01-16 15:38:23 +08:00
    我觉得你需要的是 SparseTensor.
    ipwx
        2
    ipwx  
       2018-01-16 15:56:49 +08:00
    我怎么觉得维度对不上啊? index: [?, 10],但是 result [?, 1000],怎么对的?
    qce7
        3
    qce7  
       2018-01-16 15:56:51 +08:00
    弱弱的问一下:result[index, :] = data, 这个是切片语法吗,index 是一个 Tensor 不是 int 类型没关系的吗
    jinyu121
        4
    jinyu121  
    OP
       2018-01-16 17:02:22 +08:00
    @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
        5
    ballshapesdsd  
       2018-01-16 17:17:55 +08:00
    楼主是自己做的项目还是工作用的
    rogerchen
        6
    rogerchen  
       2018-01-16 18:52:34 +08:00 via iPhone
    取下标请认准 gather scatter
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   894 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 21:23 · PVG 05:23 · LAX 14:23 · JFK 17:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.