JM8.6解码端是如何从配置文件decoder.cfg获取数据的? (init_conf函数)

本文详细介绍了ldecod.c文件中init_conf函数的工作原理,该函数用于从配置文件decoder.cfg中读取数据,并将这些数据填充到指定的结构体中。文章展示了如何处理配置文件中的各个参数,并解释了它们的意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      在ldecod.c文件的main中调用了init_conf函数,这个函数实际上就实现了程序从配置文件读数据的过程. 之前说过,在JM8.6编码端,Configure函数起着做配置文件encoder_baseline.cfg数据的作用,现在来看看解码端的init_conf函数.

      main中是这样调用的:

init_conf(input, argv[1]);


     其中input是一个结构体指针,字符串指针argv[1]实际上就指向了字符串"decoder.cfg", 进入init_conf函数看看:

void init_conf(struct inp_par *inp,
               char *config_filename)
{
  FILE *fd;
  int NAL_mode;

  // read the decoder configuration file
  if((fd=fopen(config_filename,"r")) == NULL)
  {
    snprintf(errortext, ET_SIZE, "Error: Control file %s not found\n",config_filename);
    error(errortext, 300);
  }

  fscanf(fd,"%s",inp->infile);                // H.264 compressed input bitsream
  
  // 过滤配置文件中的“注释”
  fscanf(fd,"%*[^\n]");

  fscanf(fd,"%s",inp->outfile);               // YUV 4:2:2 input format
  fscanf(fd,"%*[^\n]");

  fscanf(fd,"%s",inp->reffile);               // reference file
  fscanf(fd,"%*[^\n]");


  // Frame buffer size
  fscanf(fd,"%d,",&inp->dpb_size);   // may be overwritten in case of RTP NAL
  fscanf(fd,"%*[^\n]");
  if (inp->dpb_size < 1)
  {
    snprintf(errortext, ET_SIZE, "Decoded Picture Buffer Size is %d. It has to be at least 1",inp->dpb_size);
    error(errortext,1);
  }

  fscanf(fd,"%d",&(NAL_mode));                // NAL mode
    fscanf(fd,"%*[^\n]");

  switch(NAL_mode)
  {
  case 0:
    inp->FileFormat = PAR_OF_ANNEXB;
    break;
  case 1:
    inp->FileFormat = PAR_OF_RTP;
    break;
  default:
    snprintf(errortext, ET_SIZE, "NAL mode %i is not supported", NAL_mode);
    error(errortext,400);
  }

  fscanf(fd,"%d,",&inp->ref_offset);   // offset used for SNR computation
  fscanf(fd,"%*[^\n]");

  fscanf(fd,"%d,",&inp->poc_scale);   // offset used for SNR computation
  fscanf(fd,"%*[^\n]");


  if (inp->poc_scale < 1 || inp->poc_scale > 2)
  {
    snprintf(errortext, ET_SIZE, "Poc Scale is %d. It has to be 1 or 2",inp->poc_scale);
    error(errortext,1);
  }

#ifdef _LEAKYBUCKET_
  fscanf(fd,"%ld,",&inp->R_decoder);             // Decoder rate
  fscanf(fd, "%*[^\n]");
  fscanf(fd,"%ld,",&inp->B_decoder);             // Decoder buffer size
  fscanf(fd, "%*[^\n]");
  fscanf(fd,"%ld,",&inp->F_decoder);             // Decoder initial delay
  fscanf(fd, "%*[^\n]"); 
  fscanf(fd,"%s",inp->LeakyBucketParamFile);    // file where Leaky Bucket params (computed by encoder) are stored
  fscanf(fd,"%*[^\n]");
#endif

  fclose (fd);


#if TRACE
  if ((p_trace=fopen(TRACEFILE,"w"))==0)             // append new statistic at the end
  {
    snprintf(errortext, ET_SIZE, "Error open file %s!",TRACEFILE);
    error(errortext,500);
  }
#endif


  if ((p_out=fopen(inp->outfile,"wb"))==0)
  {
    snprintf(errortext, ET_SIZE, "Error open file %s ",inp->outfile);
    error(errortext,500);
  }
/*  if ((p_out2=fopen("out.yuv","wb"))==0)
  {
    snprintf(errortext, ET_SIZE, "Error open file %s ",inp->outfile);
    error(errortext,500);
  }*/

  fprintf(stdout,"--------------------------------------------------------------------------\n");
  fprintf(stdout," Decoder config file                    : %s \n",config_filename);
  fprintf(stdout,"--------------------------------------------------------------------------\n");
  fprintf(stdout," Input H.264 bitstream                  : %s \n",inp->infile);
  fprintf(stdout," Output decoded YUV 4:2:0               : %s \n",inp->outfile);
  fprintf(stdout," Output status file                     : %s \n",LOGFILE);
  if ((p_ref=fopen(inp->reffile,"rb"))==0)
  {
    fprintf(stdout," Input reference file                   : %s does not exist \n",inp->reffile);
    fprintf(stdout,"                                          SNR values are not available\n");
  }
  else
    fprintf(stdout," Input reference file                   : %s \n",inp->reffile);

  fprintf(stdout,"--------------------------------------------------------------------------\n");
#ifdef _LEAKYBUCKET_
  fprintf(stdout," Rate_decoder        : %8ld \n",inp->R_decoder);
  fprintf(stdout," B_decoder           : %8ld \n",inp->B_decoder);
  fprintf(stdout," F_decoder           : %8ld \n",inp->F_decoder);
  fprintf(stdout," LeakyBucketParamFile: %s \n",inp->LeakyBucketParamFile); // Leaky Bucket Param file
  calc_buffer(inp);
  fprintf(stdout,"--------------------------------------------------------------------------\n");
#endif
  fprintf(stdout,"POC must = frame# or field# for SNRs to be correct\n");
  fprintf(stdout,"Frame    POC   QP  SnrY    SnrU    SnrV   Time(ms)\n");
}


       可见,通过调用init_conf函数,实际上就是把argv[1]对应的配置文件的数据往input对应的结构体中倾倒,像倒茶一般, 这样,程序中的全局的指针变量对应的结构体就获得了配置文件encoder.cfg中的数据.

      

       最后,附带给出配置文件decoder.cfg中的内容:

test.264                 ........H.264 coded bitstream
test_dec.yuv             ........Output file, YUV 4:2:0 format
test_rec.yuv             ........Ref sequence (for SNR)
10                       ........Decoded Picture Buffer size
0                        ........NAL mode (0=Annex B, 1: RTP packets)
0                        ........SNR computation offset
1                        ........Poc Scale (1 or 2)
500000                   ........Rate_Decoder
104000                   ........B_decoder
73000                    ........F_decoder
leakybucketparam.cfg     ........LeakyBucket Params

This is a file containing input parameters to the JVT H.264/AVC decoder.
The text line following each parameter is discarded by the decoder.

 

 

 

<think>好的,我现在需要帮助用户解决如何在没有AI文件夹路径的情况下,将下载的ONNX模型配置到最新版的Labelme中,以便使用本地AI进行标注。首先,我得先理解用户的问题。用户提到他们下载了多个SAM模型的ONNX文件,但不知道如何配置这些文件,使得Labelme能够使用它们进行本地标注,而无需AI文件夹路径。 首先,我应该回忆一下Labelme的基本结构和配置方式。Labelme是一个常用的图像标注工具,通常用于创建语义分割的数据集。它本身可能不直接集成AI模型,但可能有插件或扩展功能。用户提到的ONNX文件是Meta的Segment Anything Model(SAM)的量化版本,分为编码器和解码器,不同架构如vit_b、vit_h、vit_l等。用户希望将这些模型集成到Labelme中,以实现自动标注。 接下来,我需要考虑Labelme是否有内置的AI模型支持。根据我的知识,Labelme本身可能不直接支持SAM模型,但可能有社区开发的插件或需要手动修改配置文件。用户提到的“没有AI文件夹路径”可能意味着默认安装的Labelme没有预设的AI模型目录,需要用户手动指定模型路径。 可能的解决步骤包括: 1. 确认Labelme版本:确保用户使用的是最新版本,可能包含新的AI功能。 2. 查找配置文件:Labelme的配置文件可能在哪里?通常可能是JSON文件,存储在用户目录下的隐藏文件夹中,如~/.labelmerc。 3. 手动添加模型路径:用户需要将下载的ONNX文件路径添加到配置文件中,指定编码器和解码器的对应关系。 4. 安装依赖库:使用SAM模型可能需要额外的Python库,如onnxruntime、torch等,确保这些库已安装。 5. 启动Labelme并测试:修改配置后,启动Labelme检查是否识别到模型,并测试自动标注功能。 需要验证这些步骤是否正确。例如,Labelme的文档或GitHub仓库是否有相关说明?可能需要查阅Labelme的官方文档或GitHub issues,寻找关于集成SAM模型的指南。此外,用户可能需要将模型文件放在特定目录,或者在配置文件中明确指定每个模型的路径。 可能遇到的问题: - 配置文件的位置和格式不明确,用户可能需要指导如何找到或创建。 - 模型路径的正确设置,确保编码器和解码器配对正确。 - 依赖库版本不兼容,导致模型加载失败。 - Labelme的AI功能可能需要特定的插件或补丁,用户需要安装额外的扩展。 需要详细说明每个步骤,包括具体的命令和文件路径示例。例如,如何编辑~/.labelmerc文件,添加模型路径,或者使用命令行参数指定模型目录。同时,提醒用户注意ONNX文件与模型版本的对应关系,确保编码器和解码器匹配。 此外,用户可能需要启用Labelme的AI功能,可能需要在启动时使用特定参数,或者在界面中选择模型。需要指导用户如何在软件中找到这些选项。 最后,提供验证步骤,确保用户能够测试模型是否正常工作,例如加载图像后使用自动标注功能,观察是否生成分割结果。 总结回答结构: 1. 确认Labelme版本和支持情况。 2. 安装必要依赖。 3. 整理模型文件路径。 4. 修改Labelme配置文件,添加模型路径。 5. 启动Labelme并测试AI标注功能。 6. 常见问题解决方法。 需要确保步骤清晰,用户能逐步操作,并处理可能的错误情况。</think>在最新版 LabelMe 中使用本地 SAM 模型进行 AI 标注,需通过手动配置模型路径实现。以下是完整步骤: --- ### **1. 环境准备** ```bash # 安装 LabelMe 最新版本及 ONNX 依赖 pip install labelme onnxruntime ``` --- ### **2. 整理模型文件** 将下载的 SAM 模型按架构分类(示例路径): ``` ~/sam_models/ ├── vit_b │ ├── sam_vit_b_01ec64.quantized.encoder.onnx │ └── sam_vit_b_01ec64.quantized.decoder.onnx ├── vit_h │ ├── sam_vit_h_4b8939.quantized.encoder.onnx │ └── sam_vit_h_4b8939.quantized.decoder.onnx └── vit_l ├── sam_vit_l_0b3195.quantized.encoder.onnx └── sam_vit_l_0b3195.quantized.decoder.onnx ``` --- ### **3. 修改 LabelMe 配置文件** LabelMe 默认从 `~/.labelmerc` 读取配置,手动添加模型路径: ```json { "ai": { "sam": { "vit_b": { "encoder": "/home/用户名/sam_models/vit_b/sam_vit_b_01ec64.quantized.encoder.onnx", "decoder": "/home/用户名/sam_models/vit_b/sam_vit_b_01ec64.quantized.decoder.onnx" }, "vit_h": { "encoder": "/home/用户名/sam_models/vit_h/sam_vit_h_4b8939.quantized.encoder.onnx", "decoder": "/home/用户名/sam_models/vit_h/sam_vit_h_4b8939.quantized.decoder.onnx" }, "vit_l": { "encoder": "/home/用户名/sam_models/vit_l/sam_vit_l_0b3195.quantized.encoder.onnx", "decoder": "/home/用户名/sam_models/vit_l/sam_vit_l_0b3195.quantized.decoder.onnx" } } } } ``` --- ### **4. 启动 LabelMe 并使用 AI 标注** ```bash # 启动时指定 AI 模型 labelme --ai-model sam_vit_b ``` **操作步骤:** 1. 打开图像后,点击菜单栏 `AI` > `Auto Segment`。 2. 选择已配置的模型(如 `sam_vit_b`)。 3. 点击图像生成标注掩膜,自动创建多边形标注框。 --- ### **5. 常见问题** - **模型路径错误**:确保路径中的用户名需替换为实际路径,如 `/home/username/...`。 - **依赖缺失**:若报错 `onnxruntime` 缺失,运行 `pip install onnxruntime`。 - **模型不匹配**:确认编码器和解码器版本一致(如 `vit_b` 的 encoder 必须对应 `vit_b` 的 decoder)。 --- ### **扩展功能** - **批量处理**:结合 `labelme.cli` 模块实现自动化标注脚本。 - **自定义模型**:替换其他 ONNX 模型时,需遵循相同接口规范。 ---
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值