free(p->data.scores[i]);显示“free”: 实参不是指针 : 参数,怎么解决
时间: 2024-03-22 08:39:20 浏览: 19
这个错误是因为你尝试使用 `free()` 函数释放一个指向 `float` 类型的数据的指针,但是 `p->data.scores[i]` 实际上是一个指向指针的指针,而不是指向 `float` 类型数据的指针。
要解决这个问题,你需要首先释放 `p->data.scores[i]` 指向的内存,然后再释放 `p->data.scores[i]` 本身的内存。可以使用以下代码:
```
free(*(p->data.scores[i]));
free(p->data.scores[i]);
```
其中,`*(p->data.scores[i])` 可以将指向 `float` 类型数据的指针解引用,以释放它指向的内存。然后,你可以使用 `free()` 函数释放 `p->data.scores[i]` 本身的内存。
注意,你需要确保在释放 `p->data.scores[i]` 之前,先释放它指向的内存,否则会出现内存泄漏。
相关问题
for (int i = 0; i < 5; i++) { node->data.scores[i] = (float*)malloc(sizeof(float)); }显示错误“=”: 无法从“float *”转换为“float”,怎么解决
这个错误是因为你在给 `node->data.scores[i]` 分配内存时,使用了单个 `float*` 指针,而不是指向 `float` 类型数组的指针。因此,当你尝试将一个 `float*` 赋值给 `node->data.scores[i]` 时,会出现类型不匹配的错误。
要解决这个问题,你需要将 `node->data.scores[i]` 声明为指向 `float` 类型数组的指针,而不是单个 `float*`。可以使用以下代码:
```
for (int i = 0; i < 5; i++) {
node->data.scores[i] = (float*)malloc(sizeof(float) * num_scores);
}
```
其中,`num_scores` 是每个 `float` 类型数组中元素的数量。这将为 `node->data.scores[i]` 分配一个指向 `float` 类型数组的指针,使你能够向其分配和访问多个 `float` 类型的数据。
将下列numpy代码转化为纯pytorch代码: inds = np.where(scores > args.confidence_threshold)[:] boxes = boxes[inds] landms = landms[inds] scores = scores[inds]
请使用 PyTorch 的 mask 和 index_select 函数来替换 numpy 中的 where 和索引选择。
```
import torch
# 将 scores 转化为 PyTorch tensor
scores = torch.tensor(scores)
# 创建一个 mask,用来筛选出 scores 大于 args.confidence_threshold 的元素
mask = (scores > args.confidence_threshold)
# 使用 mask 和 index_select 函数来筛选出 boxes、landms 和 scores
boxes = boxes[mask]
landms = landms[mask]
scores = scores[mask]
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)