git clone user@git-server:project_name.git -b branch_name /your/folder
Sunday, September 29, 2019
Common git usage
Clone a single branch
Monday, September 16, 2019
Ubuntu boot to initramfs
Problem:
Ubuntu cannot boot normally but drop to initramfs. The reason is some part of filesystem is broken, so we need to fix.
BusyBox v1.18.5 (Ubuntu 1:1.18.5-1ubuntu4) built-in shell (ash)
Enter 'help' for a list of built-in commands.
(initramfs)
Solution write the command of
fsck /dev/sdax
like the below and give Y
if the console ask for fixing something:(initramfs) fsck /dev/sda1
or
(initramfs) fsck /dev/sdaX
X
specifies mounted disk part number.
If you don't want to manually press 'y' every time it asks for a fix, you can also run the command with the
-y
option.(initramfs) fsck /dev/sdaX -y
Friday, August 30, 2019
Install opencv_contrib
Note version of opencv and opencv_contrib must be the same, e.g., opencv-3.4.1 and opencv_contrib-3.4.1
in opencv-3.4.1 build directory:
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_CUDA=OFF -D CMAKE_INSTALL_PREFIX=/home/share/opencv34 -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib-3.4.1>/modules -DBUILD_opencv_rgbd=OFF ..
$ make -j
in opencv-3.4.1 build directory:
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_CUDA=OFF -D CMAKE_INSTALL_PREFIX=/home/share/opencv34 -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib-3.4.1>/modules -DBUILD_opencv_rgbd=OFF ..
$ make -j
Wednesday, June 26, 2019
segmentation loss
From original article:
https://lars76.github.io/neural-networks/object-detection/losses-for-segmentation/
IoU loss https://www.cs.umanitoba.ca/~ywang/papers/isvc16.pdf
https://lars76.github.io/neural-networks/object-detection/losses-for-segmentation/
IoU loss https://www.cs.umanitoba.ca/~ywang/papers/isvc16.pdf
Focal loss
Focal loss (FL) [2] tries to down-weight the contribution of easy examples so that the CNN focuses more on hard examples.
FL can be defined as follows:
FL(p,^p)=−(α(1−^p)γplog(^p)+(1−α)^pγ(1−p)log(1−^p))
When γ=0, we obtain BCE.
This time we cannot use
=α(1−^p)γplog(1+e−x)−(1−α)^pγ(1−p)log(e−x1+e−x)=α(1−^p)γplog(1+e−x)−(1−α)^pγ(1−p)(−x−log(1+e−x))=α(1−^p)γplog(1+e−x)+(1−α)^pγ(1−p)(x+log(1+e−x))=log(1+e−x)(α(1−^p)γp+(1−α)^pγ(1−p))+x(1−α)^pγ(1−p)=log(e−x(1+ex))(α(1−^p)γp+(1−α)^pγ(1−p))+x(1−α)^pγ(1−p)=(log(1+ex)−x)(α(1−^p)γp+(1−α)^pγ(1−p))+x(1−α)^pγ(1−p)=(log(1+e−|x|)+max(−x,0))(α(1−^p)γp+(1−α)^pγ(1−p))+x(1−α)^pγ(1−p)weighted_cross_entropy_with_logits
to implement FL in Keras. We will derive instead our own focal_loss_with_logits
function.
And the implementation is then:
Overlap measures
Dice Loss / F1 score
The Dice coefficient is similar to the Jaccard Index (Intersection over Union, IoU):
DC=2TP2TP+FP+FN=2|X∩Y||X|+|Y|IoU=TPTP+FP+FN=|X∩Y||X|+|Y|−|X∩Y|
where TP are the true positives, FP false positives and FN false negatives. We can see that DC≥IoU.
The dice coefficient can also be defined as a loss function:
DL(p,^p)=2⟨p,^p⟩∥p∥22+∥^p∥22
where p∈{0,1}n and 0≤^p≤1.
Since p is either 1 or 0, the numerator will always be one times the predicted probability of the foreground pixel (1). Hence, when p is a background pixel (0), the numerator will be 0.
Tversky loss
Tversky loss (TL) is a generalization of Dice loss. TL adds a weight to FP and FN.
DL(p,^p)=⟨p,^p⟩⟨p,^p⟩+β⟨1−p,^p⟩+(1−β)⟨p,1−^p⟩
Let β=12. Then
=2⟨p,^p⟩2⟨p,^p⟩+⟨1−p,^p⟩+⟨p,1−^p⟩=2⟨p,^p⟩⟨1,^p⟩+⟨1,p⟩
Lovász-Softmax
DL and TL simply relax the hard constraint ^p∈{0,1}n in order to have a function on the domain [0,1]. The paper [6] derives instead a surrogate loss function.
An implementation of Lovász-Softmax can be found on github. Note that this loss requires the identity activation in the last layer. A negative value means class A and a positive value means class B.
In Keras the loss function can be used as follows:
References
[1] S. Xie and Z. Tu. Holistically-Nested Edge Detection, 2015.
[2] T.-Y. Lin, P. Goyal, R. Girshick, K. He, and P. Dollar. Focal Loss for Dense Object Detection, 2017.
[3] O. Ronneberger, P. Fischer, and T. Brox. U-Net: Convolutional Networks for Biomedical Image Segmentation, 2015.
[4] F. Milletari, N. Navab, and S.-A. Ahmadi. V-Net: Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation, 2016.
[5] S. S. M. Salehi, D. Erdogmus, and A. Gholipour. Tversky loss function for image segmentation using 3D fully convolutional deep networks, 2017.
[6] M. Berman, A. R. Triki, M. B. Blaschko. The Lovász-Softmax loss: A tractable surrogate for the optimization of the intersection-over-union measure in neural networks, 2018.
Subscribe to:
Posts (Atom)