推荐学习书目
› 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
sadfQED2
V2EX  ›  Python

Python 如何利用多线程能力呢?

  •  
  •   sadfQED2 · Oct 29, 2021 · 2018 views
    This topic created in 1801 days ago, the information mentioned may be changed or developed.

    机器学习炼丹过程中,图片预处理速度完全跟不上训练速度。看了下电脑 cpu 和内存,才占用 20%不到,有啥办法提升下吗

    伪代码

    im = openImg("xxxx.png") # 已经确定这里不是瓶颈,磁盘 io 没问题
    im=dosome(im)  # 图片预处理(主要是裁剪,缩放,修改格式等待),使用 pillow 库  ,目前瓶颈在这里
    
    data = nnumpy.array(im) # 转成数组
    
    # 提交 TensorFlow 炼丹
    
    

    想问下,dosome 那一步有什么办法并发吗?

    fgwmlhdkkkw
        1
    fgwmlhdkkkw  
       Oct 29, 2021
    你都说了多线程呀。虽然有 GIL ,但是依然会有提升的。
    fgwmlhdkkkw
        2
    fgwmlhdkkkw  
       Oct 29, 2021
    也可以开多个进程,每个进程负责一部分图片。
    imycc
        3
    imycc  
       Oct 31, 2021
    IO 多的可以用多线程,计算多的用多进程,去看下 multiprocessing 这个库咯
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1103 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:11 · PVG 01:11 · LAX 10:11 · JFK 13:11
    ♥ Do have faith in what you're doing.