models icon indicating copy to clipboard operation
models copied to clipboard

[object_detection] "RuntimeError: main thread is not in main loop"and"tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocat ing tensor with shape[64,6426,48] and type float on /job:localhost/replica:0/tas k:0/device:GPU:0 by allocator GPU_0_bfc"

Open jj19940807 opened this issue 8 years ago • 5 comments

the config file I used is "ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync.config", "batch_size" default value is 64. an error occurred at run time

2018-07-17 23:38:53.847260: I T:\src\github\tensorflow\tensorflow\core\common_ru ntime\bfc_allocator.cc:680] Stats: Limit: 3532349440 InUse: 3437157888 MaxInUse: 3531101696 NumAllocs: 6995 MaxAllocSize: 1090912256

2018-07-17 23:38:53.848260: W T:\src\github\tensorflow\tensorflow\core\common_ru ntime\bfc_allocator.cc:279] **************************************************** ***********************************************x Traceback (most recent call last): File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\client\session.py", line 1322, in _do_call return fn(*args) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\client\session.py", line 1307, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\client\session.py", line 1409, in _call_tf_session run run_metadata) tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocat ing tensor with shape[64,6426,48] and type float on /job:localhost/replica:0/tas k:0/device:GPU:0 by allocator GPU_0_bfc [[Node: swap_in_Loss/Loss_1/sub_1_1 = _CopyFromHostToGpu[T=DT_FLOAT, _c lass=["loc@Loss/Loss_1/sub_1_1"], _device="/job:localhost/replica:0/task:0/devic e:GPU:0"](swap_out_Loss/Loss_1/sub_1_1, ^WeightSharedConvolutionalBoxPredictor/C lassPredictor/BiasAdd)]] Hint: If you want to see a list of allocated tensors when OOM happens, add repor t_tensor_allocations_upon_oom to RunOptions for current allocation info.

I don't know why. I felt like there might be not enough memory. I tried to change the value of "batch_size" to a smaller value,but a new error has emerged .

Traceback (most recent call last): File "object_detection\model_main.py", line 101, in tf.app.run() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\platform\app.py", line 125, in run _sys.exit(main(argv)) File "object_detection\model_main.py", line 97, in main tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0]) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\training.py", line 447, in train_and_eva luate return executor.run() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\training.py", line 531, in run return self.run_local() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\training.py", line 669, in run_local hooks=train_hooks) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\estimator.py", line 366, in train loss = self._train_model(input_fn, hooks, saving_listeners) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\estimator.py", line 1119, in _train_mode l return self._train_model_default(input_fn, hooks, saving_listeners) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\estimator.py", line 1135, in _train_mode l_default saving_listeners) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\estimator.py", line 1336, in _train_with _estimator_spec _, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss]) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\training\monitored_session.py", line 577, in run run_metadata=run_metadata) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\training\monitored_session.py", line 1053, in run run_metadata=run_metadata) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\training\monitored_session.py", line 1144, in run raise six.reraise(*original_exc_info) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\six.py", line 693, in reraise raise value File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\training\monitored_session.py", line 1129, in run return self._sess.run(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\training\monitored_session.py", line 1201, in run run_metadata=run_metadata) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\training\monitored_session.py", line 981, in run return self._sess.run(*args, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\client\session.py", line 900, in run run_metadata_ptr) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\client\session.py", line 1135, in _run feed_dict_tensor, options, run_metadata) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\client\session.py", line 1316, in _do_run run_metadata) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\client\session.py", line 1335, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.UnknownError: RuntimeError: main thread is not in main loop Traceback (most recent call last):

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\ops\script_ops.py", line 158, in call ret = func(*args)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\si te-packages\tensorflow\models-master\research\object_detection\utils\visualizati on_utils.py", line 693, in cdf_plot fig = plt.figure(frameon=False)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\matplotlib\pyplot.py", line 548, in figure **kwargs)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\matplotlib\backend_bases.py", line 161, in new_figure_manager return cls.new_figure_manager_given_figure(num, fig)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\matplotlib\backends_backend_tk.py", line 1053, in new_figure_manage r_given_figure icon_img = Tk.PhotoImage(file=icon_fname)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\tk inter_init_.py", line 3542, in init Image.init(self, 'photo', name, cnf, master, **kw)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\tk inter_init_.py", line 3498, in init self.tk.call(('image', 'create', imgtype, name,) + options)

RuntimeError: main thread is not in main loop

     [[Node: Loss/PyFunc_1 = PyFunc[Tin=[DT_FLOAT], Tout=[DT_UINT8], token="

pyfunc_1", device="/job:localhost/replica:0/task:0/device:CPU:0"](Loss/Squeeze 1/_5297)]] [[Node: train/update_FeatureExtractor/resnet_v1_50/block4/unit_1/bottle neck_v1/conv1/weights/ApplyMomentum/_8102 = _Recvclient_terminated=false, recv_ device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localho st/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_ 10150...lyMomentum", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/tas k:0/device:GPU:0"]]

Caused by op 'Loss/PyFunc_1', defined at: File "object_detection\model_main.py", line 101, in tf.app.run() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\platform\app.py", line 125, in run _sys.exit(main(argv)) File "object_detection\model_main.py", line 97, in main tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0]) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\training.py", line 447, in train_and_eva luate return executor.run() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\training.py", line 531, in run return self.run_local() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\training.py", line 669, in run_local hooks=train_hooks) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\estimator.py", line 366, in train loss = self._train_model(input_fn, hooks, saving_listeners) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\estimator.py", line 1119, in _train_mode l return self._train_model_default(input_fn, hooks, saving_listeners) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\estimator.py", line 1132, in _train_mode l_default features, labels, model_fn_lib.ModeKeys.TRAIN, self.config) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\estimator\estimator.py", line 1107, in _call_model _fn model_fn_results = self._model_fn(features=features, **kwargs) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\si te-packages\tensorflow\models-master\research\object_detection\model_lib.py", li ne 282, in model_fn prediction_dict, features[fields.InputDataFields.true_image_shape]) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\si te-packages\tensorflow\models-master\research\object_detection\meta_architecture s\ssd_meta_arch.py", line 597, in loss flattened_class_ids, flattened_classification_losses) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\si te-packages\tensorflow\models-master\research\object_detection\meta_architecture s\ssd_meta_arch.py", line 660, in _summarize_anchor_classification_loss 'NegativeAnchorLossCDF') File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\si te-packages\tensorflow\models-master\research\object_detection\utils\visualizati on_utils.py", line 703, in add_cdf_image_summary cdf_plot = tf.py_func(cdf_plot, [values], tf.uint8) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\ops\script_ops.py", line 384, in py_func func=func, inp=inp, Tout=Tout, stateful=stateful, eager=False, name=name) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\ops\script_ops.py", line 227, in _internal_py_func

input=inp, token=token, Tout=Tout, name=name)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\ops\gen_script_ops.py", line 130, in py_func "PyFunc", input=input, token=token, Tout=Tout, name=name) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\framework\op_def_library.py", line 787, in apply op_helper op_def=op_def) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\framework\ops.py", line 3414, in create_op op_def=op_def) File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\framework\ops.py", line 1740, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected- access

UnknownError (see above for traceback): RuntimeError: main thread is not in main loop Traceback (most recent call last):

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\tensorflow\python\ops\script_ops.py", line 158, in call ret = func(*args)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\si te-packages\tensorflow\models-master\research\object_detection\utils\visualizati on_utils.py", line 693, in cdf_plot fig = plt.figure(frameon=False)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\matplotlib\pyplot.py", line 548, in figure **kwargs)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\matplotlib\backend_bases.py", line 161, in new_figure_manager return cls.new_figure_manager_given_figure(num, fig)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\matplotlib\backends_backend_tk.py", line 1053, in new_figure_manage r_given_figure icon_img = Tk.PhotoImage(file=icon_fname)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\tk inter_init_.py", line 3542, in init Image.init(self, 'photo', name, cnf, master, **kw)

File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\tk inter_init_.py", line 3498, in init self.tk.call(('image', 'create', imgtype, name,) + options)

RuntimeError: main thread is not in main loop

     [[Node: Loss/PyFunc_1 = PyFunc[Tin=[DT_FLOAT], Tout=[DT_UINT8], token="

pyfunc_1", device="/job:localhost/replica:0/task:0/device:CPU:0"](Loss/Squeeze 1/_5297)]] [[Node: train/update_FeatureExtractor/resnet_v1_50/block4/unit_1/bottle neck_v1/conv1/weights/ApplyMomentum/_8102 = _Recvclient_terminated=false, recv_ device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localho st/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_ 10150...lyMomentum", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/tas k:0/device:GPU:0"]]

Error in atexit.run_exitfuncs: Traceback (most recent call last): File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\matplotlib_pylab_helpers.py", line 78, in destroy_all manager.destroy() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\matplotlib\backends_backend_tk.py", line 558, in destroy self.window.destroy() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\tk inter_init.py", line 2058, in destroy for c in list(self.children.values()): c.destroy() File "D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\tk inter_init_.py", line 2302, in destroy self.tk.call('destroy', self._w) RuntimeError: main thread is not in main loop

jj19940807 avatar Jul 17 '18 15:07 jj19940807

Try setting the batch size smaller. That usually gets rid of the OOM error. I think its because you are out of memory. The "main thread is not in main loop" error is a similar issue that im having(#4791), let me know if you find a solution for it?

MonkeyWithAComputer avatar Jul 17 '18 21:07 MonkeyWithAComputer

@MonkeyWithAComputer I'm also facing the same problem. I'm using 2 K80 GPU cards to training on my dataset. My dataset consists of 20k images. I tried using a smaller batch size but it still the same.

alvinxiii avatar Jul 20 '18 06:07 alvinxiii

I'm having the same problem. I'm training on 2 Titan XP. When I set the batch size to a small enough value I get the same RuntimeError.

normandra avatar Jul 23 '18 11:07 normandra

One line 703 of utils/visualization_utils.py change cdf_plot=tf.py_func(cdf_plot, [values], tf.uint8) to cdf_plot=tf.py_func(cdf_plot, [values], tf.float32)

this will eliminate the errors, or at least it did for me

MichaelX99 avatar Jul 23 '18 16:07 MichaelX99

Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.

tensorflowbutler avatar Jan 29 '20 23:01 tensorflowbutler