我正在嘗試使用 cv2、tensorflow 在 google colab 中構建姿勢檢測,但遇到以下錯誤。
代碼:
import tensorflow as tf
import tensorflow_hub as hub
import cv2
from matplotlib import pyplot as plt
import numpy as np
from google.colab.patches import cv2_imshow
model = hub.load('https://tfhub.dev/google/movenet/multipose/lightning/1')
movenet = model.signatures['serving_default']
img_original = cv2.imread('/content/brandon-atchison-eexdeq3NleQ-unsplash.jpeg',1)
img_copy = img_original.copy()
input_img = tf.cast(img_original,dtype=tf.int32)
img_copy.shape
tensor = tf.convert_to_tensor(img_original,dtype=tf.int32)
tensor
results = movenet(tensor)
我已經創建了變數img_copy
因為我需要對影像執行一些操作并希望原始影像保持原樣。不確定我在嘗試從movenet
模型中獲取結果時面臨的錯誤是什么。
編輯:
uj5u.com熱心網友回復:
嘗試:
results = movenet(tensor[None, ...])
因為您缺少將資料提供給模型所需的批次維度。你也可以使用tf.expand_dims
:
tensor = tf.expand_dims(tensor, axis=0)
# resize
tensor = tf.image.resize(tensor, [32 * 186, 32 * 125])
這是一個作業示例:
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/movenet/multipose/lightning/1')
movenet = model.signatures['serving_default']
tensor = tf.random.uniform((1, 160, 256, 3), minval=0, maxval=255, dtype=tf.int32)
movenet(tensor)
檢查模型描述并確保您具有正確的形狀:
一幀視頻或影像,表示為int32動態形狀的張量:1xHxWx3,其中H和W需要為32的倍數,較大的維度建議為256。要準備輸入影像張量,需要調整大小(并在需要時填充)影像以保持上述條件。請參閱使用部分以獲得更詳細的說明。請注意,輸入影像的大小控制著速度與準確性之間的權衡,因此請選擇最適合您的應用程式的值。通道順序是 RGB,值在 [0, 255] 中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/506591.html