1004. Counting Leaves (30)--dfs

深度优先搜索算法示例
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>

using namespace std;

int N,M;
struct node
{
    vector<int> child;
}cube[200];

int book[200]={0};
int maxx=-1;
void dfs(int id,int depth)
{
    if(cube[id].child.size()==0)//叶子
    {
        book[depth]++;
        if(depth>maxx)
        {
            maxx=depth;
        }
        return;
    }

    for(int i=0;i<cube[id].child.size();i++)
    {
        dfs(cube[id].child[i],depth+1);
    }

    return;
}

int main()
{
//    freopen("in.txt","r",stdin);

    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++)
    {
        int id;
        int n;
        scanf("%d %d",&id,&n);
        for(int j=0;j<n;j++)
        {
            int t;
            scanf("%d",&t);
            cube[id].child.push_back(t);
        }
    }

    dfs(1,0);

    for(int i=0;i<=maxx;i++)
    {
        printf("%d",book[i]);
        if(i!=maxx)
            printf(" ");
    }



    return 0;
}





(myenv) (base) E:\paddleDetection\PaddleDetection-release-2.8.1\deploy\pipeline>python deploy/pipeline/pipeline.py --config deploy/pipeline/config/infer_cfg_ppvehicle.yml \ --image_file="E:\屏幕截图_22-7-2025_94834_cn.bing.jpg"--device=gpu E:\anaconda\ana\python.exe: can't open file 'E:\\paddleDetection\\PaddleDetection-release-2.8.1\\deploy\\pipeline\\deploy\\pipeline\\pipeline.py': [Errno 2] No such file or directory (myenv) (base) E:\paddleDetection\PaddleDetection-release-2.8.1\deploy\pipeline>python E:\paddleDetection\PaddleDetection-release-2.8.1/deploy/pipeline/pipeline.py --config deploy/pipeline/config/infer_cfg_ppvehicle.yml \ --image_file="E:\屏幕截图_22-7-2025_94834_cn.bing.jpg"--device=gpu 信息: 用提供的模式无法找到文件。 E:\anaconda\ana\myenv\Lib\site-packages\paddle\utils\cpp_extension\extension_utils.py:715: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md warnings.warn(warning_message) Warning: Unable to use motmetrics in MTMCT in PP-Tracking, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics Warning: Unable to use motmetrics in MTMCT in PP-Tracking, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics usage: pipeline.py [-h] [-o [OPT ...]] --config CONFIG [--image_file IMAGE_FILE] [--image_dir IMAGE_DIR] [--video_file VIDEO_FILE] [--video_dir VIDEO_DIR] [--rtsp RTSP [RTSP ...]] [--camera_id CAMERA_ID] [--output_dir OUTPUT_DIR] [--pushurl PUSHURL] [--run_mode RUN_MODE] [--device DEVICE] [--enable_mkldnn ENABLE_MKLDNN] [--cpu_threads CPU_THREADS] [--trt_min_shape TRT_MIN_SHAPE] [--trt_max_shape TRT_MAX_SHAPE] [--trt_opt_shape TRT_OPT_SHAPE] [--trt_calib_mode TRT_CALIB_MODE] [--do_entrance_counting] [--do_break_in_counting] [--illegal_parking_time ILLEGAL_PARKING_TIME] [--region_type REGION_TYPE] [--region_polygon REGION_POLYGON [REGION_POLYGON ...]] [--secs_interval SECS_INTERVAL] [--draw_center_traj] pipeline.py: error: unrecognized arguments: \
最新发布
07-25
### 解决 PaddleDetection 中 `pipeline.py` 文件路径错误和参数错误问题 在使用 PaddleDetection 的 `pipeline.py` 进行目标检测时,如果遇到文件路径错误或参数错误,通常是由于配置文件路径不正确、参数传递方式错误或模型文件缺失等问题导致的。 #### 文件路径错误 文件路径错误通常表现为 `FileNotFoundError` 或类似的错误提示。在 PaddleDetection 中,`pipeline.py` 会依赖配置文件(如 `configs/ppyolo/ppyolo_r50vd_dcn_d12_3x_coco.yml`)和模型权重文件(如 `model.pdparams`)等资源。如果这些文件的路径未正确配置,就会导致文件无法找到。 确保所有文件路径为**绝对路径**或相对于 `pipeline.py` 的**正确相对路径**。例如,如果配置文件位于 `configs/ppyolo/ppyolo_r50vd_dcn_d12_3x_coco.yml`,则应确保该路径在运行时可访问。 #### 参数错误 参数错误通常表现为 `unrecognized arguments` 或 `missing arguments`。PaddleDetection 的 `pipeline.py` 接受多个命令行参数,例如 `--config` 指定配置文件、`--image_file` 指定输入图像路径等。如果传递了未定义的参数或遗漏了必要参数,程序将报错。 检查命令行参数是否符合 `pipeline.py` 所需的格式。例如: ```bash python pipeline.py --config configs/ppyolo/ppyolo_r50vd_dcn_d12_3x_coco.yml --image_file test.jpg ``` 上述命令中,`--config` 和 `--image_file` 是必须的参数,若遗漏或拼写错误,将导致参数错误。 #### 路径解析逻辑 PaddleDetection 的 `pipeline.py` 在解析文件路径时,可能涉及对字符串的路径处理逻辑。例如,以下代码片段展示了如何根据文件名后缀区分不同类型的文件并分别处理: ```python for s in source: # 按照路径符对字符串解析,以 macros.py 结尾的文件读取存在列表中 if (os.path.split(str(s))[1]).endswith('macros.py'): macro_lines.extend(ReadLines(str(s))) else: # 将所有 JS 文件加到列表中 modules.append(s) ``` 这种逻辑在路径处理中较为常见,若路径未正确解析,可能导致文件无法被正确识别[^2]。 #### 模型路径与训练/测试流程 PaddleDetection 的模型训练和测试流程通常依赖于配置文件和模型权重文件。如果路径配置错误,可能导致模型加载失败。例如,在训练过程中,如果模型权重文件路径不正确,将无法恢复训练或进行推理。 确保模型权重文件(如 `model.pdparams`)位于指定目录中,并在配置文件中正确引用。例如: ```yaml weights: output/ppyolo_r50vd_dcn_d12_3x_coco/model.pdparams ``` #### 示例命令 以下是一个完整的示例命令,用于运行 `pipeline.py` 进行目标检测: ```bash python pipeline.py \ --config configs/ppyolo/ppyolo_r50vd_dcn_d12_3x_coco.yml \ --image_file test.jpg \ --save_dir output/ ``` 该命令指定了配置文件、输入图像路径和输出保存目录,确保所有路径正确无误。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值