Loss function representing the euclidean distance from prediction to nearest groundtruth in images? - machine-learning

Is there a loss function that calculates the euclidean distance between a prediction pixel and the nearest groundtruth pixel? Specifically, this is the location distance, not the intensity distance.
This would be on binary predictions and binary groundtruth.

That's the root of mean square error (RMSE), for example:
model.compile(loss='rmse', optimizer='adagrad')
But it might be better to use mean squared error instead because of what is discussed here https://github.com/fchollet/keras/issues/1170:
i.e. Keras computes the loss batch by batch. To avoid inconsistencies
I recommend using MSE instead.
As in:
model.compile(loss='rmse', optimizer='adagrad')
But since your data has only binary predictions I would advise the binary_crossentropy instead (https://keras.io/losses/#binary_crossentropy):
model.compile(loss='binary_crossentropy', optimizer='adagrad')

Related

K-means++ clustering Algorithm

The algorithm for the K-means++ is:
Take one centroid c(i), chosen uniformly at random from the dataset.
Take a new Centroid c(i), choosing an instance x(i) from the dataset with the probability
D(X(i))^2/Sum(D(X(j))^2) from j=1 to m, where D(X(i)) is the distance between the instance and the closest centroid which is selected.
What is this parameter m used in the summation of the probability?
It might have been helpful to see the original formulation, but the algorithm is quite clear: during the initialization phase, for each point not used as a centroid, calculate the distance between said point and the nearest centroid, that will be the distance D(X[i]), the pick a random point in this set of points with probability weighted with D(X[i])^2
In your formulation it seems you got m points unused.

Selecting an IoU and confidence threshold for evaluation of model performance

mAP is commonly used to evaluate the performance of object detection models. However, there are two variables that need to be set when calculating mAP:
confidence threshold
IoU threshold
Just to clarify, confidence threshold is the minimum score that the model will consider the prediction to be a true prediction (otherwise it will ignore this prediction entirely). IoU threshold is the minimum overlap between ground truth and prediction boxes for the prediction to be considered a true positive.
Setting both of these thresholds to be low would result in a greater mAP. However, the low thresholds would most likely be inconsistent with the mAP scores from other studies. How does one select, and justify, these threshold values?
In Yolov5, we do NMS on the outputs of network, then calculate mAP. So, there is a conf_thres and an iou_thres in NMS to filter some boxes, these are set to 0.001 and 0.6, see: https://github.com/ultralytics/yolov5/blob/2373d5470e386a0c63c6ab77fbee6d699665e27b/val.py#L103.
When calculating mAP, we set iou threshold to 0.5 for mAP#0.5, or 0.5 to 0.95 with step 0.05 for mAP#0.5:0.95.
I guess the way of calculating mAP in Yolov5 is aligned to other framework. If I'm wrong, please correct me.

Bring any PyTorch cuda tensor in the range [0,1]

Suppose I have a PyTorch Cuda Float tensor x of the shape [b,c,h,w] taking on any arbitrary value allowed by Float Tensor range. I want to normalise it in the range [0,1].
I think of the following algorithm (but any other will also do).
Step1: Find minimum in each batch. Call it min and having shape [b,1,1,1].
Step2: Similarly find the maximum and call it max.
Step3: Use y = (x-min)/max. Alternatively use y = (x-min)/(max-min). I don't know which one will be better. y should have the same shape as that of x.
I am using PyTorch 1.3.1.
Specifically I am unable to get the desired min using torch.min(). Same goes for max.
I am going to use it for feeding it to pre-trained VGG for calculating perceptual loss (after the above normalisation i will additionally bring them to ImageNet mean and std). Due to some reason I cannot enforce [0,1] range during data loading part because the previous works in my area have a very specific normalisation algorithm which has to be used but some times does not ensures [0,1] bound but will be somewhere in its vicinity. That is why at the time computing perceptual loss I have to do this explicit normalisation as a precaution. All out of the box implementation of perceptual loss I am aware assume data is in [0,1] or [-1,1] range and so do not do this transformation.
Thankyou very much
Not the most elegant way, but you can do that using keepdim=True and specifying each of the dimensions:
channel_min = x.min(dim=1, keepdim=True)[0].min(dim=2,keepdim=True)[0].min(dim=3, keepdim=True)[0]
channel_max = x.max(dim=1, keepdim=True)[0].max(dim=2,keepdim=True)[0].max(dim=3, keepdim=True)[0]

Distance function to SURF-128 descriptors comparing

I read that euclidean distance is not optimal for high dimensional data, but in this publcation is written that euclidean or manhattan distance should be used.
But what better? Any benchmarks, tests?
Is it possible to obtain absolute threshhold (I know about 0.7 ratio between nearest neighbors in knn search)?

Finding the function approximated by a neural network

If I have a feed-forward multilayer perceptron with sigmoid activation function, which is trained and has known weights, how can I find the equation of the curve that is approximated by the network (the curve that separates between 2 types of data)?
In general, there is no closed form solution for the input points where your NN output is 0.5 (or 0, in case of -1/1 instead of 0/1).
What is usually done for visualization in low-dimensional input space is gridding up the input space and computing the contours of the NN output. (The contours are smooth estimate of what the NN response surface looks like.)
In MATLAB, one would do
[X,Y] = meshgrid(linspace(-1,1), linspace(-1,1));
contour(f(X,Y))
where f is your trained NN, and assuming [-1,1] x [-1,1] space.

Resources