tensorflow如何使用 訓練模型

2022-04-28 09:25:48 字數 454 閱讀 9013

首先檢測tpu存在:

tpu = tf.distribute.cluster_resolver.tpuclusterresolver()   #如果先前設定好了tpu_name環境變數,不需要再給引數.

tpu的返回值為1 or 0 ,1則檢測到了tpu.

tf.config.experimental_connect_to_cluster(tpu)

tf.tpu.experimental.initialize_tpu_system(tpu)

strategy = tf.distribute.experimental.tpustrategy(tpu)

with strategy.scope():

#define a model

#compile it

#train it

因為這目前還是乙個實驗功能,**實現可能過一段時間就變了,看官方給的通知吧.

tensorflow 如何使用矩陣

refence tensorflow machine learning cookbook working with matrices packt.tensorflow.machine.learning.cookbook.2017 筆記 coding utf 8 import tensorflow a...

tensorflow 如何控制使用cpu數量

tensorflow讀取資料有時候非常占用資源,針對這一情況,我們可以通過控制程式使用cpu的數量來限制 步驟如下 1 bashrc 中修改指定個數 export cpu num 22 python 中在需要執行的程式前加入如下配置 cpu num int os.environ.get cpu nu...

tensorflow 如何使用佔位符與變數

refence tensorflow machine learning cookbook using placeholders and variables packt.tensorflow.machine.learning.cookbook.2017 筆記 如何使用佔位符與變數 申明變數 tf.va...