numpy.core._exceptions._UFuncNoLoopError: ufunc ‘multiply‘ did not contain a loop with signature m

numpy.core._exceptions._UFuncNoLoopError: ufunc ‘multiply’ did not contain a loop with signature matching types (dtype(‘<U1’), dtype(‘float64’)) -> None

报错背景

在使用gradio的时候, 有一个接口有三个输入参数, 一个是图像, 另外两个是数字, 在我指定interface中的input=[‘image’,‘text’, gr.Slider(0.1,10)]之后就一直报这个错

image-20230321040951299

问题分析

一开始我以为是图像没有转化为浮点数, 所以一直在做img = img.astypr(float32)img = img.astypr(float64)甚至转化为了int32等将数据类型转化为浮点型/整型的操作.

image-20230321040935693

解决方法

但是后来我发现gradio中输入数据的input格式还有number, 我才恍然大悟, 怪不得一直报错说矩阵相乘的时候有字符串, 所以计算出错, 因为指定的输入格式写成了text, 所以在gradio读取input格式text类型的数据的时候就转化为了字符串

image-20230321040914249

所以在传入参数为数字时, input格式一定要是number, 不然计算会出问题

猜你喜欢

转载自blog.csdn.net/ahahayaa/article/details/129680138