tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

'convolutional.py' considered harmful?

Open markusdr opened this issue 10 years ago • 9 comments

The get started page recommends to run convolutional.py as the first tensorflow neural net model:

$ cd tensorflow/models/image/mnist
$ python convolutional.py

However, running it brought my machine down. After bringing it up again, the NVIDIA driver didn't work properly anymore (the boot messages showed nvidia-related errors and nvidia-smi became slow). I fixed it by booting into single-user mode and reinstalling the NVIDIA/CUDA drivers.

My desktop has two GPUs of type GeForce GTX 780 Ti with 3GB memory each.

I assume that convolutional.py uses too much GPU memory. Maybe a gentler script should be used in the getting-started manual.

markusdr avatar Dec 23 '15 21:12 markusdr

A simple way to shave off memory is to replace the giant testset loaded in a constant with a placeholder that gets fed with a small loop at evaluation time. I didn't do that to keep the code as simple as possible, but since several people have commented on having this issue, it might be worth changing it. I'd like confirmation that this would actually fix the problem however; @markusdr would you be able to hack that together and let me know if that solves your problem?

vincentvanhoucke avatar Dec 26 '15 15:12 vincentvanhoucke

Yes, using fewer images for the validation set and the test set solves the issue. I tested with 500 images for each of the two data sets, and it worked well.

markusdr avatar Dec 28 '15 18:12 markusdr

@markusdr can you share how did you change in the convolutional.py?
I run it encounter resource exhausted: OOM thanks.

gotope avatar Jan 04 '16 11:01 gotope

@gotope Here is the diff:

--- a/tensorflow/models/image/mnist/convolutional.py
+++ b/tensorflow/models/image/mnist/convolutional.py
@@ -40,7 +40,7 @@ IMAGE_SIZE = 28
 NUM_CHANNELS = 1
 PIXEL_DEPTH = 255
 NUM_LABELS = 10
-VALIDATION_SIZE = 5000  # Size of the validation set.
+VALIDATION_SIZE = 500  # Size of the validation set.
 SEED = 66478  # Set to None for random seed.
 BATCH_SIZE = 64
 NUM_EPOCHS = 10
@@ -126,8 +126,8 @@ def main(argv=None):  # pylint: disable=unused-argument
     # Extract it into numpy arrays.
     train_data = extract_data(train_data_filename, 60000)
     train_labels = extract_labels(train_labels_filename, 60000)
-    test_data = extract_data(test_data_filename, 10000)
-    test_labels = extract_labels(test_labels_filename, 10000)
+    test_data = extract_data(test_data_filename, 500)
+    test_labels = extract_labels(test_labels_filename, 500)

     # Generate a validation set.
     validation_data = train_data[:VALIDATION_SIZE, :, :, :]

markusdr avatar Jan 04 '16 19:01 markusdr

@markusdr thanks for share it, it works .

gotope avatar Jan 05 '16 14:01 gotope

Evals should now be batched, pending propagation of the changes. Feel free to reopen if you see more memory issues.

vincentvanhoucke avatar Jan 07 '16 19:01 vincentvanhoucke

I don't think it's been pushed yet -- will leave it open until it is.

vrv avatar Jan 07 '16 21:01 vrv

Ok, pushed.

vrv avatar Jan 07 '16 23:01 vrv

I also had this error, but with a GeForce GTX 660 with 2GB memory. I experimented and was able to successfully test up to 7850 images in the test set. However, after about 5000 images, it would come up with a warning:

W tensorflow/core/common_runtime/bfc_allocator.cc:213] Ran out of memory trying to allocate 705.73MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
W tensorflow/core/common_runtime/bfc_allocator.cc:213] Ran out of memory trying to allocate 2.60GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.

I've added this comment just for info, in case there was something more fundamentally wrong. As the GTX 660 nearly processed (7900 images is the failure point) the test set, I'm not sure why the GTX780 couldn't process the whole 10000 images as it has half again as much memory

PeterQFR avatar Apr 15 '16 02:04 PeterQFR