1012. The Best Rank (25)

题目:1012. The Best Rank (25)
思路:开了两个数组,暴力解决的;暂时没想到其它好方法;

#include<stdio.h>
#include<stdlib.h>
#define N 1000
struct stuinfo
{
    int id;
    int score[4];
    int rank[4];
    int bestrank;
    char sign;
}s[N];
int ansid[1000000];
char anschar[1000000];
int compa(const void *a,const void *b);
int compc(const void *a,const void *b);
int compm(const void *a,const void *b);
int compe(const void *a,const void *b);
int main()
{
    int n,m,i;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d %d %d %d",&s[i].id,&s[i].score[0],&s[i].score[1],&s[i].score[2]);
        int sum=s[i].score[0]+s[i].score[1]+s[i].score[2];
        if(sum%3==2)s[i].score[3]=sum/3+1;//求平均数 
        else s[i].score[3]=sum/3;
        s[i].rank[0]=s[i].rank[1]=s[i].rank[2]=s[i].rank[3]=n+1;//排名初始化 
    }
    qsort(s,n,sizeof(struct stuinfo),compa);
    for(i=0;i<n;i++)
    {
        if(i&&s[i-1].score[3]==s[i].score[3])s[i].rank[3]=s[i-1].rank[3];
        else s[i].rank[3]=i+1;
        s[i].bestrank=s[i].rank[3];
        s[i].sign='A';
    }
    qsort(s,n,sizeof(struct stuinfo),compc);
    for(i=0;i<n;i++)
    {
        if(i&&s[i-1].score[0]==s[i].score[0])s[i].rank[0]=s[i-1].rank[0];
        else s[i].rank[0]=i+1;
        if(s[i].rank[0]<s[i].bestrank)
        {
            s[i].bestrank=s[i].rank[0];
            s[i].sign='C';
        }
    }
    qsort(s,n,sizeof(struct stuinfo),compm);
    for(i=0;i<n;i++)
    {
        if(i&&s[i-1].score[1]==s[i].score[1])s[i].rank[1]=s[i-1].rank[1];
        else s[i].rank[1]=i+1;
        if(s[i].rank[1]<s[i].bestrank)
        {
            s[i].bestrank=s[i].rank[1];
            s[i].sign='M';
        }
    }
    qsort(s,n,sizeof(struct stuinfo),compe);
    for(i=0;i<n;i++)
    {
        if(i&&s[i-1].score[2]==s[i].score[2])s[i].rank[2]=s[i-1].rank[2];
        else s[i].rank[2]=i+1;
        if(s[i].rank[2]<s[i].bestrank)
        {
            s[i].bestrank=s[i].rank[2];
            s[i].sign='E';
        }
    }
    for(i=0;i<n;i++)
    {
        ansid[s[i].id]=s[i].bestrank;
        anschar[s[i].id]=s[i].sign;
    }
    for(i=0;i<m;i++)
    {
        int curid;
        scanf("%d",&curid);
        if(ansid[curid])
            printf("%d %c\n",ansid[curid],anschar[curid]);
        else
            printf("N/A\n");
    }
    return 0;
} 
int compa(const void *a,const void *b)
{
    return ((struct stuinfo *)b)->score[3]-((struct stuinfo *)a)->score[3];
}
int compc(const void *a,const void *b)
{
    return ((struct stuinfo *)b)->score[0]-((struct stuinfo *)a)->score[0];
}
int compm(const void *a,const void *b)
{
    return ((struct stuinfo *)b)->score[1]-((struct stuinfo *)a)->score[1];
}
int compe(const void *a,const void *b)
{
    return ((struct stuinfo *)b)->score[2]-((struct stuinfo *)a)->score[2];
}

转载于:https://www.cnblogs.com/xLester/p/7570474.html

D:\create\conda1\envs\python37\python.exe D:\create\programm\yolov5-master\train.py github: skipping check (not a git repository), for updates see https://github.com/ultralytics/yolov5 train: weights=yolov5s.pt, cfg=models/yolov5s.yaml, data=data\sign.yaml, hyp=data\hyps\hyp.scratch-low.yaml, epochs=300, batch_size=16, imgsz=640, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, evolve_population=data\hyps, resume_evolve=None, bucket=, cache=None, image_weights=False, device=0, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=8, project=runs\train, name=exp, exist_ok=False, quad=False, cos_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, seed=0, local_rank=-1, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest, ndjson_console=False, ndjson_file=False YOLOv5 2025-8-14 Python-3.13.5 torch-2.6.0+cu126 CUDA:0 (NVIDIA GeForce RTX 4060 Laptop GPU, 8188MiB) hyperparameters: lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0 Comet: run 'pip install comet_ml' to automatically track and visualize YOLOv5 runs in Comet TensorBoard: Start with 'tensorboard --logdir runs\train', view at http://localhost:6006/ from n params module arguments 0 -1 1 3520 models.common.Conv [3, 32, 6, 2, 2] 1 -1 1 18560 models.common.Conv [32, 64, 3, 2] 2 -1 1 18816 models.common.C3 [64, 64, 1] 3 -1 1 73984 models.common.Conv [64, 128, 3, 2] 4 -1 2 115712 models.common.C3 [128, 128, 2] 5 -1 1 295424 models.common.Conv [128, 256, 3, 2] 6 -1 3 625152 models.common.C3 [256, 256, 3] 7 -1 1 1180672 models.common.Conv [256, 512, 3, 2] 8 -1 1 1182720 models.common.C3 [512, 512, 1] 9 -1 1 656896 models.common.SPPF [512, 512, 5] 10 -1 1 131584 models.common.Conv [512, 256, 1, 1] 11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] 12 [-1, 6] 1 0 models.common.Concat [1] 13 -1 1 361984 models.common.C3 [512, 256, 1, False] 14 -1 1 33024 models.common.Conv [256, 128, 1, 1] 15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] 16 [-1, 4] 1 0 models.common.Concat [1] 17 -1 1 90880 models.common.C3 [256, 128, 1, False] 18 -1 1 147712 models.common.Conv [128, 128, 3, 2] 19 [-1, 14] 1 0 models.common.Concat [1] 20 -1 1 296448 models.common.C3 [256, 256, 1, False] 21 -1 1 590336 models.common.Conv [256, 256, 3, 2] 22 [-1, 10] 1 0 models.common.Concat [1] 23 -1 1 1182720 models.common.C3 [512, 512, 1, False] 24 [17, 20, 23] 1 64728 models.yolo.Detect [19, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]] YOLOv5s summary: 214 layers, 7070872 parameters, 7070872 gradients, 16.1 GFLOPs Transferred 342/349 items from yolov5s.pt D:\create\programm\yolov5-master\models\common.py:906: FutureWarning: `torch.cuda.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cuda', args...)` instead. with amp.autocast(autocast): D:\create\programm\yolov5-master\models\common.py:906: FutureWarning: `torch.cuda.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cuda', args...)` instead. with amp.autocast(autocast): AMP: checks passed optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 60 weight(decay=0.0005), 60 bias train: Scanning D:\create\programm\datasets\labels\train.cache... 493 images, 7 backgrounds, 0 corrupt: 100%|██████████| 500/500 [00:00<?, ?it/s] val: Scanning D:\create\programm\datasets\labels\val.cache... 7 images, 5 backgrounds, 0 corrupt: 100%|██████████| 12/12 [00:00<?, ?it/s] OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ AutoAnchor: 6.00 anchors/target, 1.000 Best Possible Recall (BPR). Current anchors are a good fit to dataset Plotting labels to runs\train\exp16\labels.jpg... OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/ 进程已结束,退出代码为 3
09-04
<think> 我们面对的主要问题是YOLOv5训练脚本运行时出现的两个问题: 1. 重复的OpenMP运行时库初始化错误:`OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized.` 2. 训练进程结束,退出代码为3(通常表示程序因错误而终止) 根据引用[1][2][3],该错误的原因是多个OpenMP运行时库(`libomp.dll`和`libiomp5md.dll`)在同一进程中被加载。这通常发生在多个库(如PyTorch、OpenCV、LightGBM等)都静态链接了OpenMP运行时,导致冲突。错误提示建议设置环境变量`KMP_DUPLICATE_LIB_OK=TRUE`作为临时解决方案,但这不是根本解决办法,可能带来性能下降或崩溃风险。 解决方案需要从根源上消除重复加载。结合引用[3]的方法,我们有两种主要方案: ### 方案一:临时环境变量设置(快速验证) 在运行训练脚本前设置环境变量: ```bash set KMP_DUPLICATE_LIB_OK=TRUE python train.py --参数 ``` 或在Python脚本开头添加: ```python import os os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE' ``` **注意**:此方法仅临时绕过错误,可能影响稳定性[^3]。 ### 方案二:删除冲突的DLL文件(推荐) 根据引用[3],我们可以删除Anaconda环境中的`libiomp5md.dll`以避免冲突。具体步骤如下: 1. 激活您使用的conda环境(例如名为`python37`): ```bash conda activate python37 ``` 2. 定位到环境目录下的`Library\bin`文件夹,例如: ``` D:\create\conda1\envs\python37\Library\bin ``` 3. 在该目录下找到`libiomp5md.dll`文件,将其重命名(例如改为`libiomp5md.dll.bak`)或删除。 4. 重新运行训练脚本。 ### 方案三:更新/重新安装相关库 更新PyTorch、torchvision以及其他可能使用OpenMP的库(如numpy、scipy、opencv-python)到最新版本,确保它们使用相同版本的OpenMP: ```bash pip install --upgrade torch torchvision numpy opencv-python ``` ### 额外建议:验证CUDA和cuDNN 退出代码3也可能与CUDA环境有关。请确认: - PyTorch版本与CUDA版本匹配(使用`torch.cuda.is_available()`检查) - 更新NVIDIA显卡驱动 ### 验证修复后的效果 重新运行训练命令: ```bash D:\create\conda1\envs\python37\python.exe D:\create\programm\yolov5-master\train.py ``` 观察是否还会出现`OMP`错误,并检查退出代码是否正常(0表示成功)。 §§相关问题§§ 1. 如何诊断Windows环境下其他库的DLL冲突错误?(例如`cudart64_110.dll`未找到) 2. 在YOLOv5训练中,退出代码3还可能由哪些原因引起? 3. 如何彻底解决多个Python库之间的OpenMP冲突? [^1]: 引用自OpenMP初始化错误解决方法 [^2]: 引用自faiss包报错解决方案 [^3]: 引用自删除冲突DLL文件方案 </think> ### 解决YOLOv5训练中'OMP: Error #15'错误及退出代码3问题 针对您遇到的`OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized`错误和程序退出代码3的问题,提供以下系统级解决方案: --- ### 一、根本原因分析 1. **OpenMP库冲突**:多个OpenMP运行时库(`libomp.dll`和`libiomp5md.dll`)被同时加载,导致初始化冲突[^1][^2] 2. **环境变量问题**:Anaconda环境中存在冗余的OpenMP库文件 3. **PyTorch版本兼容性**:退出代码3通常表示CUDA或库初始化失败 --- ### 二、永久解决方案(推荐) #### 方法1:删除冲突的DLL文件(最有效) 1. 打开Anaconda环境目录: ```bash D:\create\conda1\envs\python37\Library\bin ``` 2. 查找并删除以下文件: - `libiomp5md.dll` - `libomp.dll` 3. 保留单一OpenMP库(建议保留`libomp.dll`) > **原理**:删除冗余库可消除冲突源[^3] #### 方法2:修复环境变量优先级 1. 编辑系统环境变量: ```powershell # PowerShell管理员模式执行 [Environment]::SetEnvironmentVariable("PATH", [Environment]::GetEnvironmentVariable("PATH", "Machine").Replace("C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\bin;", ""), "Machine") ``` 2. 确保PyTorch库路径优先: ```powershell $newPath = "D:\create\conda1\envs\python37\Library\bin;" + [Environment]::GetEnvironmentVariable("PATH", "Machine") [Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") ``` --- ### 三、临时解决方案 在训练脚本开头添加(不推荐长期使用): ```python import os os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE' # 绕过冲突检测[^1][^2] ``` --- ### 四、退出代码3的专项解决 1. **CUDA兼容性验证**: ```python import torch print(torch.__version__) # 应 ≥ 1.10 print(torch.cuda.is_available()) # 应返回True ``` 2. **PyTorch重安装**: ```bash pip uninstall torch torchvision pip install torch==2.0.0+cu117 torchvision==0.15.1+cu117 -f https://download.pytorch.org/whl/torch_stable.html ``` --- ### 五、预防措施 1. **创建纯净环境**: ```bash conda create -n yolov5_fixed python=3.8 conda activate yolov5_fixed pip install -r yolov5/requirements.txt ``` 2. **OpenMP库验证**: ```powershell # 检查重复库 where /R D:\create\conda1 envs\python37 libiomp*.dll ``` > **验证成功标志**:训练启动后不再出现'OMP: Error #15'提示,且退出代码为0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值