Programming Bugs Records

单独开一个blog来记录各式各样的bugs…

编程bugs记录

这篇博客谨记录我所遇到过的bugs。
它包括两个部分,一个是bugs记录,另一个是techniques记录。

Bugs

$\LaTeX$ Bugs

1. caption outside float

记录于2019/08/25,

为以下代码报的错:

1
\renewcommand{\algorithm}{算法}

且我在为算法添加标题时用了中文标题,然后就报错了…

解决方案是注释(删了)这行,就可以用中文标题了…

2.Something’s wrong—perhaps a missing \item.

Bug是

1
LaTeX Error: Something's wrong--perhaps a missing \item.

网上有的说法是参考文献的问题,而我的是因为使用列表环境\begin{enumerate}[(1)]时没有添加\usepackage{enumerate}

CV2 Bugs

1. FindContours supports only CV_8UC1 images

记录于2019/09/02,

Bug是

1
[start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function cvStartFindContours_Impl

It appears when I want to find a contour using cv2 fuctions after adding some dilation operations, and the solution is just using

1
2
image = np.clip(image, 0, 255)
image = np.array(image,np.uint8)

The reference comes from https://blog.csdn.net/u010030977/article/details/81214145

2. UMat for argument ‘src’

Recorded on 8th, Aug, 2019.

The bug is

1
TypeError: Expected cv::UMat for argument 'src'

It appears because I open an image with PIL, then try to convert it to RGB using cv2

Techniques

PyTorch

1. get class probabilities

Recorded on 25th, August, 2019.

When designing a DNN for classification, sometimes we want to see what the probability of the issue whether a test sample belongs to a certain class is.

Before this, we need the output of the net, usually a list of numbers.

1
2
3
4
5
6
7
net = net.cuda()
input = input.cuda()
outputs = net(input)# the output of the net

p = torch.nn.functional.softmax(outputs, dim=1)# `p` is what we want and its sum is 1
_, predicted = torch.max(outputs.data, 1)# `predicted` is the order because we get the max in `p`
classes[predicted.cpu()]# the class name