Location>code7788 >text

Deploying CPU and GPU generalized tensorflow: the Anaconda environment

Popularity:568 ℃/2024-08-06 14:09:28

  This article describes how inAnacondaenvironment, download and configure thePythonA new version of the commonly used machine learning, deep learning intensorflowThe library approach.

  In two previous postsPython TensorFlow deep learning regression code: DNNRegressortogether withPython TensorFlow deep neural network regression:In it, we introduced the use ofPythonhit the nail on the headtensorflowlibrary that implements themachine learningtogether withdeep learningspecific ideas and code implementations; however, there was no specific description of the originaltensorflowlibrary configuration method. So, in this article, we'll cover the methods for configuring the library in theAnacondaenvironment, configure thetensorflowlibrary for detailed methods; in addition, it should be noted here that in newer versions of thetensorflowLibraries (versions greater than1.5 But forWindowsFor users, the version cannot yet be higher than2.10), which already supports bothCPUGPUtraining, there is no longer a need to distinguish between being configuredCPUversion of the library or theGPUversion of the library now.

  First, andAnacondaenvironment to configure other libraries as well, we need to open theAnaconda Promptsoftware; as shown below.

image

  A terminal window will then pop up as shown below.

  Next, we can begintensorflowConfiguration of the library. Since I'm hoping here to set thetensorflowlibrary is configured to another existingAnacondaIn the virtual environment (the name of this virtual environment ispy36tfPythonThe version is3.6) instead of this current defaultbaseenvironment and therefore need to follow the articleWays to create an Anaconda virtual Python environmentThe first thing to do is to go to the program calledpy36tfin the virtual environment, as shown in the following figure.

  If people need to configure the default environment intensorflowlibraries, you can perform the next actions directly; if you wish to create a new environment to configure thetensorflowlibrary, then refer to the article mentioned aboveWays to create an Anaconda virtual Python environment, create and enter a new virtual environment, and then just continue with the next actions.

  Next, go ahead and enter the following code to begin configuration immediatelytensorflowCoop.

pip install --upgrade tensorflow

  After running the above code, you can see that it will start immediatelytensorflowThe library is configured as shown below. Among other things, since I'm herePythonThe version is3.6of the newestPythonversion, so as you can see from the image belowtensorflowThe library version is also not up-to-date, but2.6.2version of it - and that's certainly enough for me. If people wish to use the latest version oftensorflowlibrary, care needs to be taken to also use the latestPythonVersion.

  Also, it's important to mention here - if I use the code shown below for thetensorflowlibrary configuration, the configuration gets thetensorflowThe library, on the other hand, isversion, rather than the one we just got above which is theversion, it was never possible to get the latest version of thetensorflowlibrary; and no matter how it is updated after thattensorflowlibraries, all of which report an error message.

conda install tensorflow

  For example, on my computer, if I run the above code, the result is shown below.

  I don't know exactly where the problem is, but you can see from the picture above that this method gets thetensorflowThe library is alwaysversion (e.g. shown above)tensorflowlibrary1.2.1(the version). So, if people need to compare newer versions oftensorflowlibrary, it is still recommended to use the previously mentionedpip install --upgrade tensorflowThis code does it.

  Let's go back to the foregoingtensorflowThe library configuration is in the works; wait a moment and it's usually done!tensorflowlibrary configuration. It is important to note here that if at this point you get an error as shown below, thetensorflowThe library is still not configured successfully for now.

  This situation is due topipThis is caused by not having a high enough version, so we need to set thepipUpgrade.

python -m pip install --upgrade pip

  Enter the above code as shown below.

  After running this code, we re-run it oncepip install --upgrade tensorflowThis code is sufficient. However, in my case, after re-running this code, I got the problem again as shown below.

  By checking, it was found that there was a problem with the web proxy; after closing the proxy, the problem could be solved (but it was strange, I don't know why this error was not reported just now, and it appeared only after re-running this code). In the end, the resulting interface is shown below.

  Next, we can check this by entering the following codetensorflowWhether the library has been configured successfully.

python -c "import tensorflow as tf;print(tf.reduce_sum(([1000, 1000])))"

  As shown below, if you end up with aThe result will show that ourtensorflowThe library is finally configured.

  At this point, the big success is complete. Of course, getting here may not be a complete success - as you can see from the image above, the currenttensorflowThe library does not carryGPUCalculations. If everyone's computer does not haveGPUor do not need to useGPUAdd it to the calculation, then you don't have to worry about the problem, which is equivalent to having been fully successful, and follow up by starting directly with thetensorflowlibraries for all kinds of deep learning applications will suffice; but for computers withGPUand also wants to makeGPUFor those joining computing, we'll cover the specifics of how to configure it in the next blog.