<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>chen-xiuwei</title>
 <link href="https://chen-xw.github.io/atom.xml" rel="self"/>
 <link href="https://chen-xw.github.io/"/>
 <updated>2026-04-12T05:34:49+00:00</updated>
 <id>https://chen-xw.github.io</id>
 <author>
   <name>chen-xw</name>
   <email></email>
 </author>

 
 <entry>
   <title>烹饪</title>
   <link href="https://chen-xw.github.io/%E7%83%B9%E9%A5%AA/2026-02-02-%E7%83%B9%E9%A5%AA/"/>
   <updated>2026-02-02T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/%E7%83%B9%E9%A5%AA/烹饪</id>
   <content type="html">&lt;p&gt;后续记录烹饪技巧。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;烹饪菜品分类&lt;/strong&gt;&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;肉菜&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;红烧排骨&lt;/li&gt;
  &lt;li&gt;姜抄鸡心&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;素菜&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;土豆丝&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Prompt</title>
   <link href="https://chen-xw.github.io/machine/learning/2022-12-07-prompt/"/>
   <updated>2022-12-07T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/machine/learning/prompt</id>
   <content type="html">&lt;p&gt;对Prompt的一个总结。&lt;/p&gt;

&lt;h3 id=&quot;学习资源&quot;&gt;&lt;strong&gt;学习资源&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/442486331&quot;&gt;一个总结&lt;/a&gt;
___&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;目标&quot;&gt;&lt;strong&gt;目标&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;暂时写到这有空了再来补充&quot;&gt;暂时写到这，有空了再来补充&lt;/h3&gt;
</content>
 </entry>
 
 <entry>
   <title>Clip</title>
   <link href="https://chen-xw.github.io/machine/learning/2022-12-07-clip/"/>
   <updated>2022-12-07T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/machine/learning/clip</id>
   <content type="html">&lt;p&gt;对Clip的一个总结。&lt;/p&gt;

&lt;h3 id=&quot;学习资源&quot;&gt;&lt;strong&gt;学习资源&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/493489688#:~:text=CLIP%E6%98%AF%E4%B8%80%E7%A7%8D%E5%9F%BA,%E5%83%8F%E5%AF%B9%E7%9A%84%E5%8C%B9%E9%85%8D%E5%85%B3%E7%B3%BB%E3%80%82&quot;&gt;一个系统的总结&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/432590298&quot;&gt;Just so so的总结&lt;/a&gt;
___&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;目标&quot;&gt;&lt;strong&gt;目标&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;暂时写到这有空了再来补充&quot;&gt;暂时写到这，有空了再来补充&lt;/h3&gt;
</content>
 </entry>
 
 <entry>
   <title>Data Augmentation</title>
   <link href="https://chen-xw.github.io/machine/learning/2022-09-04-Data-Augmentation/"/>
   <updated>2022-09-04T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/machine/learning/Data Augmentation</id>
   <content type="html">&lt;p&gt;合适的数据增广方法对于最后模型的精度具有重要的影响，本文总结了常用的数据增广方法。&lt;/p&gt;

&lt;h3 id=&quot;学习资源&quot;&gt;&lt;strong&gt;学习资源&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/61759947&quot;&gt;总结&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/439206910&quot;&gt;AutoAugment 总结&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://openaccess.thecvf.com/content_CVPR_2019/papers/Cubuk_AutoAugment_Learning_Augmentation_Strategies_From_Data_CVPR_2019_paper.pdf&quot;&gt;AutoAugment Paper&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1909.13719&quot;&gt;RandAugment Paper&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1106.1813&quot;&gt;SMOTE&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1801.02929&quot;&gt;SamplePairing&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1710.09412&quot;&gt;mixup&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;分类&quot;&gt;&lt;strong&gt;分类&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;——————&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;有监督的数据增强（采用预设的数据变换规则，在已有数据的基础上进行数据的扩增，包含单样本数据增强和多样本数据增强，其中单样本又包括几何操作类，颜色变换类）多样本数据增强中，利用多个样本来产生新的样本（SMOTE，Samplepairing,mixup等）&lt;/li&gt;
  &lt;li&gt;无监督的数据增强，包括两类（1）通过模型学习数据的分布，随机生成与训练数据集分布一致的图像（GAN代表方法）（2）通过模型学习出适合当前任务的数据增强方法（AutoAugment代表方法）&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;autoaugment常用基础方法&quot;&gt;&lt;strong&gt;Autoaugment常用基础方法&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;ShearX(Y)是沿着x/y轴，固定另外一轴进行放射变换的过程&lt;/li&gt;
  &lt;li&gt;TranslateX(Y)就是在水平/竖直两个方向平移图像，&lt;/li&gt;
  &lt;li&gt;Rotate 旋转也是一种放射变换，围绕着旋转中心旋转一定角度&lt;/li&gt;
  &lt;li&gt;AutoContrast，Contrast 图像的对比度是指图像明亮的地方与灰暗地方的像素的差别。可以认为扩大差别或者减少。自动增加对比度是指让图像中最大的灰度变为255，最小的灰度变为0，然后依次成比率改变图像的像素。&lt;/li&gt;
  &lt;li&gt;Invert 是指对图像的像素值全部变成255&lt;/li&gt;
  &lt;li&gt;Equalize 是指把图像的密度直方图给规则化一下。图像本质上是一组采样数据，我们可以以像素值为划分，观察在每一个像素值上有多少个像素，这就是所谓的图像直方图。可以根据直方图做出F的分布函数，Equalize操作本质上是希望这个分布函数是线性均匀上升到1的，这就是均衡化操作。&lt;/li&gt;
  &lt;li&gt;Solarize 是指给定一个阈值，对像素值大于阈值的所有像素点做invert操作。&lt;/li&gt;
  &lt;li&gt;Posterize 把原来每个像素用8比特表示的图像压缩到更少的比特（一个更好的压缩方法是Vector Quantization）&lt;/li&gt;
  &lt;li&gt;Color 将颜色从RGB空间向HSV空间进行转移，其中V表示明度，S表示饱和度，H表示色调。&lt;/li&gt;
  &lt;li&gt;Brightness 就是图像的亮度，他是HSV空间的V部分，V为0的时候表示非常暗，越高代表视觉上的越亮&lt;/li&gt;
  &lt;li&gt;Sharpness 代表图像的锐度。锐度计算是通过图像的梯度进行计算的，即对图像的像素空间进行差分，一般差分值大的部分代表图像变化剧烈，这也就是所谓的边缘部分，增大这些边缘就会显得锐度变大。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;其他&quot;&gt;&lt;strong&gt;其他&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;————&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Cutout,与randomerasing类似，也是通过填充区域，从而将填充区域的图像信息遮挡，有利于提高模型的泛化能力。与RandomErasing不同的是，Cutout使用固定大小的正方形区域，采用全0填充，而且允许正方形区域在图片外。&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Incremental Learning</title>
   <link href="https://chen-xw.github.io/machine/learning/2022-06-24-Few-Shot-Learning/"/>
   <updated>2022-06-24T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/machine/learning/Few Shot Learning</id>
   <content type="html">&lt;p&gt;Incremental Learning’s Survey,挺长时间没有进行总结了，现在花点时间总结一下近期在做的方向，这段时间主要进行的是对增量学习的研究。&lt;/p&gt;

&lt;h3 id=&quot;学习资源&quot;&gt;&lt;strong&gt;学习资源&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/xialeiliu/Awesome-Incremental-Learning&quot;&gt;全集论文合集&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/G-U-N/PyCIL&quot;&gt;代码合集&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;目标&quot;&gt;&lt;strong&gt;目标&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;借用一篇论文中话” Incremental Learning aims to develop artificially intelligent systems that can continuously learn to address new tasks from new data while preserving knowledge learned from previously learned tasks.&lt;/li&gt;
  &lt;li&gt;我的理解呢？简单的说就是 给你n个不同的任务（n个不同的数据集，disjoint），输入呢？ 就是这一个个的任务Ti，送入模型（第一个随机化的模型或者上一个任务得到的模型）进行训练，输出呢？就是经过当前任务训练完成的模型。测试就是用最后得到的模型在当前见过的所有的任务上的准确率。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;难点&quot;&gt;&lt;strong&gt;难点&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;Catastrophic Forgetting&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;目前主流方法&quot;&gt;&lt;strong&gt;目前主流方法&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;主要分为三大类：Replay methods、Regularization-based methods、Parameter isolation methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;replay-methods&quot;&gt;&lt;strong&gt;Replay Methods&lt;/strong&gt;&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;这种方法又可以分为Rehearsal、Pseudo Rehearsal、Constrained,其中Rehearsal methods包括了ICarl、ER、SER、TEM、CoPE；Pseudo Rehearsal包括了DGR、PR、CCLUGM、LGM；Constrained包括了GEM、A-GEM、GSS。&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;regularization-based-methods&quot;&gt;&lt;strong&gt;Regularization-based methods&lt;/strong&gt;&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;这种方法又可以分为Prior focused、Data focused,其中Prior focused包括了EWC、IMM、SI、R-EWC、MAS、Riemannian、Walk；Data focused包括了LWF、LFL、EBLL、DMC。&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;parameter-isolation-methods&quot;&gt;&lt;strong&gt;Parameter isolation methods&lt;/strong&gt;&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;这种方法又可以分为Fixed Network、Dynamic Architectures，其中Fixed Network包括了PackNet、PathNet、Piggyback、HAT；Dynamic Architectures包括了PNN、Expert Gate、RCL、DAN。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;常用的数据集&quot;&gt;&lt;strong&gt;常用的数据集&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;CIFAR100数据集，100个类，每个类有600张图片，一般500张用来训练，100张用来测试；&lt;/li&gt;
  &lt;li&gt;Tiny Imagenet数据集，200个类，每个类总共有600张图片，500张用来训练，50张验证，50张测试；&lt;/li&gt;
  &lt;li&gt;Imagenet 1k数据集，1000个类，1281167张用来训练，50000张用来验证，100000用与测试。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;low--high-level&quot;&gt;&lt;strong&gt;Low &amp;amp; High level&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;Low level, 普通的SGD优化&lt;/li&gt;
  &lt;li&gt;High Level, 将所有Task的数据集放在一起进行训练&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;目前效果对比&quot;&gt;&lt;strong&gt;目前效果对比&lt;/strong&gt;&lt;/h3&gt;

&lt;h3 id=&quot;暂时写到这有空了再来补充&quot;&gt;暂时写到这，有空了再来补充&lt;/h3&gt;
</content>
 </entry>
 
 <entry>
   <title>马尔科夫链</title>
   <link href="https://chen-xw.github.io/machine-learning/2022-02-20-%E9%A9%AC%E5%B0%94%E5%8F%AF%E5%A4%AB%E9%93%BE/"/>
   <updated>2022-02-20T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/machine-learning/马尔可夫链</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;马尔可夫链的一些基础知识&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;资源&quot;&gt;&lt;strong&gt;资源&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;[百度百科]](https://baike.baidu.com/item/%E9%A9%AC%E5%B0%94%E5%8F%AF%E5%A4%AB%E9%93%BE/6171383?fromtitle=%E9%A9%AC%E5%B0%94%E7%A7%91%E5%A4%AB%E9%93%BE&amp;amp;fromid=4688932&amp;amp;fr=aladdin)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/26453269&quot;&gt;知乎&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.360doc.com/content/19/0319/08/32196507_822586429.shtml&quot;&gt;其他&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;介绍&quot;&gt;&lt;strong&gt;介绍&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;马尔科夫链是一个随机过程，未来的状态只与当前的状态有关，与之前的状态无关。&lt;/li&gt;
  &lt;li&gt;马尔科夫链中随机变量的状态随时间步的变化称为演变或转移（通过转移矩阵或转移图）。&lt;/li&gt;
  &lt;li&gt;n阶马尔科夫链，其转移矩阵是其所有转移矩阵的连续矩阵乘法。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;疑问&quot;&gt;&lt;strong&gt;疑问&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;转移矩阵最后一列的状态是什么，就是最后一个状态吗？&lt;/li&gt;
  &lt;li&gt;转移矩阵的第一列元素是当前状态？&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>推荐系统</title>
   <link href="https://chen-xw.github.io/%E6%8E%A8%E8%8D%90%E7%B3%BB%E7%BB%9F/2022-02-20-%E6%8E%A8%E8%8D%90%E7%B3%BB%E7%BB%9F/"/>
   <updated>2022-02-20T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/%E6%8E%A8%E8%8D%90%E7%B3%BB%E7%BB%9F/推荐系统</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;马尔可夫链的一些基础知识&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;资源&quot;&gt;&lt;strong&gt;资源&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/tsinghua-fib-lab/GNN-Recommender-Systems&quot;&gt;一个比较好的综述&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>基础知识</title>
   <link href="https://chen-xw.github.io/machine-learning/2021-12-21-%E4%B8%80%E4%BA%9B%E5%B0%8F%E7%9F%A5%E8%AF%86/"/>
   <updated>2021-12-21T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/machine-learning/一些小知识</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;机器学习的一些基础知识&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;资源&quot;&gt;&lt;strong&gt;资源&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html&quot;&gt;正则表达式&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.csdn.net/weixin_43786241/article/details/109154274&quot;&gt;交叉熵&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;file:///D:/Paper/OneDrive/Paper/Gradient%20norm%20for%20model%20generalization/Penalizing%20Gradient%20Norm%20for%20Efficiently%20Improving%20Generalization%20in%20Deep%20Learning.pdf&quot;&gt;梯度范数&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/2202.03599&quot;&gt;梯度范数2&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Zero-shot_learning&quot;&gt;zero-shot-learning&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/One-shot_learning&quot;&gt;one-shot-learning&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.analyticsvidhya.com/blog/2021/05/an-introduction-to-few-shot-learning/&quot;&gt;few-shot-learning&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;交叉熵&quot;&gt;&lt;strong&gt;交叉熵&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;相对熵=交叉熵-信息熵，其中&lt;/li&gt;
  &lt;li&gt;信息熵表示在结果出来之前对可能产生的信息量的期望（期望就是所有可能结果的概率乘以该对应的结果）。用来衡量事务不确定性的，信息熵越大，事务越具有不确定性。我的理解就是y*与y的不确定性。&lt;/li&gt;
  &lt;li&gt;相对熵用来表示两个概率分布的差异，当两个随机分布相同时，他们的相对熵为零，当两个随机分布的差别增大时，他们的相对熵也会增大。&lt;/li&gt;
  &lt;li&gt;交叉熵，由于在机器学习和深度学习中，样本和标签已知，那么信息熵相当于常量，此时，只需拟合交叉熵（此时交叉熵近似与相对熵）。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;梯度范数&quot;&gt;&lt;strong&gt;梯度范数&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;可以通过惩罚梯度范数来提高模型的泛化能力，原理是 penalizing the gradient norm of loss function is to encourage the optimizer to find a minimum that lies in a relatively flat neighborhood region, since such flat minima have been demonstrated to be able to lead to better model generalization than sharp ones.(becase penalize the gradient norm of loss function would motivate the loss function to have small Lipschitz constant in local. If the loss function has a smaller Lipschitz constant, it would indicate that the loss function landscape is flatter, which in consequence could lead to better model generalization)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;zeroone-shot-learning&quot;&gt;&lt;strong&gt;zero(one)-shot learning&lt;/strong&gt;&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Zero-shot learning (ZSL) is a problem setup in machine learning, where at test time, a learner observes samples from classes, which were not observed during training, and needs in order to predict the class they belong to. Zero-shot methods generally work by associating observed and non-observed classes through some form of auxiliary information, which encodes observable distinguishing properties of objects.[1] For example, given a set of images of animals to be classified, along with auxiliary textual descriptions of what animals look like, an artificial intelligence (“AI”), which has been trained to recognize horses, but has never been given a zebra, can still recognize a zebra when it also knows that zebras look like striped horses. This problem is widely studied in computer vision, natural language processing, and machine perception.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;One-shot learning is an object categorization problem, found mostly in computer vision. Whereas most machine learning-based object categorization algorithms require training on hundreds or thousands of samples, one-shot learning aims to classify objects from one, or only a few, samples.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Few-shot learning  means making classification or regression based on a very
small number of samples.   Few-shot learning is the problem of making predictions based on a limited number of samples. Few-shot learning is different from standard supervised learning. The goal of few-shot learning is not to let the model recognize the images in the training set and then generalize to the test set. Instead, the goal is to learn.   The goal of training is not to know what an elephant is and what a tiger is. Instead, the goal is to know the
similarity and difference between objects.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Multiple Instance Learning</title>
   <link href="https://chen-xw.github.io/machine-learning/2021-12-05-Multiple-Instance-Learning/"/>
   <updated>2021-12-05T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/machine-learning/Multiple Instance Learning</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;总结Mutlple Intance Learning是一个什么问题？&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;资源&quot;&gt;资源&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://nilg.ai/blog/202105/an-introduction-to-multiple-instance-learning/&quot;&gt;An Introduction to Multiple Instance Learning&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.sciencedirect.com/science/article/pii/S0004370213000581&quot;&gt;Multiple instance classification: Review, taxonomy
and comparative study&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>李保亮对研究生提出的六个建议</title>
   <link href="https://chen-xw.github.io/%E7%A7%91%E7%A0%94%E5%BB%BA%E8%AE%AE/2021-11-21-%E7%A7%91%E7%A0%94%E5%BB%BA%E8%AE%AE-%E6%9D%8E%E4%BF%9D%E4%BA%AE%E5%AF%B9%E7%A0%94%E7%A9%B6%E7%94%9F%E6%8F%90%E5%87%BA%E7%9A%84%E5%85%AD%E4%B8%AA%E5%BB%BA%E8%AE%AE/"/>
   <updated>2021-11-21T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/%E7%A7%91%E7%A0%94%E5%BB%BA%E8%AE%AE/科研建议 李保亮对研究生提出的六个建议</id>
   <content type="html">&lt;p&gt;研究生初期容易出现焦虑，不知自己的工作有没有价值，容易乱想，不知如何下手，感觉一切都在摸索。通过记录一些大牛（过来人）的经验，建议来充实一下。&lt;/p&gt;

&lt;h2 id=&quot;主题&quot;&gt;主题&lt;/h2&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;李保亮，2021年新晋最年轻院士（46岁），来自武汉大学，主要研究从事胆固醇代谢平衡调控的研究&lt;/li&gt;
  &lt;li&gt;来源 &lt;a href=&quot;https://baijiahao.baidu.com/s?id=1716997675089346232&amp;amp;wfr=spider&amp;amp;for=pc&quot;&gt;百度知识&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;文章&quot;&gt;文章&lt;/h2&gt;

&lt;hr /&gt;

&lt;p&gt;各位老师，亲爱的同学们：&lt;/p&gt;

&lt;p&gt;大家下午好！&lt;/p&gt;

&lt;p&gt;非常荣幸作为教师代表在这里发言。首先要热烈祝贺同学们来到武汉大学——这所有着126年厚重历史和人文底蕴的全国最美大学。相较于本科阶段宽口径厚基础的学习，研究生阶段才是你们科研生涯的正式开始，是你们探索自然和人类社会更多未知领域的起点。&lt;/p&gt;

&lt;p&gt;习近平总书记强调，高校应该成为使人心静下来的地方，教师要静心从教，学生要静心学习，通过研究学问提升境界，通过读书学习升华气质，以学养人、治心养性。看到你们朝气蓬勃的笑脸，我不禁想起了我的研究生生涯，我的师长、我的同学，以及我带过的学生们。&lt;/p&gt;

&lt;p&gt;1997年，我从南京大学毕业后，进入中科院上海生化所读研究生。入学后，发现作为一名研究生其实非常自由，没有老师天天盯着你，有大量自主安排的时间，生活费也很充足，于是也开始和其他同学一样热衷打游戏。&lt;/p&gt;

&lt;p&gt;但是，我很快觉得这样不行，太虚度光阴。为了把游戏彻底戒掉，我把游戏光盘扔掉了，把游戏从电脑里彻底删除，还在自己的书桌上贴了个字条：“每天看一篇文献”。我的导师看到后，非常高兴，估计从那时候起他就对我的印象很好，并在此后的科研中给予了我非常多的帮助，我们现在依然有很密切的合作。&lt;/p&gt;

&lt;p&gt;所以，我给大家的第一个建议就是：第一印象很重要，要想办法给你的导师留下一个深刻的好印象。&lt;/p&gt;

&lt;p&gt;我的研究生导师李伯良老师是个很好的老师。他给我很多自由，也很大方，让我可以探索许多课题和方向。这个阶段的训练教会了我如何来选择新的科研方向，为我将来独立做PI之后开拓新的课题特别有帮助。&lt;/p&gt;

&lt;p&gt;由于我在这个阶段坚持读了很多文献，所以我的思维和眼界就非常开阔。我的实验训练是在博士后阶段完成的，和大多数人的科学训练是反着的。&lt;/p&gt;

&lt;p&gt;所以，给大家的第二个建议就是：研究生阶段的科学训练没有固定的模式，可能也没有完美的条件，但你一定要利用现有的有利条件尽可能发展自己。&lt;/p&gt;

&lt;p&gt;在我研究生毕业前一年多，美国西南医学中心的两位大牛Mike Brown和Joe Goldstein第一次来中国，他们是1985年生物化学领域的诺贝尔奖得主，当时他们在复旦做学术报告，我穿过大半个上海去参加了这个学术会议，主动和他们交谈，正是因为研究生阶段的积累，使我有底气敢于和他们交流。&lt;/p&gt;

&lt;p&gt;此后，我获得了他们给我到美国西南医学中心做博后的offer，这是我的科学研究生涯中最重要的经历。所以，我给大家的第三个建议是：不要错过和大牛亲密接触的机会。&lt;/p&gt;

&lt;p&gt;在Brown-Goldstein实验室，我受到了最严格的科研训练，他们科学研究的品位、实验设计的严格、对高质量数据的追求等等对我影响特别深。这个阶段养成我坚持一个方向、把一个通路做透的科研习惯。&lt;/p&gt;

&lt;p&gt;3年博士后期间，我以第一作者发表了1篇MC，1篇CM，3JBC。但我的工资和去其他地方做博后的同学比较起来，一直是最低的。我很庆幸我没有因为工资高低原因选择其他的实验室，否则我不可能学习到这么多东西，不可能成长这么快。所以，我的第四个建议是不要让金钱左右你的选择，牺牲了长远的事业发展。&lt;/p&gt;

&lt;p&gt;2014年，我从中科院来到武汉大学，这里的师生在各种艰难困苦的环境中孜孜以求追求科学真理、勇攀科学高峰的精神深深感染着我。朱英国院士就是其中最杰出的代表，这位农田院士始终将习总书记“科技兴农，粮食安全要靠自己”的殷切嘱托牢记心头，年近古稀还坚持在农田、在实验室潜心研究，将自己的一生献给了祖国的粮食安全事业。在庆祝中华人民共和国成立70周年活动中，学校以他的事迹为原型，拍摄的电影即将和同学们见面，他的高尚精神将激励我们不断前行。&lt;/p&gt;

&lt;p&gt;几年来，生科院从海内外引进了院士、杰青等各类高层次人才24人次，新增分子生物学与遗传学、免疫学、微生物学三个学科进入ESI排名前1%，在Science、Cell顶尖杂志上论文发表获得重大突破，年均高水平论文20篇以上。&lt;/p&gt;

&lt;p&gt;朱玉贤院士曾自信的和我说：如今在我们实验室培养出的研究生，已经毫不逊色在美国培养的研究生！&lt;/p&gt;

&lt;p&gt;在我带的研究生中，有2个我认为他们是非常优秀的。&lt;/p&gt;

&lt;p&gt;一个特别喜欢问问题，他一直在思考课题，他经常会来给我说“宋老师，我又有一个想法”，他寒假回家回来会给我一页纸写满他的想法。&lt;/p&gt;

&lt;p&gt;另一个特别勤奋，特别能做实验，通常大多数同学会从我布置的实验中挑1-2个简单的做，而她是把我建议的实验全部都做，我们每周的组会，她的结果总是其他人的几倍。最后这两个人都发表了高水平的科研论文。&lt;/p&gt;

&lt;p&gt;给大家的第五个建议是，勤于动脑、勤于动手，找一个你身边的优秀的人，以他作为你的榜样，每一个细节你都要做到和他一样好，甚至更好。&lt;/p&gt;

&lt;p&gt;在这里，我想分享下认识过的大师——北大程和平院士。他的背景是物理和电子，他把背景知识优势在生物学领域应用到极致。他在研究生阶段最早接触到双光子显微镜，一直设想要把这个显微镜小型化。2018年，他们成功做出了2.2克的双光子显微镜，可以装在动物的头上记录脑内的神经活动。&lt;/p&gt;

&lt;p&gt;在此，给大家的第六个建议是，做科研脑子里要装着一两个非常前沿甚至是异想天开的科学问题，等将来条件成熟或者你哪天灵光一闪，你就有可能找到突破点来攻克这个难关。&lt;/p&gt;

&lt;p&gt;当今时代，是近几百年以来我们中华民族的科技水平最接近世界最高水平的时候，我们在科技方面的进步和前进速度是举世公认的，我们国家对人才和科技的重视程度也是前所未有的。9月2号，我有幸与窦贤康校长一起参加了国家杰出青年科学基金工作座谈会，切身感受到国家领导人对基础研究的重视，对年轻人才的重视。李克强总理希望“青年人才勇闯科研‘无人区’，催生更多科技‘奇果异香’”。&lt;/p&gt;

&lt;p&gt;同学们，树立理想是很容易的，但为理想而奋斗是艰难的，这里，我借用舒红兵院士的话，“真正将科研视作自己的事业和生命，可能会累，但不会觉得苦”！科学研究是不断挑战你的智力和毅力极限的过程，希望你们都能够承担起这个光荣的历史使命，为建设创新型国家作出更大贡献。&lt;/p&gt;

&lt;p&gt;谢谢大家！&lt;/p&gt;

&lt;h2 id=&quot;其他&quot;&gt;其他&lt;/h2&gt;

&lt;hr /&gt;

&lt;p&gt;他总是能给出很好的建议。王琰认为，近几年全球顶尖期刊连续发表了宋保亮团队一系列重要研究成果，是对其学术水平的最好评价。&lt;/p&gt;

&lt;p&gt;把研究课题做到极致，这既是宋保亮对自己的科研要求，也是他对每一位学生的要求。”无论是实验数据指标，还是课题完成指标，我们都要求把数据做得更准确，课题挖得更深入，在所在领域的研究更进一步。” 宋保亮说。&lt;/p&gt;

&lt;p&gt;我们刻意追求解决领域里最基本最关键的科学问题，刻意追求和人、疾病相关的科学问题，符合这些研究方向的，我们都会努力做。如果不符合，我们不会做。&lt;/p&gt;

&lt;p&gt;在宋保亮看来，做好这两个 “ 刻意追求 “，需要不断走出自己的舒适区，在研究方法和思路上不断创新，尽管过程艰难，但这样才会不断提高和突破。&lt;/p&gt;

&lt;p&gt;在博士后陈亮和博士生肖健看来，两个 “ 刻意追求 “是对生物学家和社会大众的两个受众群体的关照，秉承的是学有所用的理念，为的是让基础研究成果服务社会大众。&lt;/p&gt;

&lt;p&gt;正是基于这样的学术研究价值取向，宋保亮在20多年从事胆固醇代谢研究中，已取得一系列引领该领域的原创性成果：2015年发现细胞内胆固醇运输的新通路；2017 年发现胆固醇可以共价修饰蛋白；2018 年发现高血脂的 “ 保护基因 “…… 这些研究发现，为预防和治疗过氧化物酶体紊乱疾病、肝癌和心脑血管疾病等提供了新的可能和路径。&lt;/p&gt;

&lt;p&gt;” 宋老师工作异常勤奋，他始终把培养学生放在第一位。”武汉大学生命科学学院副教授罗婕介绍，只要宋保亮在武汉，他一定是实验室去得最早和走得最晚的一个，即使不在，他也会给同学打电话聊实验进展。&lt;/p&gt;

&lt;p&gt;为了让学生专心钻研课题，实验室专门聘请了铺细胞、饲养小鼠和清洗器皿的三位工作人员。宋保亮经常说，作为老师要多鼓励学生，包容学生试错。&lt;/p&gt;

&lt;p&gt;” 在科研上，宋老师对学生倾囊相授，甚至是其他院系的学生，只要是想做科研，宋老师都欢迎他们使用实验室，而不设任何门槛。”博士生赵南告诉记者，家庭比较困难的学生如果想做兼职，他会推荐其担任实验共享平台助理管理员或者课程助管。&lt;/p&gt;

&lt;p&gt;” 成为一个高尚的人、一个有用的人、一个有精神追求的人。”是宋保亮对研究生的寄语。&lt;/p&gt;

&lt;p&gt;一起共勉！&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>行人重识别</title>
   <link href="https://chen-xw.github.io/%E8%A1%8C%E4%BA%BA%E9%87%8D%E8%AF%86%E5%88%AB/2021-07-16-%E8%A1%8C%E4%BA%BA%E9%87%8D%E8%AF%86%E5%88%AB/"/>
   <updated>2021-07-16T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/%E8%A1%8C%E4%BA%BA%E9%87%8D%E8%AF%86%E5%88%AB/行人重识别</id>
   <content type="html">&lt;p&gt;记录一下学习行人重识别过程中比较好的资源以及自己的一些理解（后续不断补充）&lt;/p&gt;

&lt;h2 id=&quot;学习资源&quot;&gt;学习资源&lt;/h2&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.bilibili.com/video/BV1Pg4y1q7sN?p=47&quot;&gt;罗浩老师讲解视频，小白的福音&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.csdn.net/qq_30121457/article/details/108918512?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.baidujs&amp;amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.baidujs&quot;&gt;行人重识别的概述,一些分类&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.csdn.net/qq_37747189/article/details/109551330?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-7.baidujs&amp;amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-7.baidujs&quot;&gt;行人重识别的介绍，系统图特别友好&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;代码&quot;&gt;代码&lt;/h2&gt;

&lt;hr /&gt;

&lt;p&gt;代码主要参考了罗浩老师的&lt;a href=&quot;https://github.com/michuanhaohao/deep-person-reid&quot;&gt;deep-reid-baseline&lt;/a&gt;, 代码中有很多的注释，便于自己的理解&lt;/p&gt;

&lt;p&gt;###暂时写到这，有空继续补充。&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>YOLOv3训练WIDERFACE数据集</title>
   <link href="https://chen-xw.github.io/yolov3/2021-05-28-YOLOv3%E8%AE%AD%E7%BB%83WIDERFACE%E6%95%B0%E6%8D%AE%E9%9B%86-2/"/>
   <updated>2021-05-28T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/yolov3/YOLOv3训练WIDERFACE数据集-2</id>
   <content type="html">&lt;p&gt;本文主要是基于上一篇YOLOv3训练WIDERFACE数据集而补充的知识，上一篇中使用了YOLOv3的官网代码进行训练的，本文中将说明使用Tensorflow和keras进行训练,主要是基于Lilnux下，在Windows下也可以运行，只不过对于路径的问题，需要修改一下，详见文章底部。&lt;/p&gt;

&lt;h3 id=&quot;参考资源&quot;&gt;参考资源&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/YunYang1994/tensorflow-yolov3&quot;&gt;Tensorflow代码资源&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/qqwweee/keras-yolo3&quot;&gt;Keras+Tensorflow代码资源&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;代码下载&quot;&gt;代码下载&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;参考上面代码链接，下载相关代码，可以直接使用git下载，也可以下载到本地后上传到服务器上。&lt;/p&gt;

&lt;h3 id=&quot;环境要求&quot;&gt;环境要求&lt;/h3&gt;

&lt;hr /&gt;
&lt;ul&gt;
  &lt;li&gt;服务器上使用的python版本为3.6，Tensorflow版本为1.14.1，记得1.14之前版本的是下载不成功的，Keras版本为2.1.5，numpy版本为1.19.2，其他环境根据自己的需求下载即可，上面的环境是部署在服务器上的，运行代码没有问题。&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Tensorflow不推荐使用2.0版本以上的，之前使用过2.0版本以上的，报错是很难解决的，网上的解决方法特别少，过一段时间可能就好了。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Windows10下的python版本为3.7，Tensorflow-GPU版本为1.14.1，Keras版本也是2.1.5&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;由于代码中有详细的使用步骤在此就不赘述了下面记录一下运行过程中的问题&quot;&gt;由于代码中有详细的使用步骤，在此就不赘述了，下面记录一下运行过程中的问题。&lt;/h4&gt;

&lt;h3 id=&quot;权重文件&quot;&gt;权重文件&lt;/h3&gt;

&lt;hr /&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;YunYang大佬的代码中，对你下载的.weights文件（可能是yolov3.weights、darknet53.weights、darknet53.conv.74），首先进行convert_weights(或者是from_darknet_weights_to_cpkt)操作，转换成Tensorflow样式的权重文件，转换之后，你可以进行相应的操作，但是如果你想检测图片，不管是使用原先的Tensorflow样式的权重文件还是你训练出来的权重文件，都得经过freeze_graph（或者from_darknet_weights_to_pb）操作，生成pb文件，因为检测代码中使用的正是pb文件。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;qqwwee大佬的代码中，对权重文件进行convert操作后转换成了h5文件，进行相应的操作。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;保存检测结果&quot;&gt;保存检测结果&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;服务器中无法直接显示图片，你可以保存下检测结果进行查看，修改代码如下：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;YunYang大佬中的，在image_demo中修改，文档中的最后处
    &lt;pre&gt;&lt;code&gt;image = Image.fromarray(image)
image.save(&apos;./picture/output.jpg&apos;)
#image.show()
&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
  &lt;li&gt;qqwwee大佬中的，在yolo_video中第16行处
    &lt;pre&gt;&lt;code&gt; r_image = yolo.detect_image(image)
          r_image.show()
          r_image.save(&apos;./picture/output.jpg&apos;)
&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;遇到的问题&quot;&gt;遇到的问题&lt;/h3&gt;

&lt;hr /&gt;
&lt;ol&gt;
  &lt;li&gt;在运行qqwwee大佬检测视频的时候，输入一段视频，会报一个错误，具体忘了是什么错误了，需要修改的地方是视频输出路径中必须有数字，如下：
    &lt;pre&gt;&lt;code&gt;def detect_video(yolo, video_path, output_path=&quot;./output001.mp4&quot;):
&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;目前想到的问题就这么多后续继续补充&quot;&gt;目前想到的问题就这么多，后续继续补充。&lt;/h4&gt;

&lt;h4 id=&quot;如有问题欢迎交流&quot;&gt;如有问题，欢迎交流！&lt;/h4&gt;
</content>
 </entry>
 
 <entry>
   <title>YOLOv3在WIDERFACE数据集测试自己的模型</title>
   <link href="https://chen-xw.github.io/yolov3/2021-05-28-YOLOv3%E5%9C%A8WIDERFACE%E6%95%B0%E6%8D%AE%E9%9B%86%E6%B5%8B%E8%AF%95%E8%87%AA%E5%B7%B1%E7%9A%84%E6%A8%A1%E5%9E%8B/"/>
   <updated>2021-05-28T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/yolov3/YOLOv3在WIDERFACE数据集测试自己的模型</id>
   <content type="html">&lt;p&gt;本文主要是在WIDERFACE数据集上评估自己的模型（利用官网代码生成的模型），包括图片的检测、损失函数的绘制、验证集上准确率和召回率的计算以及P-R曲线的绘制。&lt;/p&gt;

&lt;head&gt;
     &lt;meta name=&quot;referrer&quot; content=&quot;no-referrer&quot; /&gt;
 &lt;/head&gt;

&lt;h3 id=&quot;参考资源&quot;&gt;参考资源&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/qq_34806812/article/details/81459982?utm_source=blogxgwz3&quot;&gt;绘制损失函数、IOU&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/tzwsg/article/details/107677231?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_v2~rank_aggregation-6-107677231.pc_agg_rank_aggregation&amp;amp;utm_term=yolov3%E7%BB%98%E5%88%B6pr%E6%9B%B2%E7%BA%BF&amp;amp;spm=1000.2123.3001.4430&quot;&gt;绘制p-r曲线&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/cgt19910923/article/details/80524173&quot;&gt;计算recall值&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/xue_csdn/article/details/95519585&quot;&gt;reval_voc_py.py代码&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/qq_32473523/article/details/107493849&quot;&gt;voc_eval.py代码&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/qq_33193309/article/details/108453810&quot;&gt;计算准确率、召回率等&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;图片的检测&quot;&gt;图片的检测&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;单图片检测部分是比较简单的一个步骤，忘记了源代码中是否有保存检测结果的代码，如果没有自己添加即可。&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;损失函数的绘制&quot;&gt;损失函数的绘制&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;这部分的前提应该是你有每次迭代过程的记录文件，可以是nohup命令得出的nohup.out文件，也可以是其他形式的文件。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;首先利用extract_log.py文件对nohup.out文件进行处理，取出每次迭代过程的记录文件，去除其他没有用的信息，代码借鉴了参考资源中的代码。运行成功后，会得到下图中的两个文件（我生成了多次）。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/损失函数.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# coding=utf-8
# 该文件用来提取训练log，去除不可解析的log后使log文件格式化，生成新的log文件供可视化工具绘图
 
import inspect
import os
import random
import sys
def extract_log(log_file,new_log_file,key_word):
    with open(log_file, &apos;r&apos;) as f:
      with open(new_log_file, &apos;w&apos;) as train_log:
  #f = open(log_file)
    #train_log = open(new_log_file, &apos;w&apos;)
        for line in f:
    # 去除多gpu的同步log
          if &apos;Syncing&apos; in line:
            continue
    # 去除除零错误的log
          if &apos;nan&apos; in line:
            continue
          if key_word in line:
            train_log.write(line)
    f.close()
    train_log.close()
 
extract_log(&apos;train_yolov3.log&apos;,&apos;train_log_loss.txt&apos;,&apos;images&apos;)
extract_log(&apos;train_yolov3.log&apos;,&apos;train_log_iou.txt&apos;,&apos;IOU&apos;)
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;运行train_loss_visualization.py文件，绘制loss函数图像，代码也是参考资源中的，此时就会出现你所需要的图像。&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#%matplotlib inline
 
lines =50000    #改为自己生成的train_log_loss.txt中的行数
result = pd.read_csv(&apos;train_log_loss.txt&apos;, skiprows=[x for x in range(lines) if ((x%10!=9) |(x&amp;lt;1000))] ,error_bad_lines=False, names=[&apos;loss&apos;, &apos;avg&apos;, &apos;rate&apos;, &apos;seconds&apos;, &apos;images&apos;])
result.head()
 
result[&apos;loss&apos;]=result[&apos;loss&apos;].str.split(&apos; &apos;).str.get(1)
result[&apos;avg&apos;]=result[&apos;avg&apos;].str.split(&apos; &apos;).str.get(1)
result[&apos;rate&apos;]=result[&apos;rate&apos;].str.split(&apos; &apos;).str.get(1)
result[&apos;seconds&apos;]=result[&apos;seconds&apos;].str.split(&apos; &apos;).str.get(1)
result[&apos;images&apos;]=result[&apos;images&apos;].str.split(&apos; &apos;).str.get(1)
result.head()
result.tail()
 
# print(result.head())
# print(result.tail())
# print(result.dtypes)
 
print(result[&apos;loss&apos;])
print(result[&apos;avg&apos;])
print(result[&apos;rate&apos;])
print(result[&apos;seconds&apos;])
print(result[&apos;images&apos;])
 
result[&apos;loss&apos;]=pd.to_numeric(result[&apos;loss&apos;])
result[&apos;avg&apos;]=pd.to_numeric(result[&apos;avg&apos;])
result[&apos;rate&apos;]=pd.to_numeric(result[&apos;rate&apos;])
result[&apos;seconds&apos;]=pd.to_numeric(result[&apos;seconds&apos;])
result[&apos;images&apos;]=pd.to_numeric(result[&apos;images&apos;])
result.dtypes
 
 
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(result[&apos;avg&apos;].values,label=&apos;avg_loss&apos;)
# ax.plot(result[&apos;loss&apos;].values,label=&apos;loss&apos;)
ax.legend(loc=&apos;best&apos;)  #图列自适应位置
ax.set_title(&apos;The loss curves&apos;)
ax.set_xlabel(&apos;batches&apos;)
fig.savefig(&apos;avg_loss&apos;)
# fig.savefig(&apos;loss&apos;)

&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id=&quot;绘制损失函数的图像就上述两个操作同理绘制iou图像也是类似的只需要运行参考链接中的train_iou_visualizationpy文件即可&quot;&gt;绘制损失函数的图像就上述两个操作，同理，绘制IOU图像也是类似的，只需要运行参考链接中的train_IOU_visualization.py文件即可。&lt;/h4&gt;

&lt;h3 id=&quot;使用fast-r-cnn代码中的方法计算准确率&quot;&gt;使用Fast R-CNN代码中的方法计算准确率&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;这是我第一个使用的计算准确率的方法，虽然处理预测文件的时候，我去除了非人脸信息的检测结果，也设置了相应的阈值，但是很奇怪的是计算出的准确率离奇的低。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;从上述参考资源处下载voc_eval.py和reval_voc_py3.py文件&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;利用官网代码对验证集的图片进行检测，默认生成comp4_det_test_face.txt(在results文件夹下)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;./darknet detector valid cfg/voc.data cfg/yolov3-voc.cfg backup/yolov3-voc_final.weights -out car.txt -gpu 0 -thresh .5
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;运行reval_voc_py3.py代码，会得到各个类别的AP值，以及mAP值。&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;每次检测后都会在voc2007数据集文件夹下生成一个annotation的文件，需要再次检测时，得把它删除，不然报错。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;pre&gt;&lt;code&gt;python3.6 reval_voc_py3.py  --voc_dir /home/amax/cxw/darknet-master/voc/VOCdevkit --year 2007 --image_set test --classes data/voc-my.names  Testforpr
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;绘制p-r曲线&quot;&gt;绘制p-r曲线&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;上一步骤中，已经求得了准确率和召回率的值，并保存在了pkl文件中，绘制p-r曲线时，只需要加载上这个文件即可。&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# coding=utf-8
import _pickle as cPickle
import matplotlib.pyplot as plt

plt.rcParams[&apos;font.sans-serif&apos;] = [u&apos;NSimSun&apos;]
plt.rcParams[&apos;axes.unicode_minus&apos;] = False
fr = open(&apos;tower_pr.pkl&apos;, &apos;rb&apos;)  # 这里open中第一个参数需要修改成自己生产的pkl文件
inf = cPickle.load(fr)
fr.close()

# fbad = open(&apos;tower_pr.pkl&apos;,&apos;rb&apos;)#这里open中第一个参数需要修改成自己生产的pkl文件
# inf_bad = cPickle.load(fbad)
# fbad.close()


x = inf[&apos;rec&apos;]
y = inf[&apos;prec&apos;]
plt.figure()
plt.xlabel(&apos;召回率&apos;, size=15)
plt.ylabel(&apos;精确率&apos;, size=15)
plt.xticks(fontproperties=&apos;Times New Roman&apos;, size=14)
plt.yticks(fontproperties=&apos;Times New Roman&apos;, size=14)

plt.plot(x, y)

plt.savefig(&quot;PR曲线.svg&quot;, bbox_inches=&apos;tight&apos;)  # plt保存需要在show之前
plt.show()

print(&apos;AP：&apos;, inf[&apos;ap&apos;])

&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;利用一个更直观的方法计算ap值&quot;&gt;利用一个更直观的方法计算AP值&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;AP值的计算无非就是将验证集的检测结果同原数据进行对比，设置相应的阈值，计算数据即可。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;首先是要对验证集上的检测结果进行处理，将每幅图片检出的人脸保存到每一个txt文件中，有多少张图片就会有多少txt文件。代码如下：&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/test结果.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;import os
 
# txt_file为配置文件.data中的valid
txt_file = &apos;/home/amax/cxw/darknet-master/scripts/2007_val.txt&apos;
f = open(txt_file)
lines = f.readlines()
for line in lines:
    line = line.split(&apos;/&apos;)[-1][0:-5]
    # test_out_file 为转换后保存的结果地址
    test_out_file = &apos;/home/amax/cxw/darknet-master/testresults&apos;
    # 下面3个with需要自己的修改，修改成自己对应的类别
    with open(os.path.join(test_out_file , line + &apos;.txt&apos;), &quot;a&quot;) as new_f:
        f1 = open(&apos;/home/amax/cxw/darknet-master/results/comp4_det_test_face.txt&apos;, &apos;r&apos;)
        f1_lines = f1.readlines()
        for f1_line in f1_lines:
            f1_line = f1_line.split()
            if line == f1_line[0]:
                new_f.write(&quot;%s %s %s %s %s %s\n&quot; % (&apos;smoke&apos;, f1_line[1], f1_line[2], f1_line[3], f1_line[4], f1_line[5]))
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;同理对你原先的标注数据集进行相应的处理，也处理成上述的格式，便于比较，注意其中的Labels文件是经过归一化处理之后的文件了，要进行相应的复原操作。&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;import os
from PIL import Image
import numpy as np
# label_img为数据集的labels地址，img_path为数据集images的地址
label_img = &apos;/home/amax/cxw/darknet-master/voc/VOCdevkit/VOC2007/labels&apos;
img_path = &apos;/home/amax/cxw/darknet-master/voc/VOCdevkit/VOC2007/JPEGImages&apos;
classes = {
    0:&apos;smoke&apos;,
    1:&apos;white&apos;,
    2:&apos;red&apos;
}
for line in lines:
    line = line.split(&apos;/&apos;)[-1][0:-5] + &apos;.txt&apos;
    txt = label_img + line
    img = np.array(Image.open(img_path + line.split(&apos;/&apos;)[-1][0:-4] + &apos;.jpg&apos;))
    sh, sw = img.shape[0], img.shape[1]
    # gt_out_file为转换后的地址
    gt_out_file = &apos;/home/amax/cxw/darknet-master/yoloresults&apos;
    with open(os.path.join(gt_out_file , line ), &quot;a&quot;) as new_f:
        f1 = open(txt)
        f1_lines = f1.readlines()
        for f1_line in f1_lines:
            f1_line = f1_line.split()
            x = float(f1_line[1]) * sw
            y = float(f1_line[2]) * sh
            w = float(f1_line[3]) * sw
            h = float(f1_line[4]) * sh
            xmin = x+1-w/2
            ymin = y+1-h/2
            xmax = x+1+w/2
            ymax = y+1+h/2
            new_f.write(&quot;%s %s %s %s %s\n&quot; % (classes[int(f1_line[0])], xmin ,ymin,xmax,ymax))

&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;执行如下代码，可以计算出标注人脸框、检测出的总人脸框、检测正确的人脸框和检测错误的人脸框，可以根据自己的需要设置相应的阈值，所谓的阈值就是利用交并比判定是否是人脸框的标准，大于阈值的判定为人脸框，否则不是人脸框。&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;import os
 
 
def compute_IOU(rec1, rec2):
    &quot;&quot;&quot;
    计算两个矩形框的交并比。
    :param rec1: (x0,y0,x1,y1)      (x0,y0)代表矩形左上的顶点，（x1,y1）代表矩形右下的顶点。下同。
    :param rec2: (x0,y0,x1,y1)
    :return: 交并比IOU.
    &quot;&quot;&quot;
    left_column_max = max(rec1[0], rec2[0])
    right_column_min = min(rec1[2], rec2[2])
    up_row_max = max(rec1[1], rec2[1])
    down_row_min = min(rec1[3], rec2[3])
    # 两矩形无相交区域的情况
    if left_column_max &amp;gt;= right_column_min or down_row_min &amp;lt;= up_row_max:
        return 0
    # 两矩形有相交区域的情况
    else:
        S1 = (rec1[2] - rec1[0]) * (rec1[3] - rec1[1])
        S2 = (rec2[2] - rec2[0]) * (rec2[3] - rec2[1])
        S_cross = (down_row_min - up_row_max) * (right_column_min - left_column_max)
        return S_cross / (S1 + S2 - S_cross)
 
# gt为yolo数据转换后的地址
gt = &apos;/home/amax/cxw/darknet-master/yoloresults/&apos;
# test为检测结果转换后的地址
test = &apos;/home/amax/cxw/darknet-master/testresults/&apos;
# count_gt为标注的所有数据框
count_gt = {
 
}
# count_test为检测的所有数据框
count_test = {
 
}
# count_yes_test为检测正确的数据框
count_yes_test = {
 
}
# count_no_test为检测错误的数据框
count_no_test = {
 
}
# 计数
for gt_ in os.listdir(gt):
    txt = gt + gt_
    f = open(txt)
    lines = f.readlines()
    for line in lines:
        line = line.split()
        name = line[0]
        if name not in count_gt:
            count_gt[name] = 0
        count_gt[name] += 1
for test_ in os.listdir(test):
    txt = test + test_
    f = open(txt)
    lines = f.readlines()
    for line in lines:
        line = line.split()
        name = line[0]
        if name not in count_test:
            count_test[name] = 0
        count_test[name] += 1
# 下面主要思想：遍历test结果，再遍历对应gt的结果，如果两个框的iou大于一定的阙址并且类别相同，视为正确
for test_ in os.listdir(test):
    f_test_txt = test + test_
    f_test = open(f_test_txt)
    f_test_lines = f_test.readlines()
    for f_test_line in f_test_lines:
        f_test_line = f_test_line.split()
        f_gt_txt = gt + test_
        f_gt = open(f_gt_txt)
        f_gt_lines = f_gt.readlines()
        flag = 1
        for f_gt_line in f_gt_lines:
            f_gt_line = f_gt_line.split()
            IOU = compute_IOU([float(f_gt_line[1]), float(f_gt_line[2]), float(f_gt_line[3]), float(f_gt_line[4])],
                              [float(f_test_line[2]), float(f_test_line[3]), float(f_test_line[4]), float(f_test_line[5])])
            if f_gt_line[0] == f_test_line[0] and IOU &amp;gt;= 0.5 and float(f_test_line[1]) &amp;gt;= 0.3:
                flag = 0
                if f_test_line[0] not in count_yes_test:
                    count_yes_test[f_test_line[0]] = 0
                count_yes_test[f_test_line[0]] += 1
 
        if flag == 1:
            if f_test_line[0] not in count_no_test:
                count_no_test[f_test_line[0]] = 0
            count_no_test[f_test_line[0]] += 1
# 有以下4个结果，就可以计算相关指标了
print(count_gt)
print(count_test)
print(count_yes_test)
print(count_no_test)

&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id=&quot;注意修改文件的路径第三部分介绍的计算准确率的方法比利用fast-r-cnn的方法简单没有详细的研究第二部分的方法有时间再去补充&quot;&gt;注意修改文件的路径，第三部分介绍的计算准确率的方法比利用Fast R-CNN的方法简单，没有详细的研究第二部分的方法，有时间再去补充。&lt;/h4&gt;

&lt;h4 id=&quot;如有问题欢迎交流&quot;&gt;如有问题，欢迎交流！&lt;/h4&gt;

</content>
 </entry>
 
 <entry>
   <title>YOLOv3训练WIDERFACE数据集</title>
   <link href="https://chen-xw.github.io/yolov3/2021-05-27-YOLOv3%E8%AE%AD%E7%BB%83WIDERFACE%E6%95%B0%E6%8D%AE%E9%9B%86/"/>
   <updated>2021-05-27T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/yolov3/YOLOv3训练WIDERFACE数据集</id>
   <content type="html">&lt;p&gt;本文主要描写了使用官网给出的YOLOv3目标检测模型（也就是使用darknet)，在Linux下对WIDERFACE数据集进行训练，以此来实现人脸检测的任务。&lt;/p&gt;

&lt;head&gt;
     &lt;meta name=&quot;referrer&quot; content=&quot;no-referrer&quot; /&gt;
 &lt;/head&gt;

&lt;h3 id=&quot;参考链接&quot;&gt;参考链接&lt;/h3&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://www.cnblogs.com/Assist/p/11091501.html&quot;&gt;https://www.cnblogs.com/Assist/p/11091501.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/lilai619/article/details/79695109&quot;&gt;https://blog.csdn.net/lilai619/article/details/79695109&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/sunqiande88/article/details/102414883&quot;&gt;https://blog.csdn.net/sunqiande88/article/details/102414883&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;其他资源&quot;&gt;其他资源&lt;/h3&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://pjreddie.com/darknet/yolo/&quot;&gt;YOLOv3官网&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/pjreddie/darknet&quot;&gt;YOLOv3源码&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://pjreddie.com/media/files/papers/YOLOv3.pdf&quot;&gt;YOLOv3论文&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;算法下载及使用&quot;&gt;算法下载及使用&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;YOLOv3源码既可以在Linux下使用，也可以在Windows下使用，Windows的使用可以参考链接中的使用方法，本文是基于Linux下使用的。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;首先从YOLOv3源码处，下载源码，参考上面其他资源处，可以使用git下载，也可以在本地下载后，上传到服务器中。下载后会出现下面的各个文件：&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/代码源文件.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;下载后，需要进行make操作，修改Makefile文件,如下图：&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/makefile1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;首先修改第一处，如上图，可以修改GPU=1，表示使用GPU，CUDNN=1，表示使用CUDN加速，下面的同理，我在运行时，只使用了GPU=1，速度已经可以达到我的要求。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;修改第二处，NVCC的位置，将后面的nvcc修改成自己nvcc在服务器上的位置,如下图&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/makefile2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;目前为止算法已经可以在本地运行可以输入darknet观察输出结果如果输出为下图证明此部分工作已经完成&quot;&gt;目前为止，算法已经可以在本地运行，可以输入./darknet，观察输出结果，如果输出为下图，证明此部分工作已经完成。&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/检验darknet运行是否成功.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;数据集进行处理生成训练和验证的图片路径&quot;&gt;数据集进行处理，生成训练和验证的图片路径&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;下载的YOLOv3代码中包含了voc_label.py文件，这个文件就是用于生成训练图片路径的代码，我修改后的代码如下，修改的地方主要就是数据集的路径，总共修改了8处，最后一行代码也可以根据自己的需求进行修改。&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join

sets=[ (&apos;2007&apos;, &apos;train&apos;), (&apos;2007&apos;, &apos;val&apos;)]   #修改处1

classes = [&quot;face&quot;]                           #修改处2


def convert(size, box):
    dw = 1./(size[0])
    dh = 1./(size[1])
    x = (box[0] + box[1])/2.0 - 1
    y = (box[2] + box[3])/2.0 - 1
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

def convert_annotation(year, image_id):
    in_file = open(&apos;/home/amax/cxw/tensorflow-yolov3-master/voc/train/VOCdevkit/VOC%s/Annotations/%s.xml&apos;%(year, image_id))   #修改处3
    out_file = open(&apos;/home/amax/cxw/tensorflow-yolov3-master/voc/train/VOCdevkit/VOC%s/labels/%s.txt&apos;%(year, image_id), &apos;w&apos;)  #修改处4
    tree=ET.parse(in_file)
    root = tree.getroot()
    size = root.find(&apos;size&apos;)
    w = int(size.find(&apos;width&apos;).text)
    h = int(size.find(&apos;height&apos;).text)

    for obj in root.iter(&apos;object&apos;):
        difficult = obj.find(&apos;difficult&apos;).text
        cls = obj.find(&apos;name&apos;).text
        if cls not in classes or int(difficult)==1:
            continue
        cls_id = classes.index(cls)
        xmlbox = obj.find(&apos;bndbox&apos;)
        b = (float(xmlbox.find(&apos;xmin&apos;).text), float(xmlbox.find(&apos;xmax&apos;).text), float(xmlbox.find(&apos;ymin&apos;).text), float(xmlbox.find(&apos;ymax&apos;).text))
        bb = convert((w,h), b)
        out_file.write(str(cls_id) + &quot; &quot; + &quot; &quot;.join([str(a) for a in bb]) + &apos;\n&apos;)

wd = &quot;/home/amax/cxw/tensorflow-yolov3-master/voc/train&quot;        #修改处5

for year, image_set in sets:
    if not os.path.exists(&apos;/home/amax/cxw/tensorflow-yolov3-master/voc/train/VOCdevkit/VOC%s/labels/&apos;%(year)):                      #修改处6
        os.makedirs(&apos;/home/amax/cxw/tensorflow-yolov3-master/voc/train/VOCdevkit/VOC%s/labels/&apos;%(year))                             #修改处7
    image_ids = open(&apos;/home/amax/cxw/tensorflow-yolov3-master/voc/train/VOCdevkit/VOC%s/ImageSets/Main/%s.txt&apos;%(year, image_set)).read().strip().split()    #修改处8
    list_file = open(&apos;%s_%s.txt&apos;%(year, image_set), &apos;w&apos;)
    for image_id in image_ids:
        list_file.write(&apos;%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n&apos;%(wd, year, image_id))
        convert_annotation(year, image_id)
    list_file.close()

os.system(&quot;cat 2007_train.txt 2007_val.txt &amp;gt; train.txt&quot;)

&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
  &lt;li&gt;执行成功之后，可以看到生成了如下图的三个文件。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/数据集的处理1.png&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/数据集的处理2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;使用k均值聚类算法得到自己的anchors&quot;&gt;使用K均值聚类算法得到自己的anchors&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;这一部分你可能觉得很突兀，但这是为了下一章节修改anchors需要的工作，这个部分你可以先跳过，当需要的时候再回到这。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;下载k-means算法或者k-means++算法对WIDERFACE数据集进行聚类，由于时间的关系，忘记是从哪下载的代码了，应该是下面的代码，记得有一个代码是不成功的（但愿不是这一个）。&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;
import numpy as np

class YOLO_Kmeans:

    def __init__(self, cluster_number, filename):
        self.cluster_number = cluster_number
        self.filename = &quot;voc_train.txt&quot;

    def iou(self, boxes, clusters):  # 1 box -&amp;gt; k clusters
        n = boxes.shape[0]
        k = self.cluster_number

        box_area = boxes[:, 0] * boxes[:, 1]
        box_area = box_area.repeat(k)
        box_area = np.reshape(box_area, (n, k))

        cluster_area = clusters[:, 0] * clusters[:, 1]
        cluster_area = np.tile(cluster_area, [1, n])
        cluster_area = np.reshape(cluster_area, (n, k))

        box_w_matrix = np.reshape(boxes[:, 0].repeat(k), (n, k))
        cluster_w_matrix = np.reshape(np.tile(clusters[:, 0], (1, n)), (n, k))
        min_w_matrix = np.minimum(cluster_w_matrix, box_w_matrix)

        box_h_matrix = np.reshape(boxes[:, 1].repeat(k), (n, k))
        cluster_h_matrix = np.reshape(np.tile(clusters[:, 1], (1, n)), (n, k))
        min_h_matrix = np.minimum(cluster_h_matrix, box_h_matrix)
        inter_area = np.multiply(min_w_matrix, min_h_matrix)

        result = inter_area / (box_area + cluster_area - inter_area)
        return result

    def avg_iou(self, boxes, clusters):
        accuracy = np.mean([np.max(self.iou(boxes, clusters), axis=1)])
        return accuracy

    def kmeans(self, boxes, k, dist=np.median):
        box_number = boxes.shape[0]
        distances = np.empty((box_number, k))
        last_nearest = np.zeros((box_number,))
        np.random.seed()
        clusters = boxes[np.random.choice(
            box_number, k, replace=False)]  # init k clusters
        while True:

            distances = 1 - self.iou(boxes, clusters)

            current_nearest = np.argmin(distances, axis=1)
            if (last_nearest == current_nearest).all():
                break  # clusters won&apos;t change
            for cluster in range(k):
                clusters[cluster] = dist(  # update clusters
                    boxes[current_nearest == cluster], axis=0)

            last_nearest = current_nearest

        return clusters

    def result2txt(self, data):
        f = open(&quot;yolo_anchors.txt&quot;, &apos;w&apos;)
        row = np.shape(data)[0]
        for i in range(row):
            if i == 0:
                x_y = &quot;%d,%d&quot; % (data[i][0], data[i][1])
            else:
                x_y = &quot;, %d,%d&quot; % (data[i][0], data[i][1])
            f.write(x_y)
        f.close()

    def txt2boxes(self):
        f = open(self.filename, &apos;r&apos;)
        dataSet = []
        for line in f:
            infos = line.split(&quot; &quot;)
            length = len(infos)
            for i in range(1, length):
                width = int(infos[i].split(&quot;,&quot;)[2]) - \
                    int(infos[i].split(&quot;,&quot;)[0])
                height = int(infos[i].split(&quot;,&quot;)[3]) - \
                    int(infos[i].split(&quot;,&quot;)[1])
                dataSet.append([width, height])
        result = np.array(dataSet)
        f.close()
        return result

    def txt2clusters(self):
        all_boxes = self.txt2boxes()
        result = self.kmeans(all_boxes, k=self.cluster_number)
        result = result[np.lexsort(result.T[0, None])]
        self.result2txt(result)
        print(&quot;K anchors:\n {}&quot;.format(result))
        print(&quot;Accuracy: {:.2f}%&quot;.format(
            self.avg_iou(all_boxes, result) * 100))


if __name__ == &quot;__main__&quot;:
    cluster_number = 9
    filename = &quot;voc_train.txt&quot;
    kmeans = YOLO_Kmeans(cluster_number, filename)
    kmeans.txt2clusters()
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;需要修改一下自己的filename，改成自己的路径，结果会输出九组anchors，同时还会输出一个概率，一般是70%左右（记得）。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;修改配置文件&quot;&gt;修改配置文件&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;此部分需要修改.data、.names、.cfg等文件，修改成适合单目标检测（face），文件中的random属性可以设置为0（显存比较小的时候，此部分位于三个[yolo]处，下文）&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;修改names文件
    &lt;ul&gt;
      &lt;li&gt;names文件处于data文件夹下，可以新建一个names文件，里面内容只写入face一个属性，如下图：&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/names文件.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;修改data文件
    &lt;ul&gt;
      &lt;li&gt;data文件处于cfg文件下，可以新建一个data文件，打开后如下图：&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/修改data文件.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- 修改classes=1，只进行人脸检测
- 修改train和valid路径，本文上一步生成的三个文件中的前两个的路径
- 修改names路径，本章节第一小步修改的names文件路径
- backup属性可以不用修改，它的用途忘记了，健忘
&lt;/code&gt;&lt;/pre&gt;

&lt;ol&gt;
  &lt;li&gt;修改cfg文件
    &lt;ul&gt;
      &lt;li&gt;修改batch、subdivisions属性，分为test和train两部分，由于是进行训练，因此修改如下：&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/cfg文件.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt; 其中batch需要根据自己电脑的配置进行修改，服务器一般可以使用64，32，自己的电脑可能要低一些，16，32都可，根据自己的需求,subdivisions也得根据自己的电脑修改，如果太高，会严重消耗CPU资源。
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;修改learning_rate,学习率可以使用多种策略，（可以上网百度，查看各种策略的区别），如下图&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/学习率.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt; 此部分使用了step策略，初始学习率设置为0.001，40000步后学习率降低为0.0001，45000步后学习率降低为0.00001，可以根据自己的需求进行调整，
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;修改anchors，classes和filters属性，此部分总共需要修改三处，每处三个属性，从文件的最后面向前，三部分[yolo]处，如下图&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/最后三处.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt; 前面K均值聚类算法得到的九组anchors就是用于此部分的，修改成先前得到的九组anchors；修改classes为1，filters为18（（1+5）*3）。
&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id=&quot;前面的准备工作已经结束下一步进行数据集的训练&quot;&gt;前面的准备工作已经结束，下一步进行数据集的训练。&lt;/h4&gt;

&lt;h3 id=&quot;下载预训练权重&quot;&gt;下载预训练权重&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;预训练权重可以使用darknet53的权重，此权重已经包含了最主要的网络结构，便于模型的扩展，并且文件还小。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://pjreddie.com/media/files/darknet53.conv.74&quot;&gt;下载链接&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;进行数据集的训练&quot;&gt;进行数据集的训练&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;对数据集进行训练，可以在后台执行，使用nohup等命令。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;使用官网命令如下,我使用的服务器上有两块GPU，因此为0，1
    &lt;pre&gt;&lt;code&gt;./darknet detector train cfg/voc.data cfg/yolov3-voc.cfg darknet53.conv.74 -gpus 0,1
&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
  &lt;li&gt;查看nohup.out文件，查看中间过程，如下图：&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/nohup.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;如果训练到中间，因其他原因导致服务器意外关闭，可以加载上已经训练出的模型权重，重新训练，如下代码
    &lt;pre&gt;&lt;code&gt;./darknet detector train cfg/voc-my.data cfg/yolov3-voc-my.cfg backup/yolov3-voc-100000.weights -gpus 0,1
&lt;/code&gt;&lt;/pre&gt;
    &lt;blockquote&gt;
      &lt;p&gt;其中，训练出的模型权重保存在backup文件夹下。&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;使用nohup命令如下
    &lt;pre&gt;&lt;code&gt;nohup ./darknet detector train cfg/voc.data cfg/yolov3-voc.cfg darknet53.conv.74 -gpus 0,1 &amp;amp;
&lt;/code&gt;&lt;/pre&gt;
    &lt;blockquote&gt;
      &lt;p&gt;如果出现没有权限，把错误百度，有解决方法。&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;到目前为止训练的过程已经结束当你理解yolov3模型和训练过程的参数的含义后下一步就是常说的炼药的过程了修改自己的学习率batch等参数让自己的模型更精确&quot;&gt;到目前为止，训练的过程已经结束，当你理解YOLOv3模型和训练过程的参数的含义后，下一步就是常说的“炼药”的过程了，修改自己的学习率，batch等参数让自己的模型更精确。&lt;/h4&gt;

&lt;h3 id=&quot;可能遇到的错误&quot;&gt;可能遇到的错误&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;其他错误，一般都能在网上百度到，博客的连接中也写明了大部分的错误，如果make阶段出现错误，建议只开GPU=1，我使用过程中，由于是老师的服务器，没有大部分的权限，报了很多错误，因此只使用了GPU=1.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;你可能出现./darknet: error while loading shared libraries: libcudart.so.10.0: cannot open shared object file: No such file or directory这个错误，解决方法如下：
    &lt;pre&gt;&lt;code&gt;export LD_LIBRARY_PATH=/usr/local/cuda/lib64 &amp;amp;&amp;amp; sudo ldconfig
&lt;/code&gt;&lt;/pre&gt;
    &lt;blockquote&gt;
      &lt;p&gt;通过输入密码后，成功解决了上述错误。&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;如有问题欢迎交流&quot;&gt;如有问题，欢迎交流！&lt;/h4&gt;
</content>
 </entry>
 
 <entry>
   <title>WIDERFACE数据集转化为VOC格式</title>
   <link href="https://chen-xw.github.io/yolov3/2021-05-26-WIDERFACE%E6%95%B0%E6%8D%AE%E9%9B%86%E8%BD%AC%E4%B8%BAVOC%E6%A0%BC%E5%BC%8F/"/>
   <updated>2021-05-26T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/yolov3/WIDERFACE数据集转为VOC格式</id>
   <content type="html">&lt;p&gt;本文是对WIDERFACE数据集进行预处理，生成YOLOv3代码输入要求的COCO或者VOC格式，在此将其转化成了VOC格式，总体来说，此部分比较简单。&lt;/p&gt;

&lt;head&gt;
     &lt;meta name=&quot;referrer&quot; content=&quot;no-referrer&quot; /&gt;
 &lt;/head&gt;

&lt;h3 id=&quot;参考链接&quot;&gt;参考链接&lt;/h3&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/sunqiande88/article/details/102414883&quot;&gt;https://blog.csdn.net/sunqiande88/article/details/102414883&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;下载widerface数据集&quot;&gt;下载WIDERFACE数据集&lt;/h3&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;http://shuoyang1213.me/WIDERFACE/&quot;&gt;数据集官网下载&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;下载数据集可以从上述官网中下载，也可以直接在网上搜索，可以找到许多百度网盘分享的，下载后可以看到如下内容：&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/下载后的数据集.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;其中WIDER_train为训练集，WIDER_test为测试集，WIDER_val为验证集，wider_face_split包含了人脸框等信息。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;训练集验证集转换为voc格式&quot;&gt;训练集、验证集转换为VOC格式&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;借鉴网上的代码将WIDERFACE数据集转换为VOC格式&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# -*- coding: utf-8 -*-

import shutil
import random
import os
import string
from skimage import io

headstr = &quot;&quot;&quot;\
&amp;lt;annotation&amp;gt;
    &amp;lt;folder&amp;gt;VOC2012&amp;lt;/folder&amp;gt;
    &amp;lt;filename&amp;gt;%06d.jpg&amp;lt;/filename&amp;gt;
    &amp;lt;source&amp;gt;
        &amp;lt;database&amp;gt;My Database&amp;lt;/database&amp;gt;
        &amp;lt;annotation&amp;gt;PASCAL VOC2012&amp;lt;/annotation&amp;gt;
        &amp;lt;image&amp;gt;flickr&amp;lt;/image&amp;gt;
        &amp;lt;flickrid&amp;gt;NULL&amp;lt;/flickrid&amp;gt;
    &amp;lt;/source&amp;gt;
    &amp;lt;owner&amp;gt;
        &amp;lt;flickrid&amp;gt;NULL&amp;lt;/flickrid&amp;gt;
        &amp;lt;name&amp;gt;company&amp;lt;/name&amp;gt;
    &amp;lt;/owner&amp;gt;
    &amp;lt;size&amp;gt;
        &amp;lt;width&amp;gt;%d&amp;lt;/width&amp;gt;
        &amp;lt;height&amp;gt;%d&amp;lt;/height&amp;gt;
        &amp;lt;depth&amp;gt;%d&amp;lt;/depth&amp;gt;
    &amp;lt;/size&amp;gt;
    &amp;lt;segmented&amp;gt;0&amp;lt;/segmented&amp;gt;
&quot;&quot;&quot;
objstr = &quot;&quot;&quot;\
    &amp;lt;object&amp;gt;
        &amp;lt;name&amp;gt;%s&amp;lt;/name&amp;gt;
        &amp;lt;pose&amp;gt;Unspecified&amp;lt;/pose&amp;gt;
        &amp;lt;truncated&amp;gt;0&amp;lt;/truncated&amp;gt;
        &amp;lt;difficult&amp;gt;0&amp;lt;/difficult&amp;gt;
        &amp;lt;bndbox&amp;gt;
            &amp;lt;xmin&amp;gt;%d&amp;lt;/xmin&amp;gt;
            &amp;lt;ymin&amp;gt;%d&amp;lt;/ymin&amp;gt;
            &amp;lt;xmax&amp;gt;%d&amp;lt;/xmax&amp;gt;
            &amp;lt;ymax&amp;gt;%d&amp;lt;/ymax&amp;gt;
        &amp;lt;/bndbox&amp;gt;
    &amp;lt;/object&amp;gt;
&quot;&quot;&quot;

tailstr = &apos;&apos;&apos;\
&amp;lt;/annotation&amp;gt;
&apos;&apos;&apos;


def writexml(idx, head, bbxes, tail):
    filename = (&quot;Annotations/%06d.xml&quot; % (idx))
    f = open(filename, &quot;w&quot;)
    f.write(head)
    for bbx in bbxes:
        f.write(objstr % (&apos;face&apos;, bbx[0], bbx[1], bbx[0] + bbx[2], bbx[1] + bbx[3]))
    f.write(tail)
    f.close()


def clear_dir():
    if shutil.os.path.exists((&apos;Annotations&apos;)):
        shutil.rmtree((&apos;Annotations&apos;))
    if shutil.os.path.exists((&apos;ImageSets&apos;)):
        shutil.rmtree((&apos;ImageSets&apos;))
    if shutil.os.path.exists((&apos;JPEGImages&apos;)):
        shutil.rmtree((&apos;JPEGImages&apos;))

    shutil.os.mkdir((&apos;Annotations&apos;))
    shutil.os.makedirs((&apos;ImageSets/Main&apos;))
    shutil.os.mkdir((&apos;JPEGImages&apos;))


def excute_datasets(idx, datatype):

    f = open((&apos;ImageSets/Main/&apos; + datatype + &apos;.txt&apos;), &apos;a&apos;)
    f_bbx = open((&apos;wider_face_split/wider_face_&apos; + datatype + &apos;_bbx_gt.txt&apos;), &apos;r&apos;)

    while True:
        filename = f_bbx.readline().strip(&apos;\n&apos;)

        if not filename:
            break
        im = io.imread((&apos;WIDER_&apos; + datatype + &apos;/images/&apos; + filename))
        head = headstr % (idx, im.shape[1], im.shape[0], im.shape[2])
        nums = f_bbx.readline().strip(&apos;\n&apos;)
        bbxes = []
        if nums==&apos;0&apos;:
            bbx_info= f_bbx.readline()
            continue
        for ind in range(int(nums)):
            bbx_info = f_bbx.readline().strip(&apos; \n&apos;).split(&apos; &apos;)
            bbx = [int(bbx_info[i]) for i in range(len(bbx_info))]
            # x1, y1, w, h, blur, expression, illumination, invalid, occlusion, pose
            if bbx[7] == 0:
                bbxes.append(bbx)
        writexml(idx, head, bbxes, tailstr)
        shutil.copyfile((&apos;WIDER_&apos; + datatype + &apos;/images/&apos; + filename), (&apos;JPEGImages/%06d.jpg&apos; % (idx)))
        f.write(&apos;%06d\n&apos; % (idx))
        idx += 1
    f.close()
    f_bbx.close()
    return idx


if __name__ == &apos;__main__&apos;:
    clear_dir()
    idx = 1
    idx = excute_datasets(idx, &apos;val&apos;)
    idx = excute_datasets(idx, &apos;train&apos;)
    print(&apos;Complete...&apos;)

&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
  &lt;li&gt;其中main函数中，可以修改val和train来改成自己需要的，前者为验证集，后者为训练集，这部分代码执行是与下载的数据集同一个文件中的。&lt;/li&gt;
  &lt;li&gt;运行代码，输出Complete…后，查看原来的文件可以看到多了三个文件，如下图，各个文件表示的含义就是VOC格式的文件。
&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/voc转化后.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;测试集转换为voc格式&quot;&gt;测试集转换为VOC格式&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;网上搜了很长时间没有找到转换测试集的代码，自己认真分析了上述代码，测试集没有人脸框的标注，原来可以修改上述代码，是自己菜了，代码如下：&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;
import shutil
import random
import os
import string
from skimage import io

headstr = &quot;&quot;&quot;\
&amp;lt;annotation&amp;gt;
    &amp;lt;folder&amp;gt;VOC2012&amp;lt;/folder&amp;gt;
    &amp;lt;filename&amp;gt;%06d.jpg&amp;lt;/filename&amp;gt;
    &amp;lt;source&amp;gt;
        &amp;lt;database&amp;gt;My Database&amp;lt;/database&amp;gt;
        &amp;lt;annotation&amp;gt;PASCAL VOC2012&amp;lt;/annotation&amp;gt;
        &amp;lt;image&amp;gt;flickr&amp;lt;/image&amp;gt;
        &amp;lt;flickrid&amp;gt;NULL&amp;lt;/flickrid&amp;gt;
    &amp;lt;/source&amp;gt;
    &amp;lt;owner&amp;gt;
        &amp;lt;flickrid&amp;gt;NULL&amp;lt;/flickrid&amp;gt;
        &amp;lt;name&amp;gt;company&amp;lt;/name&amp;gt;
    &amp;lt;/owner&amp;gt;
    &amp;lt;size&amp;gt;
        &amp;lt;width&amp;gt;%d&amp;lt;/width&amp;gt;
        &amp;lt;height&amp;gt;%d&amp;lt;/height&amp;gt;
        &amp;lt;depth&amp;gt;%d&amp;lt;/depth&amp;gt;
    &amp;lt;/size&amp;gt;
    &amp;lt;segmented&amp;gt;0&amp;lt;/segmented&amp;gt;
&quot;&quot;&quot;
objstr = &quot;&quot;&quot;\
    &amp;lt;object&amp;gt;
        &amp;lt;name&amp;gt;%s&amp;lt;/name&amp;gt;
        &amp;lt;pose&amp;gt;Unspecified&amp;lt;/pose&amp;gt;
        &amp;lt;truncated&amp;gt;0&amp;lt;/truncated&amp;gt;
        &amp;lt;difficult&amp;gt;0&amp;lt;/difficult&amp;gt;
        &amp;lt;bndbox&amp;gt;
            &amp;lt;xmin&amp;gt;%d&amp;lt;/xmin&amp;gt;
            &amp;lt;ymin&amp;gt;%d&amp;lt;/ymin&amp;gt;
            &amp;lt;xmax&amp;gt;%d&amp;lt;/xmax&amp;gt;
            &amp;lt;ymax&amp;gt;%d&amp;lt;/ymax&amp;gt;
        &amp;lt;/bndbox&amp;gt;
    &amp;lt;/object&amp;gt;
&quot;&quot;&quot;

tailstr = &apos;&apos;&apos;\
&amp;lt;/annotation&amp;gt;
&apos;&apos;&apos;




def writexml(idx, head, bbxes, tail):
    filename = (&quot;Annotations/%06d.xml&quot; % (idx))
    f = open(filename, &quot;w&quot;)
    f.write(head)
    for bbx in bbxes:
        f.write(objstr % (&apos;face&apos;, bbx[0], bbx[1], bbx[0] + bbx[2], bbx[1] + bbx[3]))
    f.write(tail)
    f.close()


def clear_dir():
    if shutil.os.path.exists((&apos;Annotations&apos;)):
        shutil.rmtree((&apos;Annotations&apos;))
    if shutil.os.path.exists((&apos;ImageSets&apos;)):
        shutil.rmtree((&apos;ImageSets&apos;))
    if shutil.os.path.exists((&apos;JPEGImages&apos;)):
        shutil.rmtree((&apos;JPEGImages&apos;))

    shutil.os.mkdir((&apos;Annotations&apos;))
    shutil.os.makedirs((&apos;ImageSets/Main&apos;))
    shutil.os.mkdir((&apos;JPEGImages&apos;))


def excute_datasets(idx, datatype):

    f = open((&apos;ImageSets/Main/&apos; + datatype + &apos;.txt&apos;), &apos;a&apos;)
    f_bbx = open((&apos;wider_face_split/wider_face_&apos; + datatype + &apos;_filelist.txt&apos;), &apos;r&apos;)

    while True:
        filename = f_bbx.readline().strip(&apos;\n&apos;)

        if not filename:
            break

        shutil.copyfile((&apos;WIDER_&apos; + datatype + &apos;/images/&apos; + filename), (&apos;JPEGImages/%06d.jpg&apos; % (idx)))
        f.write(&apos;%06d\n&apos; % (idx))
        idx += 1
    f.close()
    f_bbx.close()
    return idx


if __name__ == &apos;__main__&apos;:
    clear_dir()
    idx = 1
    idx = excute_datasets(idx, &apos;test&apos;)
    print(&apos;Complete...&apos;)

&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
  &lt;li&gt;之前转换的代码删了，这部分是自己写博客的时候，凭记忆修改的，如果有问题，可以自己读一下代码。&lt;/li&gt;
  &lt;li&gt;代码运行提示成功后，可以看到输出了两个文件，如下图，之所以没有以前的几个文件是因为测试集没有人脸框的标注。
&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/测试集.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;总体来说上述已经完成了widerface数据集转换为voc数据集但是后续代码评估时你可能需要有可能看你的评估模型labels文件因此下面是用于生成labels文件的代码&quot;&gt;总体来说，上述已经完成了WIDERFACE数据集转换为VOC数据集，但是后续代码评估时，你可能需要（有可能，看你的评估模型）labels文件，因此下面是用于生成labels文件的代码。&lt;/h4&gt;

&lt;h3 id=&quot;生成labels文件&quot;&gt;生成labels文件&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;下面的代码，就是生成labels文件的代码，实在是忘记从哪下载的了，因此没有在开始处复制链接。&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
import xml.etree.ElementTree as ET
import os
from os import getcwd

sets = [(&apos;2012&apos;, &apos;train&apos;), (&apos;2012&apos;, &apos;val&apos;)]

classes = [&quot;face&quot;]

def convert(size, box):
    dw = 1. / size[0]
    dh = 1. / size[1]
    x = (box[0] + box[1]) / 2.0
    y = (box[2] + box[3]) / 2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x * dw
    w = w * dw
    y = y * dh
    h = h * dh
    return (x, y, w, h)


def convert_annotation(year, image_id):
    in_file = open(&apos;VOCdevkit/VOC%s/Annotations/%s.xml&apos; % (year, image_id))
    out_file = open(&apos;VOCdevkit/VOC%s/labels/%s.txt&apos; % (year, image_id), &apos;w&apos;)
    tree = ET.parse(in_file)
    root = tree.getroot()
    size = root.find(&apos;size&apos;)
    w = int(size.find(&apos;width&apos;).text)
    h = int(size.find(&apos;height&apos;).text)

    for obj in root.iter(&apos;object&apos;):
        difficult = obj.find(&apos;difficult&apos;).text
        cls = obj.find(&apos;name&apos;).text
        if cls not in classes or int(difficult) == 1:
            continue
        cls_id = classes.index(cls)
        xmlbox = obj.find(&apos;bndbox&apos;)
        b = (float(xmlbox.find(&apos;xmin&apos;).text), float(xmlbox.find(&apos;xmax&apos;).text), float(xmlbox.find(&apos;ymin&apos;).text),
             float(xmlbox.find(&apos;ymax&apos;).text))
        bb = convert((w, h), b)
        out_file.write(str(cls_id) + &quot; &quot; + &quot; &quot;.join([str(a) for a in bb]) + &apos;\n&apos;)


if __name__ == &apos;__main__&apos;:
    wd = getcwd()
    for year, image_set in sets:
        if not os.path.exists(&apos;VOCdevkit/VOC%s/labels/&apos; % (year)):
            os.makedirs(&apos;VOCdevkit/VOC%s/labels/&apos; % (year))
        image_ids = open(&apos;VOCdevkit/VOC%s/ImageSets/Main/%s.txt&apos; % (year, image_set)).read().strip().split()
        list_file = open(&apos;%s_%s.txt&apos; % (year, image_set), &apos;w&apos;)
        for image_id in image_ids:
            line = &apos;%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n&apos; % (wd, year, image_id)
            list_file.write(line.replace(&quot;\\&quot;, &apos;/&apos;))
            convert_annotation(year, image_id)
        list_file.close()

&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
  &lt;li&gt;运行上述代码之后，可以看到文件夹下多了一个labels文件，里面的信息是归一化后的坐标信息和类别。
&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/labels文件.png&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://chen-xiuwei.github.io/image/YOLO/labels文件2.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;到目前为止转换的工作已经全部完成下一步就行进行自己的训练了&quot;&gt;到目前为止，转换的工作已经全部完成，下一步就行进行自己的训练了。&lt;/h4&gt;

&lt;h4 id=&quot;如有问题欢迎交流&quot;&gt;如有问题，欢迎交流！&lt;/h4&gt;
</content>
 </entry>
 
 <entry>
   <title>相关工作</title>
   <link href="https://chen-xw.github.io/%E7%9B%B8%E5%85%B3%E5%B7%A5%E4%BD%9C/2021-05-25-%E7%9B%B8%E5%85%B3%E5%B7%A5%E4%BD%9C/"/>
   <updated>2021-05-25T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/%E7%9B%B8%E5%85%B3%E5%B7%A5%E4%BD%9C/相关工作</id>
   <content type="html">&lt;p&gt;记录一下对搭建博客的过程。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;博客工作&lt;/strong&gt;&lt;/p&gt;
&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;2017年之前，记录知识一般都使用CSDN，后来感觉博客园的界面特别美观，转而使用了博客园，保研结束之后，想着写一个属于自己的博客，记录自己日常学习的知识，了解到了Github写博客的强大之处，因此花费了一段时间，试着写一个自己的博客。&lt;/li&gt;
  &lt;li&gt;2021年5月25日 经过零散的时间，终于完成了大部分的工作&lt;/li&gt;
  &lt;li&gt;2021年10月2日 简单的更新了一下个人主页（之前的太丑了，虽然现在的也很丑）&lt;/li&gt;
  &lt;li&gt;2021年11月2日 更新了主页面的访问量，之前的访问次数一直显示不正常，更新后显示正常。&lt;/li&gt;
  &lt;li&gt;2021年11月4日 sidebar中更新了一个新的小插件，显示建立博客的时间&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;致谢&lt;/strong&gt;&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;博客中借鉴了以下博客的样式和代码，非常感谢你们！&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://jekyllthemes.org/themes/lanyon/&quot;&gt;Lanyon主题&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://jekyllthemes.org/themes/codinfox-lanyon/&quot;&gt;Codinfox Lanyon主题&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://jekyllthemes.org/themes/wu-kan/&quot;&gt;jekyll-theme-WuK主题&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.cnblogs.com/cxwpluto/&quot;&gt;我的博客园主题(主题来源于https://www.cnblogs.com/Weber-security/)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>数据库中文乱码</title>
   <link href="https://chen-xw.github.io/mysql/2021-04-15-%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E6%96%87%E4%B9%B1%E7%A0%81/"/>
   <updated>2021-04-15T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/mysql/数据库中文乱码</id>
   <content type="html">&lt;p&gt;主要描写了我使用JDBC连接数据库遇到的问题，其中问题已经解决。&lt;/p&gt;

&lt;head&gt;
     &lt;meta name=&quot;referrer&quot; content=&quot;no-referrer&quot; /&gt;
 &lt;/head&gt;

&lt;p&gt;&lt;strong&gt;JDBC连接数据库写入数据的编码问题&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;
&lt;ul&gt;
  &lt;li&gt;可能你写入数据库的编码方式不是UTF8，需要修改一下，在你连接的地方添加 ` &amp;amp;characterEncoding=UTF8 `
&lt;img src=&quot;https://img2020.cnblogs.com/blog/1770410/202104/1770410-20210415214321774-2090300738.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;也可能是你安装的Mysql数据库没有设置编码方式
 1.配置文件更改编码方式（my.ini文件) 
 MySQL数据库为5.5.3之前的话，在mysqld下添加 &lt;code&gt;default-character-set=utf8&lt;/code&gt;,之后的版本添加 &lt;code&gt;character-set-server=utf8&lt;/code&gt;
 2.在cmd下更改编码方式
 查看所有的编码方式，&lt;code&gt;show variables like &apos;character%;&lt;/code&gt; ,会显示出所有的编码方式，修改编码方式，如下：&lt;code&gt;set character_set_client=utf8&lt;/code&gt;;
以上便是我所遇到的数据库中文乱码的问题，通过这些方法，成功解决了问题。&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>VGG网络学习</title>
   <link href="https://chen-xw.github.io/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/2021-04-15-VGG%E7%BD%91%E7%BB%9C%E5%AD%A6%E4%B9%A0/"/>
   <updated>2021-04-15T00:00:00+00:00</updated>
   <id>https://chen-xw.github.io/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/VGG网络学习</id>
   <content type="html">&lt;p&gt;经过一段时间对VGG网络的学习，想记录一下学到的知识。&lt;/p&gt;

&lt;head&gt;
     &lt;meta name=&quot;referrer&quot; content=&quot;no-referrer&quot; /&gt;
 &lt;/head&gt;

&lt;p&gt;&lt;strong&gt;VGG&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;
&lt;ul&gt;
  &lt;li&gt;VGG：由Oxford的Visual Geometry Group组提出，是2014年ILSVRC竞赛的第二名。&lt;/li&gt;
  &lt;li&gt;分类：A,A-LRN,B,C,D,E共六个配置（根据卷积核大小和卷积层数目），D,E比较常用，分别称为VGG 16和VGG 19。&lt;/li&gt;
  &lt;li&gt;参考资料：(https://zhuanlan.zhihu.com/p/41423739)(https://www.cnblogs.com/lfri/p/10493408.html)&lt;/li&gt;
  &lt;li&gt;模型结构：(https://dgschwend.github.io/netscope/#/preset/vgg-16)&lt;/li&gt;
  &lt;li&gt;参考代码(tensorflow)：(http://www.cs.toronto.edu/~frossard/post/vgg16/)&lt;/li&gt;
  &lt;li&gt;训练参考代码(tensorflow)：(https://github.com/machrisaa/tensorflow-vgg)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;网络结构&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;
&lt;ul&gt;
  &lt;li&gt;创新点（相比于AlexNet)
    &lt;blockquote&gt;
      &lt;p&gt;采用连续的n个3 x 3的卷积核代替AlexNet中的较大卷积核，比如可以用3个3 x 3的卷积核代替一个7 x 7的卷积核，可以通过图像理解（参考资料中），也可以通过公式计算，比如8 x 8的图像经过一层卷积(步长为1，padding为0)之后输出为6 x 6的图像，再经过一层卷积之后输出为4 x 4，再经过一层之后输出为2 x 2的图像，效果跟一次7 x 7的效果一样。&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;VGG-16
    &lt;blockquote&gt;
      &lt;p&gt;由13个卷积层，5个池化层，3个全连接层组成，其中卷积核都为3 x 3，池化用的都是2 x 2。&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;VGG-19
    &lt;blockquote&gt;
      &lt;p&gt;由16个卷积层，5个池化层，3个全连接层组成。&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;代码&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;
&lt;ul&gt;
  &lt;li&gt;环境
    &lt;blockquote&gt;
      &lt;p&gt;自身电脑的环境为，tensorflow-cpu 2.4.0,numpy 1.19.5 ,scipy 1.1.0&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;说明
    &lt;blockquote&gt;
      &lt;p&gt;由于tensorflow2.0以上版本的相比于tensorflow2.0以下版本的变化挺大的，直接用2.0以上版本的运行，可能会出问题，问题如下：module tensorflow has no attribute truncated_normal 可以通过添加如下代码：(1)在import下添加&lt;code&gt;tf.compat.v1.disable_eager_execution() &lt;/code&gt;，(2)修改&lt;code&gt;tf.truncated_normal&lt;/code&gt;为&lt;code&gt;tf.compat.v1.random.truncated_normal&lt;/code&gt;&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;运行截图（检测图片为黄鼠狼）
&lt;img src=&quot;https://img2020.cnblogs.com/blog/1770410/202104/1770410-20210415213715234-1664002774.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如有问题，欢迎交流；如有错误，欢迎指正。&lt;/p&gt;
</content>
 </entry>
 

</feed>
