odd_errors(持续更新,欢迎补充,工程中遇到的错误)

本文探讨了在使用PyTorch进行深度学习时常见的运行时错误,包括CUDA内存溢出、非法内存访问及状态字典加载失败等问题,并提供了相应的解决策略。
  1. TypeError: ‘module’ object is not subscriptable
  2. RuntimeError: merge_sort: failed to synchronize: an illegal memory access was encountered
  3. RuntimeError: CUDA out of memory. Tried to allocate 322.00 MiB (GPU 0; 10.91 GiB total capacity; 8.62 GiB already allocated; 278.00 MiB free; 766.86 MiB cached)IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number .data[0]->.item()
  4. TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
  5. predict.data.numpy()->predict.data.cpu().numpy()
  6. RuntimeError: Error(s) in loading state_dict for CrowdCounter: Missing key(s) in state_dict: "CCN.de_pred.0.conv.bias
    net.load_state_dict(torch.load(model_path),strict=False) add strict=False
  7. THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1525796793591/work/torch/lib/THC/generic/THCStorage.c line=82 error=2 : out of memory ->cuda memory used off
从引用[3]可知,`odd_divider`可能指的是奇分频器相关内容。代码中给出了两种奇分频器的实现,分别是`odd_freqdiv_without55`和`odd_freqdiv_with55`。 `odd_freqdiv_without55`模块通过一个计数器`cnt`在时钟上升沿或复位信号下降沿进行计数操作。当复位信号有效时,计数器清零;否则,当计数器达到`TIMES - 1`时,计数器归零,否则计数器加 1。输出信号`clk_out`在计数器等于 1 时为 1,否则为 0。该模块实现了一个简单的奇分频功能,分频倍数由参数`TIMES`决定。 ```verilog `timescale 1ns/1ps module odd_freqdiv_without55 #(parameter TIMES = 3) ( input clk, input rst_n, output clk_out ); reg [1:0] cnt; always @(posedge clk or negedge rst_n) begin if (!rst_n) begin cnt <= 0; end else begin cnt <= (cnt == TIMES - 1)? 0 : (cnt + 1); end end assign clk_out = (cnt == 1)? 1 : 0; endmodule ``` `odd_freqdiv_with55`模块使用了两个计数器`cnt_p`和`cnt_n`,分别在时钟的上升沿和下降沿进行计数操作。同样,在复位信号有效时,计数器清零;否则,当计数器达到`TIMES - 1`时,计数器归零,否则计数器加 1。输出信号`clk_out`根据两个计数器的值来确定,当`cnt_n`不为 0 且小于等于`TIMES / 2`,或者`cnt_p`不为 0 且小于等于`TIMES / 2`时,`clk_out`为 1,否则为 0。该模块也实现了奇分频功能,并且考虑了时钟的上升沿和下降沿情况,可能在某些对时钟信号要求更精确的场景中使用。 ```verilog `timescale 1ns/1ps module odd_freqdiv_with55 #(parameter TIMES = 3) ( input clk, input rst_n, output clk_out ); reg [$clog2(TIMES) - 1 : 0] cnt_p; reg [$clog2(TIMES) - 1 : 0] cnt_n; always @(posedge clk or negedge rst_n) begin if (!rst_n) begin cnt_p <= 0; end else begin cnt_p <= (cnt_p == TIMES - 1)? 0 : (cnt_p + 1); end end always @(negedge clk or negedge rst_n) begin if (!rst_n) begin cnt_n <= 0; end else begin cnt_n <= (cnt_n == TIMES - 1)? 0 : (cnt_n + 1); end end assign clk_out = ((cnt_n != 0 && cnt_n <= TIMES / 2) || (cnt_p != 0 && cnt_p <= TIMES / 2))? 1 : 0; endmodule ``` 奇分频器在数字电路设计中有着广泛的应用,例如在时钟信号处理中,需要将高频时钟信号分频为低频时钟信号,以满足不同模块的时钟需求;在通信系统中,可能需要对时钟信号进行分频来实现特定的波特率等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值