開始使用免費開始

處理影像資料

你拿到了一張以黑白表示的英文字母影像,並已被編碼為張量 letter。你想判斷這個字母是 X 還是 K。你沒有訓練好的神經網路,但手邊有一個簡單模型 model,可以用來分類 letter

Python 互動環境中已提供 3x3 張量 letter 與 1x3 張量 model。你可以先將 lettermodel 相乘,對結果做加總,然後檢查是否等於 1,以此判斷 letter 是否為 K。就像更複雜的模型(例如神經網路)一樣,model 是一組權重,排列成一個張量。

注意:tensorflow 中的 reshape()matmul()reduce_sum() 已匯入並可直接使用。

本練習屬於課程

Python 的 TensorFlow 入門

檢視課程

練習說明

  • 模型 model 目前是 1x3 張量,但應該是 3x1。請重新調整 model 的形狀。
  • 將 3x3 張量 letter 與 3x1 張量 model 做矩陣相乘。
  • 對相乘後得到的張量 output 做加總,並將結果指定給 prediction
  • 使用 .numpy() 方法列印 prediction,以判斷 letter 是否為 K。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Reshape model from a 1x3 to a 3x1 tensor
model = ____(model, (____, ____))

# Multiply letter by model
output = ____(letter, model)

# Sum over output and print prediction using the numpy method
prediction = ____
print(prediction.____)
編輯並執行程式碼