libsvm fails for very small numbers with error code 'Wrong input on line' - libsvm

I've tried searching the internet for inputs on this one, but ineffectively.
I am using libSVM (https://www.csie.ntu.edu.tw/~cjlin/libsvm/) and I've encountered this while training the SVM with rbf kernel.
If a feature contains very small numbers, like feature 15 in the following
0 1:4.25606e+07 2:4.2179e+07 3:5.1059e+07 4:7.72388e+06 5:7.72037e+06 6:8.87669e+06 7:4.40263e-06 8:0.0282494 9:819 10:2.34513e-05 11:21.5385 12:95.8974 13:179.117 14:9 15:6.91877e-310
libSVM will fail reading the file with the error code Wrong input at line <lineID>.
After some testing, I was able to confirm that changing such a small number to 0 appears to fix the error. i.e. this line is correctly read:
0 1:4.17077e+07 2:4.12838e+07 3:5.04597e+07 4:7.76011e+06 5:7.74881e+06 6:8.91813e+06 7:3.97472e-06 8:0.0284308 9:936 10:2.46506e-05 11:22.8714 12:100.969 13:186.641 14:17 15:0
Can anybody help me figure out why this is happening? My file contains a lot of number around that order of magnitude.
I am calling the SVM via terminal on Ubuntu like:
<path to>/svm-train -s 0 -t 2 -g 0.001 -c 100000 <path to features file> <path for output model file>

Related

How to correctly use ogr2ogr and gdal_rasterize to rasterize a smaller area of a large vector of GeoPackage?

I am using gdal_rasterize and ogr2ogr with a goal to get a partial raster of .gpkg file.
With first command I want to clip a smaller area of a large map.
ogr2ogr -spat xmin ymin xmax ymax out.gpkg in.gpkg
This results in a file that with command ogrinfo out.gpkg gives expected output by listing the layers numbers and names.
Then trying to rasterize this new file with:
gdal_rasterize out.gpkg -burn 255 -ot Byte -ts 250 250 -l anylayer out.tif
results in: ERROR 1: Cannot get layer extent when tried with any of the layers names given by ogrinfo
Using the same command on the original in.gpkg doesnt give errors and results in expected .tiff file raster.
ogr2ogr --version GDAL 2.4.2, released 2019/06/28
gdal_rasterize --version GDAL 2.4.2, released 2019/06/28
This process should at the end be implemented with the gdal C++ API.
Are the commands given some how invalid this way, how?
Should the whole process be done differently, how?
What does the ERROR 1: Cannot get layer extent mean?

Error: Could not create output file Processed 0 frames

I am running one of the oneVPL samples- hello-vpp.
I've downloaded the samples source code from oneAPI samples repository-
https://github.com/oneapi-src/oneAPI-samples.git
My OS is Ubuntu 18.04.
After build, I tried the below command to get the output.
./hello-vpp ../content/input.i420 640 480
and I got the below error.
Could not create output file
Processed 0 frames
Any corrections in my command? What would be the expected output?
VPP sample only works with i420 video format and it's size must be 128x96. So the right command to run hello-vpp sample is:
./hello-vpp ../content/input.i420 128x96
The expected output would be
Found ApiVersion: 2.2
SW session created
Processing ../content/input.i420 -> out.i420
Processed 60 frames
The output file i.e. out.i420 would be found in the build directory(Path: "\Libraries\oneVPL\hello-vpp\build") and its size is 640x480 by default.

Horizontal artifacts between geotiff edges using gdalbuildvrt and gdaltranslate

I am trying to merge a number of geotiffs into one large geotiff with overviews, however the final merged geotiff shows a number of horizontal artifacts around the edges of the original merged geotiffs (see here for an example).
I create the merged file using the following code:
'''Produce Combined VRT'''
string ='gdalbuildvrt -srcnodata "0 0 0 0" -hidenodata -r bilinear %s -overwrite %s' %(tmp_vrt, GDal_merge_string)
os.system(string)
'''Convert VRT to Geotiff'''
string ='gdal_translate -b 1 -b 2 -b 3 -mask 4 --config GDAL_TIFF_INTERNAL_MASK YES -of GTiff %s %s' %(tmp_vrt,tmp_fname)
os.system(string)
I have a hunch that this might have to do with using gdal_translate on a vrt, as the erorrs occur on the edges of the original geotiffs, and in this case it might be related or similar to the issue found in this post.
This code is using VRTs to combine the geotiffs for speed purposes, but perhaps it might be better to just merge these with gdalwarp?
Edit: I have reduced the number of flags and left out the overviews in the code above, as suggested in the comment below by Benjamin. The error seems to be produced in the code above. I think the issue may lie in the masking process. I guess at some point in the process of stacking the bands, the inputs are distorted. Is it generally inadvisable to gdal_translate VRTs?

Increasing number of predictions in Inception for Tensorflow

I am going through the training tutorial on retraining Inception's final layer after having installed Tensorflow for Ubuntu with regular CPU support. I successfully made the flower examples work however after switching to a new set of categories with ten sub-folders I cannot make Inception produce ten scores for each input image rather than the default five. My current command line to run a test image looks like this, working with headers labelled 0-9.
bazel build tensorflow/examples/label_image:label_image && \
bazel-bin/tensorflow/examples/label_image/label_image \
--graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt \
--output_layer=final_result \ --input_layer=Mul
--image=$HOME/Input/Example.jpg
Which produces as a result
5 (4): 0.642959
3 (2): 0.243444
9 (8): 0.0513504
4 (5): 0.0231318
6 (7): 0.0180509
However I cannot find anything in the programs that Inception runs to reconfigure how many output scores are produced so that all ten of my categories have scores rather than just five. How do I change this?
I tried with 8 categories and was able to get result for all of them.
If your code has below line
top_k = predictions[0].argsort()[-5:][::-1]
change it to
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
If code contains predictions = np.squeeze(predictions) then use predictions instead of predictions[0]
I have run this using following command instead of bazel and I found it easier.
python /path_to_file/label_image.py /path_to_image/image.jpeg
First make sure that graph is created after you run retrain.py and it is at the correct location. (default is inside /tmp/).

What is the model file in svm-train command-line syntax?

I have used grid.py in LIBSVM and found the best parameter for my dataset
C -8.0 g -0.0625 CV- 63.82
Then I tried svm-train but I don't understand the syntax of the svm-train command
svm-train [options] training_set_file [model_file]
A model_File is need but grid.py only gave me a .out file. When I used this, it showed an error.
My question is:
Could you explain what the model file is, preferably using an example?
I am using LIBSVM on Debian (using the command-line).
You want command-lines like:
svm-train -C 8.0 -g 0.0625 training.data svm.model
svm-predict testing.data svm.model predict.out
The model file (svm.model) is just a place to store the model parameters learned by svm-train so that they can be later used for prediction. The model is created by svm-train, it is not produced by grid.py, and it is input to svm-predict. Therefore you can make any name you like to give to svm--train, so long as you give the same name to svm-predict. I often call the file something like model-C8.0-g0.0625 so I can later tell what it is.
A model file will look like this:
svm_type c_svc
kernel_type rbf
gamma 0.5
nr_class 2
total_sv 6164
rho -2.4768
label 1 -1
nr_sv 3098 3066
SV
2 1:-0.452773 2:-0.455573 3:-0.485312 4:-0.436805 ...
If you need to know more about the model file, see the LIBSVM FAQ