Tensorflow.Estimators筆記 - 介紹

      網(wǎng)友投稿 911 2022-05-30

      一、簡介

      estimators是tensorFlow的機器學(xué)習(xí)高階API:

      包括四個部分:

      1.1、訓(xùn)練

      1.2、評估

      1.3、預(yù)測

      1.4、服務(wù)導(dǎo)出

      該api基于類:tf.estimator.Estimator.

      二、優(yōu)勢

      estimator有以下優(yōu)勢:

      2.1、基于estimator的模型既可以在本地運行,也可以在分布式環(huán)境中運行,可以不修改代碼同時在CPU、TPU、GPU服務(wù)器上運行

      2.2、輕便的實現(xiàn)模型開發(fā)者之間的共享

      2.3、更簡單的時間模型

      2.4、estimator是簡化訂制在tf.layers

      2.5、自動圖像化

      2.6、提供安全的訓(xùn)練循環(huán):·圖像化、·內(nèi)置變量、·啟動隊列、·異常管理、·從錯誤中創(chuàng)建和刪除測點文件

      三、pre-made(預(yù)制)

      預(yù)制能夠讓開發(fā)者從更高層面工作。預(yù)制estimator為開發(fā)者創(chuàng)造和管理圖和會話對象。

      3.1、預(yù)制estimators程序結(jié)構(gòu)

      3.1.1 寫一個或多個數(shù)據(jù)集導(dǎo)入函數(shù)(返回一個特征數(shù)據(jù)字典、一個包含標(biāo)簽的tensor)

      def input_fn(dataset):

      Tensorflow.Estimators筆記 - 介紹

      ...? # manipulate dataset, extracting the feature dict and the label

      return feature_dict, label

      3.1.2 定義特征列

      每一個tf.feature_column定義特征名、類型和任何輸入預(yù)處理,舉三個例子:

      # Define three numeric feature columns.

      population = tf.feature_column.numeric_column('population')

      crime_rate = tf.feature_column.numeric_column('crime_rate')

      median_education = tf.feature_column.numeric_column('median_education',

      normalizer_fn=lambda x: x - global_education_mean)

      3.1.3 實例化預(yù)制estimator

      舉 LinearClassifier的例子:

      # Instantiate an estimator, passing the feature columns.

      estimator = tf.estimator.LinearClassifier(

      feature_columns=[population, crime_rate, median_education],

      )

      3.1.4調(diào)用訓(xùn)練、評價、生成方法:

      舉train方法:

      # my_training_set is the function created in Step 1

      estimator.train(input_fn=my_training_set, steps=2000)

      3.2、預(yù)制評估器的優(yōu)勢

      指明計算圖在計算機和計算集群中何處運行的最佳實踐

      普遍有用的事件總結(jié)最佳實踐

      四、訂制評估器

      訂制評估器和預(yù)制評估器的核心,都是模型函數(shù)。

      五、工作流推薦

      5.1 假設(shè)合適的預(yù)制評估器存在,用它來構(gòu)造第一個模型并建立基準(zhǔn)線

      5.2 構(gòu)造和測試全局管道,包括對這個預(yù)制評估器的數(shù)據(jù)完整性和可靠性

      5.3 對預(yù)制評估器做適當(dāng)?shù)男薷?,使他能夠產(chǎn)生最佳結(jié)果

      5.4 如果可以的話,建立自己的模型

      六、從Keras models建立評估器

      舉例調(diào)用tf.keras.estimator.model_to_estimator

      # Instantiate a Keras inception v3 model.

      keras_inception_v3 = tf.keras.applications.inception_v3.InceptionV3(weights=None)

      # Compile model with the optimizer, loss, and metrics you'd like to train with.

      keras_inception_v3.compile(optimizer=tf.keras.optimizers.SGD(lr=0.0001, momentum=0.9),

      loss='categorical_crossentropy',

      metric='accuracy')

      # Create an Estimator from the compiled Keras model. Note the initial model

      # state of the keras model is preserved in the created Estimator.

      est_inception_v3 = tf.keras.estimator.model_to_estimator(keras_model=keras_inception_v3)

      # Treat the derived Estimator as you would with any other Estimator.

      # First, recover the input name(s) of Keras model, so we can use them as the

      # feature column name(s) of the Estimator input function:

      keras_inception_v3.input_names? # print out: ['input_1']

      # Once we have the input name(s), we can create the input function, for example,

      # for input(s) in the format of numpy ndarray:

      train_input_fn = tf.estimator.inputs.numpy_input_fn(

      x={"input_1": train_data},

      y=train_labels,

      num_epochs=1,

      shuffle=False)

      # To train, we call Estimator's train function:

      est_inception_v3.train(input_fn=train_input_fn, steps=2000)

      TensorFlow

      版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。

      上一篇:【產(chǎn)品技術(shù)】密鑰小課堂:打造自己的數(shù)字簽名
      下一篇:云翌通助力超前通信,提升專業(yè)凝聚價值
      相關(guān)文章
      亚洲精品国产字幕久久不卡 | 亚洲色成人网站WWW永久| 亚洲日本在线电影| 亚洲最大的黄色网| 亚洲欧洲另类春色校园小说| 亚洲欧洲校园自拍都市| 99久久亚洲综合精品成人网| 在线电影你懂的亚洲| 亚洲精品线在线观看| 日本久久久久亚洲中字幕| 少妇中文字幕乱码亚洲影视| 亚洲精品综合一二三区在线 | 亚洲av午夜成人片精品网站| 亚洲国产成人一区二区三区| 亚洲国产精品一区二区久久hs| 亚洲国产成人一区二区三区| 亚洲国产第一页www| 亚洲视频网站在线观看| 亚洲春色在线观看| 亚洲天堂2016| 亚洲丶国产丶欧美一区二区三区| 亚洲精品宾馆在线精品酒店| 日本亚洲成高清一区二区三区 | 亚洲AV无码国产精品色午友在线| 亚洲色婷婷综合久久| 永久亚洲成a人片777777| 亚洲国产成人片在线观看 | 亚洲av日韩综合一区二区三区| 亚洲成在人线在线播放无码| 久久精品国产亚洲AV未满十八| 一本久到久久亚洲综合| 久久精品国产亚洲Aⅴ香蕉| 亚洲精品狼友在线播放| 亚洲国产一区在线| 亚洲国产精品白丝在线观看| 亚洲人成色777777精品| 亚洲第一se情网站| 在线观看亚洲精品福利片| 国产V亚洲V天堂A无码| 1区1区3区4区产品亚洲| 亚洲人成图片网站|