-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Version 5 Changes #820
Comments
Just by chance, how do I invoke the new createWorker in a local environment. For example doing it right now for me gives me that the createWorker was not defined. It is the only issue so far. |
@luisalvarado I am assuming this is solely in reference to the new dev/v5 branch, and you are able to run the examples in the master branch. I updated the examples in the dev/v5 branch today, and confirmed they all run. Therefore, if you run (for example) this example code it should be clear how to run locally. |
Summary
Major New Features
Breaking Changes Impacting Many Users
createWorker
arguments changedcreateWorker
createWorker("chi_sim", 1)
worker.initialize
andworker.loadLanguage
functions now do nothing and can be deleted from codecreateWorker
worker.reinitialize
In other words, code should be modified from this:
To this:
Breaking Changes Impacting Fewer Users
corePath
will need to update the contents of theircorePath
directorycorePath
should point to a directory that contains all 4 of the files below from Tesseract.js-core v5:tesseract-core.wasm.js
tesseract-core-simd.wasm.js
tesseract-core-lstm.wasm.js
tesseract-core-simd-lstm.wasm.js
worker.detect
function disabled by defaultlegacyCore: true
andlegacyLang: true
increateWorker
optionsTesseract.createWorker("eng", 1, {legacyCore: true, legacyLang: true});
Non-Breaking Changes
jsdelivr
by default (rather than GitHub pages)tesseract.dev.js
andworker.dev.js
removedTesseract.recognize
andTesseract.detect
worker.recognize
andworker.detect
insteadDiscussion
How can file sizes be reduced by so much?
Tesseract contains 2 recognition models—LSTM and Legacy. The vast majority of users only use the LSTM model (the default). However, the Legacy model takes up more space, and previous versions of Tesseract.js loaded all of the resources required for both models. This resulted in significant wasteful network activity. For example, for Chinese (simplified) 73% of the size of the code and data was attributable to the (usually) unused Legacy model.
What justifies the breaking changes to
createWorker
/loadLanguage
/initialize
?The primary reason is that these changes are necessary to facilitate the major improvement of v5—significantly reducing file sizes. How this reduction is achieved is described in the answer directly above. As Tesseract.js is a JavaScript library generally run in the browser, having reasonable file sizes is a high priority. This is especially true as use on mobile devices becomes more common. Making this improvement would have been impossible without combining
createWorker
/loadLanguage
/initialize
.Previously, the user specified which recognition model (OEM) to use during
initialize
. Asinitialize
was run aftercreateWorker
andloadLanguage
(which load the code and language required for each model), there was no way for these functions to only load the data required for the chosen model. By combining these functions, Tesseract.js knows what model is being used before it loads code or data, so can load only the required resources.In addition to this primary reason, combining these functions should simplify the process of creating a worker. The large number of functions required to create a new worker (4 in
v3
and 3 inv4
) was pushing some users towards usingTesseract.recognize
instead (as this handles everything in a single function). Simplifying the process of creating a new worker will hopefully result in more users using workers, which is more efficient thanTesseract.recognize
(which creates and destroys a worker every time it is used).How can I restore the old behavior (loading both LSTM + Legacy models)?
Within
createWorker
, if you setoem
to0
(Tesseract Legacy) or2
(Tesseract Legacy + LSTM), code and language data for both the Legacy and LSTM models will be loaded automatically. You can force both models to be loaded regardless ofoem
by settinglegacyCore: true
andlegacyLang: true
in thecreateWorker
options. For example:If your application re-initializes existing workers with a different language or OEM, this is now achieved using
worker.reinitialize
(rather thanworker.loadLanguage
andworker.initialize
). For example, the following snippet recognizesfile
using the LSTM model, and then switches to the Legacy model and re-runs recognition.How does this release impact iOS compatibility?
iOS
v17.0
andv17.1
include a bug that causes the Legacy + LSTM build of Tesseract.js to crash. Apple patched this issue in iOSv17.2
. This bug does not impact the LSTM-only build, which became the default in Tesseract.js v5. Therefore, developers who want their application to be compatible with iOSv17.0
andv17.1
are advised to upgrade to Tesseract.js v5. Discussion regarding this issue is documented in #804.I am still having trouble upgrading my project, what should I do?
Start by reviewing the examples directory--most uses of Tesseract.js have a corresponding example. If you are struggling to upgrade your project after reviewing both this issue and the examples, feel free to open a new git issue.
The text was updated successfully, but these errors were encountered: