【发布时间】:2020-12-10 19:02:45
【问题描述】:
我正在使用以下代码从图像中提取特征。
def ext():
imgPathList = glob.glob("images/"+"*.JPG")
features = []
for i, path in enumerate(tqdm(imgPathList)):
feature = get_vector(path)
feature = feature[0] / np.linalg.norm(feature[0])
features.append(feature)
paths.append(path)
features = np.array(features, dtype=np.float32)
return features, paths
但是,上面的代码抛出了以下错误,
features = np.array(features, dtype=np.float32)
ValueError: only one element tensors can be converted to Python scalars
我怎样才能解决它?
【问题讨论】:
-
这对于应该是标量的东西非常可疑:
feature[0] / np.linalg.norm(feature[0])
标签: python numpy pytorch torch resnet