简体   繁体   中英

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

I'm a beginner to python and machine learning. When I ran the train.py of a project based on the yolov5 (The link of the project is https://github.com/DocF/multispectral-object-detection ), I get below error:

Traceback (most recent call last): File "E:\0_Final_Project\GithubProject\multispectral-object-detection-main\train.py", line 1010, in train_rgb_ir(hyp, opt, device, tb_writer) File "E:\0_Final_Project\GithubProject\multispectral-object-detection-main\train.py", line 647, in 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", line 358, in histogram 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", line 386, in make_histogram cum_counts = np.cumsum(np.greater(counts, 0, dtype=np.int32)) TypeError: No loop matching the specified signature and casting was found for ufunc greater

Related code:

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(),
    )

I have looked up on the stackoverflow and google, but I couldn't find anything helpful to solve this issue. Please help! Thanks

Try with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM