ในขณะที่ฉันกำลังทดลองกับ tf.estimator API ฉันต้องการเพิ่มการค้นพบที่น่าสนใจของฉันที่นี่ด้วย ฉันยังไม่รู้ว่าการใช้ขั้นตอนและพารามิเตอร์ยุคนั้นสอดคล้องกันตลอด TensorFlow หรือไม่ดังนั้นฉันจึงเกี่ยวข้องกับ tf.estimator (โดยเฉพาะ tf.estimator.LinearRegressor) ในตอนนี้
ขั้นตอนการฝึกที่กำหนดโดยnum_epochs: stepsไม่ได้กำหนดไว้อย่างชัดเจน
estimator = tf.estimator.LinearRegressor(feature_columns=ft_cols)
train_input = tf.estimator.inputs.numpy_input_fn({'x':x_train},y_train,batch_size=4,num_epochs=1,shuffle=True)
estimator.train(input_fn=train_input)
ความคิดเห็น: ฉันได้ตั้งค่าnum_epochs=1สำหรับอินพุตการฝึกอบรมและรายการเอกสารสำหรับnumpy_input_fnบอกฉันว่า"num_epochs: จำนวนเต็มจำนวนยุคที่จะวนซ้ำข้อมูลถ้าNoneจะทำงานตลอดไป" . ด้วยnum_epochs=1ในตัวอย่างข้างต้นการฝึกอบรมวิ่งตรงx_train.size / batch_sizeครั้ง / ขั้นตอน (ในกรณีของฉันนี้คือ 175000 ขั้นตอนx_trainมีขนาดของ 700000 และbatch_size4)
ขั้นตอนการฝึกที่กำหนดโดยnum_epochs: stepsกำหนดไว้อย่างชัดเจนสูงกว่าจำนวนขั้นตอนที่กำหนดโดยนัยnum_epochs=1
estimator = tf.estimator.LinearRegressor(feature_columns=ft_cols)
train_input = tf.estimator.inputs.numpy_input_fn({'x':x_train},y_train,batch_size=4,num_epochs=1,shuffle=True)
estimator.train(input_fn=train_input, steps=200000)
หมายเหตุ: num_epochs=1ในกรณีของฉันจะหมายถึงขั้นตอน 175000 ( x_train.size / batch_sizeกับx_train.size = 700,000และbatch_size = 4 ) และตรงนี้เป็นจำนวนขั้นตอนestimator.trainแม้ว่าขั้นตอนพารามิเตอร์ถูกกำหนดให้ estimator.train(input_fn=train_input, steps=200000)200,000
ขั้นตอนการฝึกอบรมที่กำหนดโดย steps
estimator = tf.estimator.LinearRegressor(feature_columns=ft_cols)
train_input = tf.estimator.inputs.numpy_input_fn({'x':x_train},y_train,batch_size=4,num_epochs=1,shuffle=True)
estimator.train(input_fn=train_input, steps=1000)
ความคิดเห็น: แม้ว่าฉันจะตั้งค่าnum_epochs=1เมื่อเรียกnumpy_input_fnการฝึกหยุดหลังจาก 1,000 ก้าว เนื่องจากsteps=1000ในการestimator.train(input_fn=train_input, steps=1000)เขียนทับnum_epochs=1ในtf.estimator.inputs.numpy_input_fn({'x':x_train},y_train,batch_size=4,num_epochs=1,shuffle=True).
สรุป : สิ่งที่พารามิเตอร์num_epochsสำหรับtf.estimator.inputs.numpy_input_fnและstepsสำหรับการestimator.trainกำหนดขอบเขตที่ต่ำกำหนดจำนวนขั้นตอนซึ่งจะวิ่งผ่าน