![](/img/trans.png)
[英]Pearsonr: TypeError: No loop matching the specified signature and casting was found for ufunc add
[英]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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.