Tensorflow คือเฟรมเวิร์กแมชชีนเลิร์นนิงที่ให้บริการโดย Google เป็นเฟรมเวิร์กโอเพนซอร์สที่ใช้ร่วมกับ Python เพื่อใช้อัลกอริทึม แอปพลิเคชันการเรียนรู้เชิงลึก และอื่นๆ อีกมากมาย ใช้ในการวิจัยและเพื่อการผลิต มีเทคนิคการเพิ่มประสิทธิภาพที่ช่วยในการดำเนินการทางคณิตศาสตร์ที่ซับซ้อนได้อย่างรวดเร็ว เนื่องจากใช้ NumPy และอาร์เรย์หลายมิติ อาร์เรย์หลายมิติเหล่านี้เรียกอีกอย่างว่า "เทนเซอร์"
แพ็คเกจ 'tensorflow' สามารถติดตั้งบน Windows ได้โดยใช้โค้ดด้านล่าง -
pip install tensorflow
Tensor เป็นโครงสร้างข้อมูลที่ใช้ใน TensorFlow ช่วยเชื่อมต่อขอบในแผนภาพการไหล แผนภาพการไหลนี้เรียกว่า 'กราฟการไหลของข้อมูล' เทนเซอร์เป็นเพียงอาร์เรย์หลายมิติหรือรายการ
ชุดข้อมูล 'Fashion MNIST' มีรูปภาพของเสื้อผ้าประเภทต่างๆ มันมีภาพสีเทาของเสื้อผ้ามากกว่า 70,000 ที่อยู่ใน 10 หมวดหมู่ที่แตกต่างกัน รูปภาพเหล่านี้มีความละเอียดต่ำ (28 x 28 พิกเซล)
เรากำลังใช้ Google Colaboratory เพื่อเรียกใช้โค้ดด้านล่าง Google Colab หรือ Colaboratory ช่วยเรียกใช้โค้ด Python บนเบราว์เซอร์และไม่ต้องมีการกำหนดค่าใดๆ และเข้าถึง GPU ได้ฟรี (หน่วยประมวลผลกราฟิก) Colaboratory ถูกสร้างขึ้นบน Jupyter Notebook
ต่อไปนี้เป็นข้อมูลโค้ดสำหรับการทำนาย -
ตัวอย่าง
probability_model = tf.keras.Sequential([model,
tf.keras.layers.Softmax()])
predictions = probability_model.predict(test_images)
print("The predictions are being made ")
print(predictions[0])
np.argmax(predictions[0])
print("The test labels are")
print(test_labels[0])
def plot_image(i, predictions_array, true_label, img):
true_label, img = true_label[i], img[i]
plt.grid(False)
plt.xticks([])
plt.yticks([])
plt.imshow(img, cmap=plt.cm.binary)
predicted_label = np.argmax(predictions_array)
if predicted_label == true_label:
color = 'blue'
else:
color = 'red'
plt.xlabel("{} {:2.0f}% ({})".format(class_names[predicted_label],
100*np.max(predictions_array),
class_names[true_label]), color=color)
def plot_value_array(i, predictions_array, true_label):
true_label = true_label[i]
plt.grid(False)
plt.xticks(range(10))
plt.yticks([])
thisplot = plt.bar(range(10), predictions_array, color="#777777")
plt.ylim([0, 1])
predicted_label = np.argmax(predictions_array)
thisplot[predicted_label].set_color('red')
thisplot[true_label].set_color(‘green’) เครดิตโค้ด − https://www.tensorflow.org/tutorials/keras/classification
ผลลัพธ์
The predictions are being made [1.3008227e−07 9.4930819e−10 2.0181861e−09 5.4944155e−10 3.8257373e−11 1.3896286e−04 1.4776078e−08 3.1724274e−03 9.4210514e−11 9.9668854e−01] The test labels are 9
คำอธิบาย
-
เมื่อโมเดลได้รับการฝึกอบรมแล้ว จะต้องมีการทดสอบ
-
ซึ่งสามารถทำได้โดยใช้แบบจำลองที่สร้างขึ้นเพื่อคาดการณ์เกี่ยวกับภาพ
-
มีการแนบเอาต์พุตเชิงเส้น บันทึก และเลเยอร์ softmax ไว้ด้วย
-
เลเยอร์ softmax ช่วยในการแปลงบันทึกเป็นความน่าจะเป็น
-
สิ่งนี้ทำเพื่อให้ง่ายต่อการตีความคำทำนายที่ทำขึ้น
-
มีการกำหนดวิธี "plot_value_array" ซึ่งแสดงค่าจริงและค่าที่คาดการณ์ไว้