- 浏览: 680059 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (181)
- Matlab (16)
- Java (26)
- autoHotkey (4)
- openCV (1)
- C++ (50)
- PDF-XChange Viewer (2)
- 学术 (11)
- javascript (4)
- linux (11)
- SWT (9)
- latex (7)
- GAE (2)
- windows (6)
- C# (3)
- PS (20)
- JNI (4)
- latex,批处理 (0)
- 批处理 (4)
- Android (5)
- 矩阵论 (1)
- SVM (1)
- 概率图模型 (0)
- Python (12)
- Eigen (5)
- 编程题 (1)
- MKL (1)
- 神经网络 (9)
- 最优化 (2)
- 摄影 (1)
- PPT (0)
- After Effects (3)
- CUDA (3)
- caffe (0)
- MXNet (2)
- svn (1)
- R (0)
- 虚拟机 (0)
- tensorflow (7)
- theano (1)
- Keras (1)
- vim (1)
- xgboost (1)
- spark (6)
- eclipse (2)
- word2vec (0)
- hadoop (1)
- dmlc (1)
- git (0)
最新评论
-
jeffersonz:
请问大神,这个插件记录下来的脚本为什么不能再Extendscr ...
PhotoShop - 记录PS的所有操作为JavaScript代码 -
cherishLC:
Andy__Zou 写道cherishLC 写道Andy__Z ...
Eigen的编译选项;MKL的使用 -
Andy__Zou:
cherishLC 写道Andy__Zou 写道cherish ...
Eigen的编译选项;MKL的使用 -
cherishLC:
Andy__Zou 写道cherishLC 写道Andy__Z ...
Eigen的编译选项;MKL的使用 -
Andy__Zou:
cherishLC 写道Andy__Zou 写道 您好,您的工 ...
Eigen的编译选项;MKL的使用
在使用tf.data等模块时,tensorflow会产生内存泄露;当内存泄露发生时,我们期望及时保存checkpoint,返回相应的状态,然后重新启动tensorflow进行增量训练。
如果采用subprocess.call()方案在子进程中调用tensorflow,需要自行实现参数、结果的序列化和反序列化,比较麻烦。
本文给出一种通过multiprocessing模块在子进程中调用tensorflow的实现,传参数so easy
话不多说,上代码:
如果采用subprocess.call()方案在子进程中调用tensorflow,需要自行实现参数、结果的序列化和反序列化,比较麻烦。
本文给出一种通过multiprocessing模块在子进程中调用tensorflow的实现,传参数so easy
话不多说,上代码:
# coding=utf-8 ''' Created on Sep 18, 2018 @author: colinliang ''' from __future__ import absolute_import, division, print_function def run_tf(args, queue=None): print('\n\n------- beginning of tf process') print('args for tf: %s' % args) import tensorflow as tf sess = tf.Session() import psutil mem_start=psutil.virtual_memory().available batch=2000000 n=(args['epoch']+1) *batch with tf.device('/cpu:0'): v = tf.get_variable(name="tf_var", shape=[n], dtype=tf.float32, initializer=tf.random_uniform_initializer(-1, 1, 0, dtype=tf.float32)) sess.run(tf.global_variables_initializer()) # print( (mem_start-psutil.virtual_memory().available)/batch) if(mem_start-psutil.virtual_memory().available >batch*12): #内存检测,有内存泄露时及时退出 result={'exit code':-1} if(queue is not None): queue.put(result) return result import time time.sleep(10) r = sess.run(v[0]) print('sess: %s' % sess) sess.close() # tf.reset_default_graph() result={'first elem of tf var':r} if(queue is not None): queue.put(result) print('------- end of tf process') return result ##################################################### from multiprocessing import Process, Queue # 参考自https://stackoverflow.com/questions/39758094/clearing-tensorflow-gpu-memory-after-model-execution for i in range(5): # Process的使用方法 https://docs.python.org/2/library/multiprocessing.html q = Queue() args = {'epoch':i} p = Process(target=run_tf, args=(args, q)) p.start() p.join() print("result: %s" % q.get())
发表评论
-
tensorflow 静态编译笔记 -- linux系统
2018-11-05 14:26 0注: 1、编译tensorflow静态库 很简单,参见: h ... -
python subprocess shell=True False 的异同
2018-09-13 10:21 2202参见:https://stackoverflow.com/qu ... -
利用pyenv管理默认python版本
2017-08-07 17:03 10901、遇到的问题 linux系统中同时存在python2和pyt ... -
Tensorflow 通过性能分析工具查看变量位置
2017-03-30 16:20 5253发现个更好的方法,只 ... -
tensorflow中的word2vec
2017-03-21 11:12 0官方tutorial: https://www.tensorf ... -
python 获取 当前行号,函数名称, 文件名
2017-02-15 15:30 3130博客http://blog.csdn.net/ksearch/ ... -
tensorflow 字符串转数字(hash函数, 字符串解析为数字)
2017-02-10 10:42 0问题描述 tensorflow可以直接解析csv文件, 但是对 ... -
tensorflow 单机多卡示例--数据并行
2017-01-05 14:44 9481本文参考自官方的cifar10 ... -
linux下将python作为后台服务
2016-12-16 14:00 15481、启动后台服务 不会写shell脚本,直接调用python: ... -
python代码优化笔记,cython等
2016-10-03 15:53 1791本文主要是整理看过的不错的文章,具体内容请参考对应链接 1、 ... -
tensorflow杂记
2016-09-18 12:04 11541本文记录使用tensorflow AP ... -
Keras切换backend : theano --> tensorflow
2016-09-07 10:57 66581、切换backend 修改~/.keras/keras.js ... -
Ubuntu16.04 源码安装GPU版tensorflow
2016-08-07 16:18 56132017年2月16日更新: tenso ... -
神经网络计算加法---tensorflow中的变量的embedding表示
2016-07-28 10:53 10053将category变量输入到神经网络中时需要进行embeddi ... -
tensorflow 之tensorboard
2016-07-12 11:15 01、端口被占用 开启第二个tensorboard时会出现此种情 ... -
python 列出安装的包
2016-07-07 15:35 511参考自:http://stackoverflow.com/qu ... -
windows下编译Python包
2016-06-11 23:31 986编译python包出现“unable to find vcva ... -
windows 10下安装GPU版MXNet
2016-06-03 21:28 8532上回说到编译CPU版的MXNet: http://cheris ... -
cs231n 笔记
2016-05-26 23:36 01、python3中 cifar10数据库的读取 cs231n ... -
Python语法资料汇总
2016-06-01 17:23 9121、python2转python3 python2和pytho ...
相关推荐
主要介绍了Python3多进程 multiprocessing 模块,结合实例形式详细分析了Python3多进程 multiprocessing 模块的概念、原理、相关方法使用技巧与注意事项,需要的朋友可以参考下
一 multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu\_count\(\)查看),在python中大部分情况需要使用多进程。 Python提供了multiprocessing。 ...
主要介绍了Python进程Multiprocessing模块原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
所谓并发无非多线程和多进程,最初找到的是threading模块,因为印象中线程“轻量…”,“切换快…”,“可共享进程资源…”等等,但是没想到这里水很深,进而找到了更好的替代品multiprocessing模块。下面会讲一些...
multipressing模块是python 2.6版本加入的,通过这个模块可以轻松实现异步调用 from multiprocessing import Pool def f(x): return x*x if __name__ == '__main__': pool = Pool(processes=1) # Start a worker...
主要介绍了Python multiprocessing模块中的Pipe管道使用实例,本文直接给出使用实例,需要的朋友可以参考下
主要介绍了Python多线程threading和multiprocessing模块等相关内容,分享了相关代码示例,小编觉得还是挺不错的,这里分享给大家,需要的朋友可以参考下
精品专题课件(2021-2022年收藏)
资源来自pypi官网。 资源全名:qt_multiprocessing-0.0.2.tar.gz
RGB’s Video Multiprocessing Gateway (VMG) product line offers the industry’s first high-density, carrier-class platform for the delivery of advanced video services, including high definition (HD) ...
主要介绍了Python使用multiprocessing创建进程的方法,实例分析了multiprocessing模块操作进程的相关技巧,需要的朋友可以参考下
Python_multiprocessing_4_效率对比_multithreading,_multiprocessing_co
一、 multiprocessing 模块 1. multiprocessing 模块提供了多进程编程的能力 它的API非常类似于 threading 模块,但是也提供了一些threading 模块不具有的能力 相比于线程,它通过派生子进程来绕过GIL 的限制,从而...