MarvinTeichmann / tensorflow-fcn

An Implementation of Fully Convolutional Networks in Tensorflow.
MIT License
1.1k stars 433 forks source link

AttributeError: type object 'GraphKeys' has no attribute 'REGULARIZATION_LOSSES' #37

Closed FLSD-LEO closed 7 years ago

FLSD-LEO commented 7 years ago

Hi! I got this error.

npy file loaded Layer name: conv1_1 Layer shape: (3, 3, 3, 64) Traceback (most recent call last): File "test_fcn32_vgg.py", line 24, in vgg_fcn.build(batch_images, debug=True) File "/home/sheldon/tensorflow-fcn-master/fcn32_vgg.py", line 74, in build self.conv1_1 = self._conv_layer(bgr, "conv1_1") File "/home/sheldon/tensorflow-fcn-master/fcn32_vgg.py", line 135, in _conv_layer filt = self.get_conv_filter(name) File "/home/sheldon/tensorflow-fcn-master/fcn32_vgg.py", line 259, in get_conv_filter tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES, AttributeError: type object 'GraphKeys' has no attribute 'REGULARIZATION_LOSSES'

python 2.7 tensorflow1.2 Could you give me some suggestions?

MarvinTeichmann commented 7 years ago

This sounds strange. My tensorflow 1.2 Version has the attribute tf.GraphKeys.REGULARIZATION_LOSSES. (See output below).

As a workaround you can replace tf.GraphKeys.REGULARIZATION_LOSSES by any string. The string 'regularization_losses' would be an option. tf.GraphKeys.REGULARIZATION_LOSSES appears 10 times in the code (see second output).

Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
Type "copyright", "credits" or "license" for more information.

IPython 5.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import tensorflow as tf
In [2]: tf.GraphKeys.REGULARIZATION_LOSSES
Out[2]: 'regularization_losses'
In [3]: tf.__version__
Out[3]: '1.2.0'
In [4]: 
>> ack tf.GraphKeys.REGULARIZATION_LOSSES  
tensorflow-fcn/fcn32_vgg.py
259:            tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,
282:            tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,
362:            tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,

tensorflow-fcn/fcn8_vgg.py
290:            tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,
316:            tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,
394:        collection_name = tf.GraphKeys.REGULARIZATION_LOSSES
404:            collection_name = tf.GraphKeys.REGULARIZATION_LOSSES

tensorflow-fcn/fcn16_vgg.py
274:            tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,
297:            tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,
377:            tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES,
FLSD-LEO commented 7 years ago

Thanks for your reply! I have solved the problem by reinstalling. But I get another error like this.

2017-07-21 20:08:07.805898: W tensorflow/core/framework/op_kernel.cc:1158] Resource exhausted: OOM when allocating tensor with shape[1,4096,13,15] Traceback (most recent call last): File "test_fcn32_vgg.py", line 33, in down, up = sess.run(tensors, feed_dict=feed_dict) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 789, in run run_metadata_ptr) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 997, in _run feed_dict_string, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1132, in _do_run target_list, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1152, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[1,4096,13,15] [[Node: content_vgg/fc6/Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/gpu:0"](content_vgg/Print_4/_39, fc6/weights/read)]]

Caused by op u'content_vgg/fc6/Conv2D', defined at: File "test_fcn32_vgg.py", line 24, in vgg_fcn.build(batch_images, debug=True) File "/home/sheldon/tensorflow-fcn-master/fcn32_vgg.py", line 97, in build self.fc6 = self._fc_layer(self.pool5, "fc6") File "/home/sheldon/tensorflow-fcn-master/fcn32_vgg.py", line 159, in _fc_layer conv = tf.nn.conv2d(bottom, filt, [1, 1, 1, 1], padding='SAME') File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 399, in conv2d data_format=data_format, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2506, in create_op original_op=self._default_original_op, op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1269, in init self._traceback = _extract_stack()

ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[1,4096,13,15] [[Node: content_vgg/fc6/Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/gpu:0"](content_vgg/Print_4/_39, fc6/weights/read)]]

It seems like an out of memory error. I am a new to tensorflow. How could I solve it? By the way, tensors = [vgg_fcn.pred, vgg_fcn.pred_up] this is mean to do what?

MarvinTeichmann commented 7 years ago

It seems like an out of memory error. I am a new to tensorflow. How could I solve it?

Use a GPU with more Memory. Or reduce batch size or reduce size or input image or do computation on cpu.