0

I want to train OpenALPR's neural network, after finally having success installing it's dependencies. All I need now is to execute train.py, according to the readme in the bottom of this page which I was following, but train.py prompts a persistent error.

When I type python train.py and insert the two-letter country code to train, I still get the error:

Processing: ./br/input/lbr.brazil.exp0.box
Executing: /home/sedento/copiaDeUsrBin -l eng ./br/input/lbr.brazil.exp0.tif lbr.brazil.exp0 nobatch box.train.stderr
sh: 1: /home/sedento/copiaDeUsrBin: Permission denied

train.py requests access to Tesseract bin, which I believe that is in my bin folder (not sure after months). So I made a copy of my bin named copiaDeUsrBin and used chmod -R 777 in it. The error persisted and I used chmod 777 on all links inside copiaDeUsrBin. I lost my sudo ability and the error still persists.

There are other errors in the "Extra info" below, and I believe they might be caused by this one. Does anyone know how to solve the permission error?

Thanks

Extra info:

Currently, when I type sudo, it prompts

sudo: /etc/sudoers is world writable
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

But I can still use commands like ls, differently than here.

The complete result of executing the train.py is as follows:

Two-Letter Country Code to Train: br
Processing: ./br/input/lbr.brazil.exp0.box
Executing: /home/sedento/copiaDeUsrBin -l eng ./br/input/lbr.brazil.exp0.tif lbr.brazil.exp0 nobatch box.train.stderr
sh: 1: /home/sedento/copiaDeUsrBin: Permission denied
mv: cannot stat './lbr.brazil.exp0.tr': No such file or directory
mv: cannot stat './lbr.brazil.exp0.txt': No such file or directory
Extracting unicharset from box file ./br/input/lbr.brazil.exp0.box
Other case A of a is not in unicharset
Other case B of b is not in unicharset
Other case C of c is not in unicharset
Other case D of d is not in unicharset
Other case E of e is not in unicharset
Other case F of f is not in unicharset
Other case G of g is not in unicharset
Other case H of h is not in unicharset
Other case I of i is not in unicharset
Other case J of j is not in unicharset
Other case K of k is not in unicharset
Other case L of l is not in unicharset
Other case M of m is not in unicharset
Other case N of n is not in unicharset
Other case O of o is not in unicharset
Other case P of p is not in unicharset
Other case Q of q is not in unicharset
Other case R of r is not in unicharset
Other case S of s is not in unicharset
Other case T of t is not in unicharset
Other case U of u is not in unicharset
Other case V of v is not in unicharset
Other case W of w is not in unicharset
Other case X of x is not in unicharset
Other case Y of y is not in unicharset
Other case Z of z is not in unicharset
Wrote unicharset file unicharset
Executing: /home/sedento/tesseract-ocr/training/mftraining -F ./tmp/font_properties -U unicharset -O ./tmp/lbr.unicharset ./tmp/*.tr
Warning: No shape table file present: shapetable
Reading ./tmp/*.tr ...

Error: Unable to open ./tmp/*.tr!
"Fatal error encountered!" == NULL:Error:Assert failed:in file globaloc.cpp, line 75
Segmentation fault (core dumped)
mv: cannot stat './tmp/lbr.unicharset': No such file or directory
cp: cannot stat './br/input/unicharambigs': No such file or directory
Reading ./tmp/*.tr ...

Error: Unable to open ./tmp/*.tr!
"Fatal error encountered!" == NULL:Error:Assert failed:in file globaloc.cpp, line 75
Segmentation fault (core dumped)
mv: cannot stat './shapetable': No such file or directory
mv: cannot stat './pffmtable': No such file or directory
mv: cannot stat './inttemp': No such file or directory
mv: cannot stat './normproto': No such file or directory
Combining tessdata files
Error: traineddata file must contain at least (a unicharset fileand inttemp) OR an lstm file.
Error combining tessdata files into lbr.traineddata
Version string:4.00.00alpha
23:version:size=12, offset=192
mv: cannot stat './lbr.unicharset': No such file or directory
mv: cannot stat './lbr.shapetable': No such file or directory
mv: cannot stat './lbr.pffmtable': No such file or directory
mv: cannot stat './lbr.inttemp': No such file or directory
mv: cannot stat './lbr.normproto': No such file or directory
mv: cannot stat './lbr.unicharambigs': No such file or directory

I've already installed Opencv, Leptonica and Tesseract (OpenALPR's dependencies), but I don't understand how to integrate it all. Git's OpenALPR compilation instructions has outdated or broken links, so as I said I was following the readme in the bottom of this page, plus the detailed tutorial for each of the dependencies (Tesseract, Leptonica and OpenCV).

(Extra info part 2) - The code train.py:

#!/usr/bin/python

import os
import glob
import sys

TESSERACT_DIR='/home/sedento/tesseract-ocr'

os.environ["TESSDATA_PREFIX"] = TESSERACT_DIR
#os.system("export TESSDATA_PREFIX=" + TESSERACT_DIR)

TESSERACT_BIN='/usr/bin'
TESSERACT_TRAINDIR= TESSERACT_DIR + '/training'

country = raw_input("Two-Letter Country Code to Train: ").lower()

LANGUAGE_NAME='l' + country

box_files = glob.glob('./' + country + '/input/*.box')

if not box_files:
    print "Cannot find input files"
    sys.exit(1)

os.system("rm ./tmp/*")

font_properties_file = open('./tmp/font_properties','w')

for box_file in box_files:
    print "Processing: " + box_file

    file_without_dir = os.path.split(box_file)[1]
    file_without_ext = os.path.splitext(file_without_dir)[0]
    input_dir = os.path.dirname(box_file)

    tif_file = input_dir + '/' + file_without_ext + ".tif"

    train_cmd = "%s -l eng %s %s nobatch box.train.stderr" % (TESSERACT_BIN, tif_file, file_without_ext)

    print "Executing: " + train_cmd 
    os.system(train_cmd)
    os.system("mv ./" + file_without_ext + ".tr ./tmp/" + file_without_ext + ".tr")
    os.system("mv ./" + file_without_ext + ".txt ./tmp/" + file_without_ext + ".txt")
    font_name=file_without_dir.split('.')[1]
    font_properties_file.write(font_name + ' 0 0 1 0 0\n')

font_properties_file.close()
os.system(TESSERACT_TRAINDIR + "/unicharset_extractor ./" + country + "/input/*.box")
#os.system('mv ./unicharset ./" + country + "/input/" + LANGUAGE_NAME + ".unicharset')
# Shape clustering should currently only be used for the "indic" languages
#train_cmd = TESSERACT_TRAINDIR + '/shapeclustering -F ./' + country + '/input/font_properties -U unicharset ./' + country + '/input/*.tr'
#print "Executing: " + train_cmd
#os.system(train_cmd)

train_cmd = TESSERACT_TRAINDIR + '/mftraining -F ./tmp/font_properties -U unicharset -O ./tmp/' + LANGUAGE_NAME + '.unicharset ./tmp/*.tr'
print "Executing: " + train_cmd
os.system(train_cmd)
os.system("rm ./unicharset")
os.system("mv ./tmp/" + LANGUAGE_NAME + ".unicharset ./")
os.system("cp ./" + country + "/input/unicharambigs ./" + LANGUAGE_NAME + ".unicharambigs")

os.system(TESSERACT_TRAINDIR + '/cntraining ./tmp/*.tr')
#os.system("mv ./unicharset ./" + LANGUAGE_NAME + ".unicharset")
os.system("mv ./shapetable ./" + LANGUAGE_NAME + ".shapetable")
#os.system("rm ./shapetable")
os.system("mv ./pffmtable ./" + LANGUAGE_NAME + ".pffmtable")
os.system("mv ./inttemp ./" + LANGUAGE_NAME + ".inttemp")
os.system("mv ./normproto ./" + LANGUAGE_NAME + ".normproto")

os.system(TESSERACT_TRAINDIR + '/combine_tessdata ' + LANGUAGE_NAME + '.')
# If a config file is in the country's directory, use that.
config_file = os.path.join('./', country, country + '.config')
if os.path.isfile(config_file):
    print "Applying config file: " + config_file
    trainedata_file = LANGUAGE_NAME + '.traineddata'
    os.system(TESSERACT_TRAINDIR + '/combine_tessdata -o ' + trainedata_file + ' ' + config_file )

os.system("mv ./" + LANGUAGE_NAME + ".unicharset ./tmp/")
os.system("mv ./" + LANGUAGE_NAME + ".shapetable ./tmp/")
os.system("mv ./" + LANGUAGE_NAME + ".pffmtable ./tmp/")
os.system("mv ./" + LANGUAGE_NAME + ".inttemp ./tmp/")
os.system("mv ./" + LANGUAGE_NAME + ".normproto ./tmp/")
os.system("mv ./" + LANGUAGE_NAME + ".unicharambigs ./tmp/")
Youki
  • 33
  • 8
  • 1
    Oh no, looks like you've ruined your installation. You will need to recover. As a general rule, running chmod 777, especially on system folders, is always a bad idea. – Azsgy Apr 09 '18 at 21:18
  • `sudo` doesn't work without the setuid bit set. `777` doesn't incorporate a setuid bit. – Charles Duffy Apr 09 '18 at 21:22
  • ...and as Azsgy said, you should never, **never** use `chmod 777`. Not for any purpose whatsoever, until you understand why this advice is generally given and can explain in detail why it doesn't apply to you in a specific instance. :) – Charles Duffy Apr 09 '18 at 21:24
  • (a short, incomplete summary of the "why this advice is generally given" -- if you make binaries world-writable, then even things like pre-authenticated daemons running code sandboxed as `nobody` can change what your executables do; it completely bypasses all your operating system's integrity -- and if someone takes advantage of that even in a short temporary window, you can't get back to a trustworthy state without complete reinstallation). – Charles Duffy Apr 09 '18 at 21:24
  • ...anyhow, as for "how do I recover from a `chmod 777 /bin`"?, it's not really a StackOverflow question -- we only cover writing code, not system administration (whether professional or otherwise). Try [unix.se]. – Charles Duffy Apr 09 '18 at 21:26
  • I knew the risks, but I really need this to work, my graduation time is running out, I'm getting desperate... But thanks for the advices. Solved the sudo being world writable by doing `pkexec chmod 555 /etc/sudoers` then `pkexec chmod 555 /etc/sudoers.d/README` and then `pkexec chmod 0755 /etc/sudoers.d` I wonder if is there any way I can detect a lack of integrity in the system now... And the original error persists – Youki Apr 09 '18 at 22:04
  • In general you cannot detect system integrity issues from within that same system. It is a common pattern in malicious software to sabotage such measures, but the details would be something for [security.SE](https://security.stackexchange.com/). – l0b0 Apr 10 '18 at 01:18
  • Ok, my system might not be 100% but seems quite OK, I can still sudo – Youki Apr 16 '18 at 18:43
  • But I still seek to understand and solve the main issue: **sh: 1: /home/sedento/copiaDeUsrBin: Permission denied** – Youki Apr 16 '18 at 19:00
  • It looks like my shell has no permission to access my folder, does that make any sense? By the way there is a **#!usr/bin/python** at the beggining of my file, so I seem to be executing it correctly with the command **python filename.py**, but then I get a shell permission error? – Youki Apr 16 '18 at 19:52

0 Answers0