繁体   English   中英

TypeError:没有找到与指定签名匹配的循环,并且为 ufunc greater 找到了转换

[英]TypeError: No loop matching the specified signature and casting was found for ufunc greater

我是 python 和机器学习的初学者。 当我运行一个基于 yolov5 的项目的 train.py 时(该项目的链接是https://github.com/DocF/multispectral-object-detection ),我得到以下错误:

回溯(最近调用最后):文件“E:\0_Final_Project\GithubProject\multispectral-object-detection-main\train.py”,第 1010 行,在 train_rgb_ir(hyp, opt, device, tb_writer) 文件“E:\0_Final_Project \GithubProject\multispectral-object-detection-main\train.py",第 647 行,在 train_rgb_ir tb_writer.add_histogram('classes', c, 0) File "C:\Users\hzji1127.conda\envs\multispectral-object- detection\lib\site-packages\torch\utils\tensorboard\writer.py", line 485, in add_histogram histogram(tag, values, bins, max_bins=max_bins), global_step, walltime File "C:\Users\hzji1127.conda \envs\multispectral-object-detection\lib\site-packages\torch\utils\tensorboard\summary.py”,第 358 行,直方图 hist = make_histogram(values.astype(float), bins, max_bins) File “C: \Users\hzji1127.conda\envs\multispectral-object-detection\lib\site-packages\torch\utils\tensorboard\summary.py", 第 386 行,make_histogram cum_counts = np.cumsum(np.greater(counts, 0 , dtype=np.int32)) TypeError: 没有循环匹配 ng 为 ufunc 找到了指定的签名和转换 greater

相关代码:

def make_histogram(values, bins, max_bins=None):
    """Convert values into a histogram proto using logic from histogram.cc."""
    if values.size == 0:
        raise ValueError("The input has no element.")
    values = values.reshape(-1)
    counts, limits = np.histogram(values, bins=bins)
    num_bins = len(counts)
    if max_bins is not None and num_bins > max_bins:
        subsampling = num_bins // max_bins
        subsampling_remainder = num_bins % subsampling
        if subsampling_remainder != 0:
            counts = np.pad(
                counts,
                pad_width=[[0, subsampling - subsampling_remainder]],
                mode="constant",
                constant_values=0,
            )
        counts = counts.reshape(-1, subsampling).sum(axis=-1)
        new_limits = np.empty((counts.size + 1,), limits.dtype)
        new_limits[:-1] = limits[:-1:subsampling]
        new_limits[-1] = limits[-1]
        limits = new_limits

    # Find the first and the last bin defining the support of the histogram:
    cum_counts = np.cumsum(np.greater(counts, 0, dtype=np.int32))
    start, end = np.searchsorted(cum_counts, [0, cum_counts[-1] - 1], side="right")
    start = int(start)
    end = int(end) + 1
    del cum_counts

    # TensorBoard only includes the right bin limits. To still have the leftmost limit
    # included, we include an empty bin left.
    # If start == 0, we need to add an empty one left, otherwise we can just include the bin left to the
    # first nonzero-count bin:
    counts = (
        counts[start - 1 : end] if start > 0 else np.concatenate([[0], counts[:end]])
    )
    limits = limits[start : end + 1]

    if counts.size == 0 or limits.size == 0:
        raise ValueError("The histogram is empty, please file a bug report.")

    sum_sq = values.dot(values)
    return HistogramProto(
        min=values.min(),
        max=values.max(),
        num=len(values),
        sum=values.sum(),
        sum_squares=sum_sq,
        bucket_limit=limits.tolist(),
        bucket=counts.tolist(),
    )

我已经查看了 stackoverflow 和谷歌,但我找不到任何有助于解决这个问题的东西。 请帮忙! 谢谢

尝试:

cum_counts = np.cumsum(np.greater(counts, 0))

TypeError: ufunc 'add' 不包含签名匹配类型 dtype(' <u1') dtype('<u1') dtype('<u1')< div><div id="text_translate"><p> 我是 Python 用户的初学者。 当我尝试在下面编写代码时发生错误</p><pre>import numpy as np np.array(['a', 'b', 'c']) + np.array(['d','e', 'f'])</pre><pre> TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('&lt;U1') dtype('&lt;U1') dtype('&lt;U1')</pre><p> 所以我尝试设置dtype = '&lt;U1' ,但它没有用</p><pre>import numpy as np np.array(['a', 'b', 'c'], dtype='&lt;U1') + np.array(['d','e', 'f'], dtype='&lt;U1')</pre><p> 如何无错误地连接那些 np.arrays ?</p></div></u1')>

[英]TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pearsonr:TypeError:没有找到与指定签名匹配的循环,并且为 ufunc add 找到了转换 Seaborn TypeError: No loop match the specified signature and cast was found for ufunc add when using hue 调用 func pearsonr 和 Got TypeError: 没有找到匹配指定签名和转换的循环用于 ufunc add np.linalg.lstsq(X,Y)[0] - TypeError: No loop match the specified signature and cast was found for ufunc lstsq_n 类型错误:ufunc &#39;add&#39; 不包含具有签名匹配类型的循环 获取没有匹配指定签名和转换错误的循环 Numpy polyfit ufunc中的Python TypeError不包含具有匹配签名类型的循环 TypeError: ufunc 'add' 不包含签名匹配类型 dtype(' <u1') dtype('<u1') dtype('<u1')< div><div id="text_translate"><p> 我是 Python 用户的初学者。 当我尝试在下面编写代码时发生错误</p><pre>import numpy as np np.array(['a', 'b', 'c']) + np.array(['d','e', 'f'])</pre><pre> TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('&lt;U1') dtype('&lt;U1') dtype('&lt;U1')</pre><p> 所以我尝试设置dtype = '&lt;U1' ,但它没有用</p><pre>import numpy as np np.array(['a', 'b', 'c'], dtype='&lt;U1') + np.array(['d','e', 'f'], dtype='&lt;U1')</pre><p> 如何无错误地连接那些 np.arrays ?</p></div></u1')> ufunc &#39;add&#39; 不包含签名匹配类型 dtype 的循环 TypeError:ufunc&#39;add&#39;不包含带有ARIMA模型签名的循环
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM