天天看點

TensorFlow安裝部署

1.環境依賴

Centos7
元件 版本
Python 2.7.5
TensorFlow 0.14.0

pyhton依賴庫

Package              Version  
-------------------- ---------
absl-py              0.8.0    
astor                0.8.0    
backports.weakref    1.0.post1
enum34               1.1.6    
funcsigs             1.0.2    
futures              3.3.0    
gast                 0.2.2    
google-pasta         0.1.7    
grpcio               1.23.0   
h5py                 2.9.0    
Keras-Applications   1.0.8    
Keras-Preprocessing  1.1.0    
Markdown             3.1.1    
mock                 3.0.5    
numpy                1.16.5   
pip                  19.2.3   
protobuf             3.9.1    
setuptools           41.2.0   
six                  1.12.0   
tensorboard          1.14.0   
tensorflow           1.14.0   
tensorflow-estimator 1.14.0   
termcolor            1.1.0    
Werkzeug             0.15.5   
wheel                0.33.6   
wrapt                1.11.2              

2.資源準備

安裝包下載下傳

百度雲盤連結:

https://pan.baidu.com/s/1cm9mZpP1JRwyGpq945ffaQ

提取碼:8bxj

3.安裝

a).安裝python-devel

## 線上安裝
yum install python-devel

## 離線安裝
rpm -ivh python-devel-2.7.5-80.el7_6.x86_64.rpm           

b).安裝virtualenv

## 線上安裝
pip install virtualenv

## 離線安裝
           

c).安裝tensorflow

進入虛拟機,安裝tensorflow
## Step1: 建立虛拟機
virtualenv tensorflow

## Step2: 進入虛拟機
source ./tensorflow/bin/activate           
## 線上安裝
pip install tensorflow

## 離線安裝
pip install --no-index --find-links=/path/to/tensorflow_1.14.0_package -r tensorflow_requirement.txt           

4.測試

測試代碼

import tensorflow as tf
mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)           

執行測試

python test.py           

測試結果

TensorFlow安裝部署

5.環境依賴下載下傳

## python-devel
http://mirror.centos.org/centos/7/updates/x86_64/Packages/python-devel-2.7.5-80.el7_6.x86_64.rpm

## tensorflow-1.14.0
https://files.pythonhosted.org/packages/d3/59/d88fe8c58ffb66aca21d03c0e290cd68327cc133591130c674985e98a482/tensorflow-1.14.0-cp27-cp27mu-manylinux1_x86_64.whl

## pip-19.2.3
https://files.pythonhosted.org/packages/00/9e/4c83a0950d8bdec0b4ca72afd2f9cea92d08eb7c1a768363f2ea458d08b4/pip-19.2.3.tar.gz

## virtualenv
https://files.pythonhosted.org/packages/f7/69/1ad2d17560c4fc60170056dcd0a568b83f3453a2ac91155af746bcdb9a07/virtualenv-16.7.4-py2.py3-none-any.whl