- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能是一个愚蠢的问题,但我是机器学习和 Tensorflow 的新手。我正在尝试使用 Tensorflow Lite 在 Raspberry Pi 上运行对象检测 API。我正在尝试借助此示例修改我的代码
https://github.com/freedomtan/tensorflow/blob/deeplab_tflite_python/tensorflow/contrib/lite/examples/python/object_detection.py
这段代码将从图像中检测对象。但是我想通过 Pi 相机实时检测物体而不是图像。我试图修改此代码以从相机而不是图像读取输入。这是我的一段代码-
import numpy as np
from tensorflow.contrib.lite.python import interpreter as interpreter_wrapper
import cv2
cap = cv2.VideoCapture(0)
ret, image_np = cap.read()
PATH_TO_MODEL = "ssd_mobilenet_v1_coco.tflite"
interpreter = tf.contrib.lite.Interpreter(model_path=PATH_TO_MODEL)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
while True:
# NxHxWxC, H:1, W:2
height = input_details[0]['shape'][1]
width = input_details[0]['shape'][2]
ret, image_np = cap.read()
image_np_expanded = np.expand_dims(image_np, axis=0)
#if floating_model:
image_np_expanded = (np.float32(image_np_expanded) - input_mean) / input_std
#HERE I AM GETTING ERROR
interpreter.set_tensor(input_details[0]['index'], image_np_expanded)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
但是我收到了这个错误-
Traceback (most recent call last):
File "New_object_detection.py", line 257, in <module>
interpreter.set_tensor(input_details[0]['index'], image_np_expanded)
File "/home/saurabh/.local/lib/python3.6/site-packages/tensorflow/contrib/lite/python/interpreter.py", line 151, in set_tensor
self._interpreter.SetTensor(tensor_index, value)
File "/home/saurabh/.local/lib/python3.6/site-packages/tensorflow/contrib/lite/python/interpreter_wrapper/tensorflow_wrap_interpreter_wrapper.py", line 133, in SetTensor
return _tensorflow_wrap_interpreter_wrapper.InterpreterWrapper_SetTensor(self, i, value)
ValueError: Cannot set tensor: Dimension mismatch
谁能告诉我如何解决这个错误或建议一个教程吗?
最佳答案
许多基于图像的机器学习模型都使用固定大小的输入进行训练。原始图像可能具有不同的尺寸,但会调整为固定尺寸(例如 224x224x3)。
因此,您需要在将输入提供给模型之前调整图像的大小。它可能工作得很好,因为训练数据也根据不同的大小进行了调整。
正如上面的评论所指出的,cv.resize
可以解决问题。
关于python - Tensorflow Lite - ValueError : Cannot set tensor: Dimension mismatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52012010/
因为谷歌发布了几篇关于移动设备联邦学习的论文,比如Gboard,但是我在TFLite网站上找不到关于训练的文档,TFLite现在支持设备训练吗? 最佳答案 我们不支持在 TensorFlow Lite
我正在尝试创建一个饼图,其中弧按大小(顺时针)排序,但不知道如何排序。 看来“theta”中的“sort”参数指向“color”的默认顺序,例如: { "$schema": "https://ve
就像这个: https://www.r-graph-gallery.com/265-grouped-boxplot-with-ggplot2/ 我尝试了刻面、颜色 channel 和构图, 但结果并不
我试图在折线图中显示一些数据。但是,我的“Harvest_Year”数据(以年为单位的日期,如 2017 年或 2018 年)显示为我认为是一个字符串 我从 .csv 文件导入数据,以下是我将字符串更
VegaLite 自动分配颜色。金价是蓝色,银价是橙色,感觉不对。 如何指定显式颜色 - #F1C40F黄金和 #95A5A6为了银? 我也想保留data.values如下面的示例代码 - 作为一组单
我正在 Vega-Lite(使用 Altair 生成)中绘制条形图。使用 Vega-View API,我编写了一些代码,用户可以在其中选择条形,这会更改这些条形的颜色(以及在应用程序的其他地方做一些其
我想注册一个自定义 Multi-Hue Sequential Color Scheme在织女星精简版。 我对文档的阅读是我只能创建 config.range对象来设置自定义色阶,但无法公开插值函数,从
最近几天我一直在尝试重命名我的 vega-lite 图表上的图例标签。 通常,这些标签与其各自的数据字段名称匹配。我有一个案例,我想给它们一个更具描述性的名称,但不重命名原始数据名称。 一个简化的例子
如何在 VegaLite 中使用数组数据? 我想将数据用作数组 dates = [1, 2, 3] prices1 = [1, 2, 1] prices2 = [1.5, 1, 2] 代替 Veg
我有一个非常简单的情况,我相信我的解决方案太复杂了,很有可能我遗漏了一些东西。说我有 time 的措施,位置(x,y,z),角度(滚动,俯仰,偏航)和速度。我想要一个简单的可视化,就像我目前拥有的那样
我似乎无法通过阅读文档来弄清楚这一点。 有没有办法实现 onClick我的任何标记的事件处理程序? 最佳答案 由于 Vega-Lite 尚不支持信号,您可以修补生成的 Vega。您可以向已编译的 Ve
我正在尝试制作一个简单的堆积条形图,仅在 X 轴上。我让它工作,有两个值 50 和 250。所以 X 轴的最大值显示为 300。 如何将其强制为另一个值,例如 500?那么从最后一个值到轴的末端是否存
我可以设置字体吗?在 vega-lite's config object , 用于所有标签和标题? 我目前为 x&y 轴和颜色图例设置了 labelFont 和 titleFont,但它在任何地方都是
在 Vega Lite 中,我试图将我的图例与这张图表的中间对齐。我需要图例的 anchor 参数,但我只能找到 titleAnchor。 Chart with Legend "legend": {
我可以设置字体吗?在 vega-lite's config object , 用于所有标签和标题? 我目前为 x&y 轴和颜色图例设置了 labelFont 和 titleFont,但它在任何地方都是
在 Vega Lite 中,我试图将我的图例与这张图表的中间对齐。我需要图例的 anchor 参数,但我只能找到 titleAnchor。 Chart with Legend "legend": {
我直接从 getmdl.io(组件页面)和所有设备(多台 PC、浏览器、手机等)复制代码,汉堡菜单不在标题中居中。我似乎无法隔离 css 中的菜单图标来重新对齐它。 getmdl.io 上的所有组件代
我正在使用 vega-lite 将一些数据渲染到 map 上。目前,我有这个架构,它呈现附加的图像: { "title": "What's the nearest city to you?",
我正在使用 Angular 4 构建一个 Web 应用程序。对于设计,我使用的是 Material Design lite。但是,我想使用 MDL 实现一个交互式轮播,它给我流畅的外观和感觉,并且与我
它看起来像 Polymer Starter Kit包含比 Material Design Lite 更多的组件,并且现在可用。由于两者都是符合 Material Design 理念的 Google 项
我是一名优秀的程序员,十分优秀!