ดูเอกสารอย่างเป็นทางการ: คุณเห็นอะไร? ค่าโดยสารปกติ? ตอนนี้เดาว่าอะไร: นี่คือโซนที่ปลอดจากบาเซล เราใช้ cmake ที่นี่!
คอลเลกชันนี้มีตัวอย่าง ที่เชื่อถือได้ และ ตายได้ เพื่อใช้ tensorflow ใน C, C ++, GO และ Python: โหลดโมเดลที่ผ่านการฝึกอบรมมาก่อนหรือรวบรวมการทำงานที่กำหนดเองโดยมีหรือไม่มี cuda การสร้างทั้งหมดได้รับการทดสอบกับรุ่น Tensorflow ที่มีเสถียรภาพล่าสุดและพึ่งพา CMake ด้วย findtensorflow.cmake ที่กำหนดเอง ไฟล์ CMAKE นี้รวมถึงงานทั่วไปสำหรับข้อบกพร่องในรุ่น TF เฉพาะ
| เทนเซอร์โฟลว์ | สถานะ |
|---|---|
| 1.14.0 | |
| 1.13.1 | |
| 1.12.0 | |
| 1.11.0 | |
| 1.10.0 | |
| 1.9.0 |
ที่เก็บมีตัวอย่างต่อไปนี้
| ตัวอย่าง | คำอธิบาย |
|---|---|
| การดำเนินงานที่กำหนดเอง | สร้างการดำเนินการที่กำหนดเองสำหรับ tensorflow ใน C ++/CUDA (ต้องการเฉพาะ PIP) |
| การอนุมาน (C ++) | รันอนุมานใน C ++ |
| การอนุมาน (c) | รันอนุมานใน C |
| การอนุมาน (ไป) | รันอนุมานใน GO |
| นักเขียนเหตุการณ์ | เขียนไฟล์เหตุการณ์สำหรับ tensorboard ใน C ++ |
| ตัวอย่าง Keras CPP | เรียกใช้ keras-model ใน C ++ |
| ตัวอย่างง่ายๆ | สร้างและเรียกใช้กราฟ tensorflow ใน C ++ |
| ปรับขนาดตัวอย่างภาพ | ปรับขนาดภาพใน tensorflow โดยมี/ไม่มี opencv |
ตัวอย่างนี้แสดงกระบวนการสร้างการดำเนินการที่กำหนดเองโดยใช้ C ++/CUDA และ CMAKE มัน ไม่ได้ มีวัตถุประสงค์เพื่อแสดงการใช้งานที่ได้รับประสิทธิภาพสูงสุด แต่มันเป็นเพียงแผ่นหม้อไอน้ำ
user@host $ pip install tensorflow-gpu --user # solely the pip package is needed
user@host $ cd custom_op/user_ops
user@host $ cmake .
user@host $ make
user@host $ python test_matrix_add.py
user@host $ cd ..
user@host $ python example.py ตัวอย่างนี้แสดงกระบวนการโหลดภาพ (โดยใช้ openCV หรือ tensorflow) ปรับขนาดภาพบันทึกภาพเป็น JPG หรือ PNG (ใช้ OpenCV หรือ TensorFlow)
user@host $ cd examples/resize
user@host $ export TENSORFLOW_BUILD_DIR=...
user@host $ export TENSORFLOW_SOURCE_DIR=...
user@host $ cmake .
user@host $ make มีสองตัวอย่างที่แสดงให้เห็นถึงการจัดการของการให้บริการ tensorflow: การใช้อินพุตเวกเตอร์และใช้อินพุตภาพที่เข้ารหัส
server@host $ CHOOSE=basic # or image
server@host $ cd serving/ ${CHOOSE} /training
server@host $ python create.py # create some model
server@host $ cd serving/server/
server@host $ ./run.sh # start server
# some some queries
client@host $ cd client/bash
client@host $ ./client.sh
client@host $ cd client/python
# for the basic-example
client@host $ python client_rest.py
client@host $ python client_grpc.py
# for the image-example
client@host $ python client_rest.py /path/to/img.[png,jpg]
client@host $ python client_grpc.py /path/to/img.[png,jpg] สร้างโมเดลใน Python บันทึกกราฟลงในดิสก์และโหลดใน C/C+/GO/Python เพื่อทำการอนุมาน เนื่องจากตัวอย่างเหล่านี้ขึ้นอยู่กับ Tensorflow C-API พวกเขาต้องการไลบรารี libtensorflow_cc.so ซึ่ง ไม่ได้ จัดส่งในแพ็คเกจ (Tensorfow-GPU) ดังนั้นคุณจะต้องสร้าง tensorflow จากแหล่งที่มาก่อนเช่น
user@host $ ls ${TENSORFLOW_SOURCE_DIR}
ACKNOWLEDGMENTS bazel-genfiles configure pip
ADOPTERS.md bazel-out configure.py py.pynano
ANDROID_NDK_HOME bazel-tensorflow configure.py.bkp README.md
...
user@host $ cd ${TENSORFLOW_SOURCE_DIR}
user@host $ ./configure
user@host $ # ... or whatever options you used here
user@host $ bazel build -c opt --copt=-mfpmath=both --copt=-msse4.2 --config=cuda //tensorflow:libtensorflow.so
user@host $ bazel build -c opt --copt=-mfpmath=both --copt=-msse4.2 --config=cuda //tensorflow:libtensorflow_cc.so
user@host $ export TENSORFLOW_BUILD_DIR=/tensorflow_dist
user@host $ mkdir ${TENSORFLOW_BUILD_DIR}
user@host $ cp ${TENSORFLOW_SOURCE_DIR} /bazel-bin/tensorflow/ * .so ${TENSORFLOW_BUILD_DIR} /
user@host $ cp ${TENSORFLOW_SOURCE_DIR} /bazel-genfiles/tensorflow/cc/ops/ * .h ${TENSORFLOW_BUILD_DIR} /includes/tensorflow/cc/ops/เราเพิ่งเรียกใช้โมเดลพื้นฐานมาก
x = tf . placeholder ( tf . float32 , shape = [ 1 , 2 ], name = 'input' )
output = tf . identity ( tf . layers . dense ( x , 1 ), name = 'output' ) ดังนั้นบันทึกโมเดลอย่างที่คุณทำเป็นประจำ สิ่งนี้ทำใน example.py นอกเหนือจากเอาต์พุตบางอย่าง
user@host $ python example.py
[<tf.Variable 'dense/kernel:0' shape=(2, 1) dtype=float32_ref>, <tf.Variable 'dense/bias:0' shape=(1,) dtype=float32_ref>]
input [[1. 1.]]
output [[2.1909506]]
dense/kernel:0 [[0.9070684]
[1.2838823]]
dense/bias:0 [0.] user@host $ python python/inference.py
[<tf.Variable 'dense/kernel:0' shape=(2, 1) dtype=float32_ref>, <tf.Variable 'dense/bias:0' shape=(1,) dtype=float32_ref>]
input [[1. 1.]]
output [[2.1909506]]
dense/kernel:0 [[0.9070684]
[1.2838823]]
dense/bias:0 [0.] user@host $ cd cc
user@host $ cmake .
user@host $ make
user@host $ cd ..
user@host $ ./cc/inference_cc
input Tensor<type: float shape: [1,2] values: [1 1]>
output Tensor<type: float shape: [1,1] values: [2.19095063]>
dense/kernel:0 Tensor<type: float shape: [2,1] values: [0.907068372][1.28388226]>
dense/bias:0 Tensor<type: float shape: [1] values: 0> user@host $ cd c
user@host $ cmake .
user@host $ make
user@host $ cd ..
user@host $ ./c/inference_c
2.190951
user@host $ go get github.com/tensorflow/tensorflow/tensorflow/go
user@host $ cd go
user@host $ ./build.sh
user@host $ cd ../
user@host $ ./inference_go
input [[1 1]]
output [[2.1909506]]
dense/kernel:0 [[0.9070684] [1.2838823]]
dense/bias:0 [0]