TF研究ノート

1. HelloWorldの

TFのようtensorflowインポート
NPとして輸入numpyの
tensorflowインポートkerasから

モデル= tf.keras.Sequential([keras.layers.Dense(単位= 1、input_shape = [1])])
model.compile(オプティマイザ= 'SGD'、損失= 'mean_squared_error')

XS = np.array([ -1.0、0.0、1.0、2.0、3.0、4.0]、DTYPE =フロート)
YS = np.array([ - 3.0、-1.0、1.0、3.0、5.0、7.0]、DTYPE =フロート)

model.fit(XS、 YS、エポック= 500)
印刷(model.predict([10.0]))

 

2.コールバック

TFのようtensorflowインポート
プリント(TF .__ version__)

クラスmyCallback(tf.keras.callbacks.Callback):
  DEF on_epoch_end(自己、エポック、ログ= {}):
    IF(logs.get( '損失')<0.4):
      印刷( "\ nReached 60%の精度は非常にトレーニングをキャンセル!")
      self.model.stop_training = Trueの

コールバック= myCallback()
mnist = tf.keras.datasets.fashion_mnist
(training_images、training_labels)、(test_images、test_labelsを)= mnist.load_data( )
training_images = training_images / 255.0
test_images =のtest_images / 255.0
モデル= tf.keras.models.Sequential([
 
  tf.keras.layers.Dense(512、活性= tf.nn.relu)、
  tf.keras.layers.Dense(10 、活性化= tf.nn.softmax)
])
model.compile(オプティマイザ= 'アダム、損失= 'sparse_categorical_crossentropy')
model.fit(training_images、training_labels、エポック= 5、コールバック= [コールバック])

おすすめ

転載: www.cnblogs.com/adelaide/p/11229509.html