TensorFlow limit the number of CPUs

Source: Internet
Author: User
Tags cpu usage
installation

This uses the Pip to install the TensorFlow CPU version

$ sudo pip install HTTPS://STORAGE.GOOGLEAPIS.COM/TENSORFLOW/LINUX/CPU/TENSORFLOW-0.5.0-CP27-NONE-LINUX_X86_64.WHL

Check the success of the installation with handwriting recognition examples from the runtime when the installation is complete

$ cd/usr/lib/python2.7/site-packages/tensorflow/models/image/mnist
$ python convolutional.py
...

or run

$ python-m tensorflow.models.image.mnist.convolutional ...
Limit number of CPUs

For the handwriting recognition examples used above, you need to modify the file/usr/lib/python2.7/site-packages/tensorflow/models/image/mnist/convolutional.py to create Session section

Modify the front with
    TF. Session (Config=config) as S:
modified
    cpu_num = Int (os.environ.get (' Cpu_num ', 1))
    config = tf. Configproto (device_count={"CPU": Cpu_num},
                inter_op_parallelism_threads = cpu_num,
                intra_op_parallelism_ Threads = Cpu_num,
                log_device_placement=true) with

    TF. Session (Config=config) as S:

After the modification is complete, use the environment variable cpu_num to specify the number of CPUs you want to use, and then run the handwriting recognition example again

$ export cpu_num=2
$ python-m tensorflow.models.image.mnist.convolutional

After running, use the top command to view the program's CPU usage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.