FastText quantize documentation incorrect? - fasttext

I'm unable to run FastText quantization as shown in the documentation. Specifically, as shown at the bottom of the cheat sheet page:
https://fasttext.cc/docs/en/cheatsheet.html
When I attempt to run quantization on my trained model "model.bin":
./fasttext quantize -output model
the following error is printed to the shell:
Empty input or output path.
I've reproduced this problem with builds from the latest code (September 14 2018) and older code (June 21 2018). Since the documented command syntax isn't working, I tried adding an input argument:
./fasttext quantize -input [file] -output model
where [file] is either my training data or trained model. Unfortunately both tries resulted in a segmentation fault with no error message from FastText.
What is the correct command syntax to quantize a FastText model? Also, is it possible to both train and quantize a model in a single run of FastText?

Solution in Python:
# Quantize the model with retraining
model.quantize(input=train_data, qnorm=True, retrain=True, cutoff=200000)
# Save quantized model
model.save_model("model_quantized.bin")

I tried this one worked:
./fasttext quantize -input <training set> -output <model name (no suffix) -[options]

This is the example that is included in the quantization-example.sh
./fasttext quantize -output "${RESULTDIR}/dbpedia" -input "${DATADIR}/dbpedia.train" -qnorm -retrain -epoch 1 -cuto$

Related

an error in caffe train

everybody.I'd like to use caffe to train a 5 classes detection task with "SSD: Single Shot MultiBox Detector", so I changed the num_classes from 21 to 6.However,I get an following error:
"Check failed: num_priors_ * num_classes_ == bottom[1]->channels() (52392 vs. 183372) Number of priors must match number of confidence predictions."
I can understand this error,and I found 52392/6=183372/21,namely why I changed num_classes to 6,but the number of confidence predictions is still 183372. So how to solve this problem. Thank you very much!
Since SSD depends on the number of labels not only for the classification output, but also for the BB prediction, you would need to change num_output in several other places in the model.
I would strongly suggest you wouldn't do that manually, but rather use the python scripts provided in the 'examples/ssd' folder. For instance, you can change line 277 in 'examples/ssd/ssd_pascal_speed.py' to:
num_classes = 5 # instead of 21
And then use the model files this script provides.

Syntax issue with converting over from wavwrite to audiowrite in octave / matlab

In Octave 3.8.1 I'm able to export a stereo wave file using the command below
wavwrite([w1(:) w2(:)],44100,16,'/tmp/testfile.wav');
I'm trying to get it to work with audiowrite using octave 4.0 see below but I get a audiowrite: wrong argument name error
audiowrite('/tmp/testfile2.wav',[w1(:) w2(:) w3(:) w4(:)],44100,16)
and
audiowrite('/tmp/testfile2.flac',[w1(:) w2(:) w3(:) w4(:)],44100,16)
It says audiowrite can have up to 256 channels am I incorrect about this?
Thanks
Try:
audiowrite('/tmp/testfile2.wav',[w1(:) w2(:) w3(:) w4(:)],44100,'BitsPerSample',16)
or
audiowrite('/tmp/testfile2.wav',[w1(:) w2(:) w3(:) w4(:)],44100).
16 Bits per sample is default. Check out the documentation here for more information.

Shape mismatch when using combining layers in Caffe

I'm using the Caffe library for training a convolutional neural network (CNN). However, I'm getting the following error when using the concat layer to combine the output from two convolutional layers before applying it to a inner_product layer.
F1023 15:14:03.867435 2660 net.cpp:788] Check failed: target_blobs[j]->shape() == source_blob->shape() Cannot share param 0 weights from layer 'fc1'; shape mismatch. Source param shape is 400 800 (320000); target param shape is 400 400 (160000)
As far as I know I am using the concat layer in the exact same way as in BVLC_GoogLeNet. The concat layer can be found in my train.prototxt at pastebin under the name combined. The dimensions of my input blob is 256x8x7x24, where the data format in Caffe is batch_size x channels x height x width. I've tried training both using the pycaffe interface and the console. I get the same error. Below is code for training using the console.
solver_path = CAFFE_ROOT+'build/tools/caffe train -solver '
model_path = self.run_dir+'models/solver.prototxt'
log_path = self.run_dir+'models/training.log'
p = subprocess.Popen("GLOG_logtostderr=1 {} {} 2> {}".format(solver_path, model_path, log_path), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
What is the meaning of this error? And how can it be resolved?
Update
As mentioned in the comments the log contains nothing else than the error. The stack trace for the error is the following:
# 0x7f231886e267 caffe::Net<>::ShareTrainedLayersWith()
# 0x7f231885c338 caffe::Solver<>::Test()
# 0x7f231885cc3e caffe::Solver<>::TestAll()
# 0x7f231885cd79 caffe::Solver<>::Step()
# 0x7f231885d6c5 caffe::Solver<>::Solve()
# 0x408d2b train()
# 0x4066f1 main
It should also be noted that my solver and code works fine for training the exact same CNN with only 1 "path" along the network, i.e. without the CONCAT layer.
I believe the issue you're having is that your train net has been updated to have a concat layer while your test net hasn't.
It would explain the 400x400 vs 400x800 issue you're having considering your concat merges two 400x400 layers. I can't know for certain without being able to see your test net.

Matlab libsvm svmpredict accuracy verbose

I have a question of an annoying fact. I'm using libsvm with matlab and I'am able to predict using:
predicted_label = svmpredict(Ylabel, Xlabel, model);
but it happen that every time I make a predictions appears this:
Accuracy = X% (y/n) (classification)
Which I find annoying because I am repeating this procedure a lot of times and also makes it slow because its displaying in screen.
I think what I want is to avoid that svmpredict being verbose.
Can anyone help me with this? Thanks in advance.
-Jessica
I found a much better approach than editing the source code of the c library was to use matlabs evalc which places any output to the first output argument.
[~ predicted_label] = evalc('svmpredict(Ylabel, Xlabel, model)');
Because the string to be evaluated is fixed should be no performance decrease.
svmpredict(Ylabel, Xlabel, model, '-q');
From the manual:
Usage: [predicted_label, accuracy, decision_values/prob_estimates] = svmpredict(testing_label_vector, testing_instance_matrix, model, 'libsvm_options')
[predicted_label] = svmpredict(testing_label_vector, testing_instance_matrix, model, 'libsvm_options')
Parameters:
model: SVM model structure from svmtrain.
libsvm_options:
-b probability_estimates: whether to predict probability estimates, 0 or 1 (default 0); one-class SVM not supported yet
-q : quiet mode (no outputs)
If you are using matlab, just find the line of code that is displaying this information (usually using 'disp', 'sprintf', or 'fprintf') and comment it out using the commenting operator %.
example:
disp(['Accuracy= ' num2str(x)]);
change it to:
% disp(['Accuracy= ' num2str(x)]);
If you are using the main libsvm library then you need to modify it before making.
1- Open the file 'svmpredict.c'
2- find this line of code:
info("Accuracy = %g%% (%d/%d) (classification)\n",
(double)correct/total*100,correct,total);
3- just comment it out using // operator
4- save and close the file
5- make the project

svmtrain error "Group must be a vector."

I am trying to train a SVM with the Matlab interface of LibSVM, but I get following error
model = svmtrain(Classes(train),Attributes(train,:),'-s 0 -t 2');
??? Error using ==> svmtrain at 172 Group must be a vector.
See also comment here: support vector machines in matlab
The problem is, that Matlab is using its own SVM implementation which takes among other things the variables in different order.
To make it work, make sure that the LibSVM library is part of your Matlab's Search Path. One option would be to use the Matlab filebrowser (Current Folder) to go the LibSVM folder and use the menu Add to Path -> Selected Folders and Subfolders. If this solves your problem and you need LibSVM regularly, add the folder to your startup.m using addpath.
See also: Error: Undefined function or method 'svmtrain' for input arguments of type 'double'