本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:C++ – 在CTC解码算法后移除相邻重复和blank索引
原文链接:https://www.stubbornhuang.com/2463/
发布于:2022年12月22日 10:34:38
修改于:2022年12月22日 10:34:38

1 C++ 在CTC解码算法后移除相邻重复和blank索引
在CTC Decode解码算法之后,比如说使用Greedy CTC Decode、Beam CTC decode、Prefix Beam CTC Decode算法之后,通常会得到包含blank索引的一个长序列,比如说
1,5,8,8,8,0,9,10,10,3,4
其中0表示blank,我们如果需要得到正确的结果,就需要将上述长序列中的blank和相邻的重复索引进行去除,比如说上述索引最终的正确结果如下
1,5,8,9,10,3,4
可以使用C++对上述功能进行实现,示例代码如下
#include <iostream>
#include <vector>
static std::vector<int> RemoveDuplicatesAndBlank(const std::vector<int>& hyp)
{
std::vector<int> result;
int current_index = 0;
while (current_index < hyp.size())
{
if (hyp[current_index] != 0)
result.emplace_back(hyp[current_index]);
int prev_index = current_index;
while (current_index < hyp.size() && hyp[current_index] == hyp[prev_index])
{
current_index += 1;
}
}
return result;
}
int main()
{
std::vector<int> a = {1,5,8,8,8,0,9,10,10,3,4 };
std::vector<int> b = RemoveDuplicatesAndBlank(a);
}
当前分类随机文章推荐
- C++ - 数组初始化 阅读255次,点赞0次
- C++ - 我的代码风格/代码规范备忘 阅读765次,点赞0次
- C++11/std::thread - 线程的基本用法 阅读3181次,点赞0次
- C++ - std::string输出双引号到字符串 阅读2905次,点赞0次
- C++11 - 父类与子类相互包含的时候该如何正确的使用智能指针,防止循环引用 阅读2449次,点赞0次
- C++11 - 快速学会正则表达式 阅读1259次,点赞2次
- C++ - 使用标准库实现事件和委托,信号和槽机制 阅读281次,点赞0次
- C++ - std::unordered_map中使用结构体或者vector等复杂的数据结构作为Key值 阅读329次,点赞0次
- C++11 - 解析并获取可变参数模板中的所有参数 阅读1141次,点赞0次
- C++ - linux编译C++代码出现error: use of deleted function std::atomic
::atomic(const std::atomic 阅读2357次,点赞0次&)
全站随机文章推荐
- Duilib - 修改程序图标以及任务栏图标 阅读305次,点赞0次
- 工具软件推荐 - 好用的免费电子书格式转换器Neat Converter 阅读881次,点赞0次
- 资源分享 - Beginning DirectX 11 Game Programming 英文高清PDF下载 阅读1183次,点赞0次
- FFmpeg - PTS、DTS、时间基、时间戳详解 阅读321次,点赞0次
- 资源分享 - 3D Game Engine Design - A Practical Approach to Real-Time Computer Graphics 英文高清PDF下载 阅读1204次,点赞0次
- 资源分享 - Ray Tracing - A Tool for All 英文高清PDF下载 阅读1604次,点赞0次
- C++ - 使用模板和智能指针构建一个双向链表工具类 阅读815次,点赞0次
- OpenCV - 创建新图像以及遍历图片像素值和设置像素值 阅读3001次,点赞0次
- C++ – 字节数组byte[]或者unsigned char[]与short的相互转换 阅读1231次,点赞0次
- C++ - 将Unicode std::wstring字符串转换为Unicode std::string转义字符,类似于\uxxxx的形式 阅读1423次,点赞0次
评论
167