提交 aa2335c2 编写于 作者: S sneaxiy

add py_reader doc

上级 3334c279
...@@ -563,6 +563,7 @@ def _py_reader(capacity, ...@@ -563,6 +563,7 @@ def _py_reader(capacity,
def start_provide_thread(func): def start_provide_thread(func):
def __provider_thread__(): def __provider_thread__():
try:
for tensors in func(): for tensors in func():
array = core.LoDTensorArray() array = core.LoDTensorArray()
for item in tensors: for item in tensors:
...@@ -579,6 +580,9 @@ def _py_reader(capacity, ...@@ -579,6 +580,9 @@ def _py_reader(capacity,
if reader.exited: if reader.exited:
break break
feed_queue.close() feed_queue.close()
except Exception as ex:
feed_queue.close()
raise ex
reader.thread = threading.Thread(target=__provider_thread__) reader.thread = threading.Thread(target=__provider_thread__)
reader.thread.daemon = True reader.thread.daemon = True
...@@ -692,6 +696,11 @@ def py_reader(capacity, ...@@ -692,6 +696,11 @@ def py_reader(capacity,
>>> exe.run(fetch_list=[loss.name]) >>> exe.run(fetch_list=[loss.name])
>>> except fluid.core.EOFException: >>> except fluid.core.EOFException:
>>> reader.reset() >>> reader.reset()
>>>
>>> ...
>>>
>>> fluid.io.save_inference_model(dirname='./model', feeded_var_names=[img, label],
>>> target_vars=[loss], executor=fluid.Executor(fluid.CUDAPlace(0)))
2. When training and testing are both performed, two different 2. When training and testing are both performed, two different
:code:`py_reader` should be created with different names, e.g.: :code:`py_reader` should be created with different names, e.g.:
......
...@@ -250,6 +250,7 @@ class PyReader(object): ...@@ -250,6 +250,7 @@ class PyReader(object):
def _start(self): def _start(self):
def __thread_main__(): def __thread_main__():
try:
for tensors in self._tensor_reader(): for tensors in self._tensor_reader():
array = core.LoDTensorArray() array = core.LoDTensorArray()
for item in tensors: for item in tensors:
...@@ -264,6 +265,9 @@ class PyReader(object): ...@@ -264,6 +265,9 @@ class PyReader(object):
break break
self._queue.close() self._queue.close()
except Exception as ex:
self._queue.close()
raise ex
self._thread = threading.Thread(target=__thread_main__) self._thread = threading.Thread(target=__thread_main__)
self._thread.daemon = True self._thread.daemon = True
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册