I'd like to use tesseract to recognize digits on gas meters. I have an image:
If I try to recognize this image using "tesseract gas.png output", it gives me "Empty page!!" and the output is empty. I started with training using this tutorial: https://blog.cedric.ws/how-to-train-tesseract-301
I tried to take one letter and train tesseract with this letter:
I tried this command "tesseract eng.matrx60x40.exp0.png output -psm 10" which worked ("2" in output.txt). I followed the tutorial and I get final eng.traineddata.
eng.traineddata
If I now try to use this traineddata with command "tesseract gas.png output" on the original image, I get "Empty page!!".
Am I doing anything wrong, or it is not possible to train the tesseract letter by letter?
Related
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$
I am very new to MATLAB and i am currently trying to learn how to import files in matlab and work on it. I am importing a "*.dat" file which contains a single column of floating point numbers[they are just filter coefficients I got from a c++ code] into an array in MATLAB. When I am displaying the output in command window the first line is always " 1.0e-03 * " followed by the contents of my file. I want to know what it means? When I check my workspace the array connects the correct number of inputs. My sample code and first few lines of output are below:
Code:-
clear; clc;
coeff = fopen('filterCoeff.dat');
A = fscanf(coeff, '%f');
A
fclose(coeff);
Output:-
A =
**1.0e-03 *** <===== What does this mean?
-0.170194000000000
0
0.404879000000000
0
-0.410347000000000
P.S: I found many options to read file eg. textscan, fscanf etc. Which one is the best to use?
It is a multiplier that applies to all the numbers displayed after that. It means that, for example, the last entry of A is not -0.410347 but -0.410347e-3, that is, -0.000410347.
I think it is is just Matlab's display number type. It means each of your results are scaled by that amount.
format longg
A
And see what it displays. Look at the docs for format for other options.
I'm using Caffe (http://caffe.berkeleyvision.org/) for image classification. I'm using it on Windows and everything seems to be compiling just fine.
To start learning I followed the MNIST tutorial (http://caffe.berkeleyvision.org/gathered/examples/mnist.html). I downloaded the data and ran ..\caffe.exe train --solver=...examples\mnist\lenet_solver.prototxt. It ran 10.000 iterations, printed that the accuracy was 98.5, and generated two files: lenet_iter_10000.solverstate, and lenet_iter_10000.caffemodel.
So, I though it would be funny to try to classify my own image, it should be easy right?.
I can find resources such as: https://software.intel.com/en-us/articles/training-and-deploying-deep-learning-networks-with-caffe-optimized-for-intel-architecture#Examples telling how to prepare, train and time my model. But each time a tutorial/article comes to actually putting a single instance into the CNN, they skip to the next point and tell to download some new model. Some resources tell to use the classifier.bin/.exe, but this file takes a imagenet_mean.binaryproto or similar for mnist. I have no idea where to find or generated this file.
So in short: When I have trained a CNN using Caffe, how to I input a single image and get the output using the files I already have?
Update: Based on the help, I got the Net to recognize an image but the recognition is not correct even if the network had an accuracy of 99.0%. I used the following python code to recognice an image:
NET_FILE = 'deploy.prototxt'
MODEL_FILE = 'lenet_iter_10000.caffemodel'
net = caffe.Net(NET_FILE, MODEL_FILE, caffe.TEST)
im = Image.open("img4.jpg")
in_ = np.array(im, dtype=np.float32)
net.blobs['data'].data[...] = in_
out = net.forward() # Run the network for the given input image
print out;
I'm not sure if I format the image correctly for the MNIST example. The image is a 28x28 grayscale image with a basic 4. Do I have to do more transformations on the image?
The network (deploy) looks like this (start and end):
input: "data"
input_shape {
dim: 1 # batchsize
dim: 1 # number of colour channels - rgb
dim: 28 # width
dim: 28 # height
}
....
layer {
name: "loss"
type: "Softmax"
bottom: "ip2"
top: "loss"
}
If I understand the question correctly, you have a trained model and you want to test the model using your own input images. There are many ways to do this.
One method I commonly use is to run a python script similar to what I have here.
Just keep in mind that you have to build python in caffe using make pycaffe and point to the folder by editing the line sys.path.append('../../../python')
Also edit the following lines to your model filenames.
NET_FILE = 'deploy.prototxt'
MODEL_FILE = 'fcn8s-heavy-pascal.caffemodel'
Edit the following line. Instead of score you should use the last layer of your network to get the output.
out = net.blobs['score'].data
You need to create a deploy.prototxt file from your original network.prototxt file. The data layer has to look like this:
input: "data"
input_shape {
dim: 1
dim: [channles]
dim: [width]
dim: [height]
}
where you replace [channels], [width], and [height] with the correct values of your image.
You also need to remove any layers which get the "label" as its bottom input (this would usually be only your loss layer).
Then you can use this deploy.prototxt file to test your inputs using MATLAB or PYTHON.
Recently I'm trying to detect digits from images in Matlab and I encountered a problem: a clear visible '1' on photo below (and many similar)
1
is not detected by 'ocr' function. Could you tell me how can I preprocess this image to allow this funcion recognize such a numbers?
you might find this example on the mathworks web-site helpful. The second example of looking for digits on a picture of calculator is particularly relevant.
Applying the first trick they use (telling OCR you are expecting a block of text) results in the code below; which I found partially worked with the particular example image you linked above.
% Load your image
I = imread('tkTMN.jpg');
% Perform OCR, looking for a block of text:
results = ocr(I, 'TextLayout', 'Block');
% Display the recognized words
if ~isempty(results.Words)
disp(results.Words);
else
error('no words found');
end
For me, on matlab 8.6.0.267246 (R2015b) this returned the word list:
'1'
'.'
'j'
So not perfect, but at least it found the '1'. The other pre-processing tricks suggested on the mathworks page might get you better results.
Hi I'm trying to print some simulinks models to use them on a latex document.
I've checked the documentation and the posts in stackoverflow and found some answers but they didn't solve my problem.
I want to create a script to print several models with their correct scaling, so I used the commands:
set_param('model','PaperPositionMode','tiled')
set_param('model','ShowPageBoundaries','on')
set_param('model','PaperType','A4')
set_param('model','TiledPageScale','2')
print -dpdf -r300 -smodel model.pdf
When I change the TiledPageScale value I see the change in Simulink, but when I print the file either on pdf or eps the result is cropped the same as with TiledPageScale 1, no matter what value I've set.
I've checked the answer Save Matlab Simulink Model as PDF with tight bounding box but I'm using matlab 2014a so I don't know if it's fixed yet
Thanks
EDIT: I'd ask or comment in the above post but I don't have the enough reputation