mirror of
https://git.coom.tech/araragi/JKCS.git
synced 2024-06-26 12:42:41 +00:00
Make FF use SIMD, load bin blobs locally, fix undeclared variables...
This commit is contained in:
parent
d72c3a3fe9
commit
a94292d4fe
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -47,3 +47,8 @@ efdb47d2f0e04144bbaa-0.245.xpi
|
|||
build-test.js
|
||||
dist/test.js
|
||||
src/pngv4.ts
|
||||
firefox/model.weights.bin
|
||||
firefox/tfjs-backend-wasm-simd.wasm
|
||||
firefox/tfjs-backend-wasm-threaded-simd.wasm
|
||||
firefox/tfjs-backend-wasm.wasm
|
||||
firefox/dist/main.js
|
||||
|
|
|
@ -66,7 +66,7 @@ const manif = {
|
|||
},
|
||||
// inject: ["./esbuild.inject.js"],
|
||||
plugins: [],
|
||||
loader: { ".bin": "text" },
|
||||
loader: { ".bin": "text", '.wasm': 'binary' },
|
||||
metafile: true,
|
||||
});
|
||||
|
||||
|
@ -102,7 +102,12 @@ const manif = {
|
|||
);
|
||||
*/
|
||||
writeFileSync("./firefox/manifest.json", JSON.stringify(manif, null, 2));
|
||||
copyFileSync("./logo.png", "./chrome/1449696017588.png");
|
||||
copyFileSync("./logo.png", "./firefox/1449696017588.png");
|
||||
|
||||
copyFileSync("./src/model.weights.bin", "./firefox/model.weights.bin");
|
||||
copyFileSync("./src/tfjs-backend-wasm-threaded-simd.wasm", "./firefox/tfjs-backend-wasm-threaded-simd.wasm");
|
||||
copyFileSync("./src/tfjs-backend-wasm-simd.wasm", "./firefox/tfjs-backend-wasm-simd.wasm");
|
||||
copyFileSync("./src/tfjs-backend-wasm.wasm", "./firefox/tfjs-backend-wasm.wasm");
|
||||
|
||||
res = await webExt.cmd.build({
|
||||
sourceDir: "./firefox/",
|
||||
|
|
3265
firefox/dist/main.js
vendored
3265
firefox/dist/main.js
vendored
File diff suppressed because one or more lines are too long
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"name": "JannySkillersCaptchaSolver",
|
||||
"description": "The Janny Skillers Captcha Solver of choice.",
|
||||
"version": "0.25",
|
||||
"version": "0.27",
|
||||
"icons": {
|
||||
"64": "1449696017588.png"
|
||||
},
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"addons":{"{jkcs@coom.tech}":{"updates":[{"version":"0.25","update_link":"https://git.coom.tech/araragi/JKCS/raw/branch/master/jkcs-0.25.xpi"}]}}}
|
||||
{"addons":{"{jkcs@coom.tech}":{"updates":[{"version":"0.27","update_link":"https://git.coom.tech/araragi/JKCS/raw/branch/master/jkcs-0.27.xpi"}]}}}
|
BIN
jkcs-0.27.xpi
Normal file
BIN
jkcs-0.27.xpi
Normal file
Binary file not shown.
14505
package-lock.json
generated
Normal file
14505
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
59
src/main.js
59
src/main.js
|
@ -2,19 +2,46 @@ import * as tf from '@tensorflow/tfjs'
|
|||
import { setWasmPaths } from '@tensorflow/tfjs-backend-wasm'
|
||||
import charsetJSON from './charset.json'
|
||||
import modelJSON from './model.json'
|
||||
import weightsData from './model.weights.bin'
|
||||
|
||||
let weightsData
|
||||
let model
|
||||
|
||||
tf.enableProdMode()
|
||||
// tf.enableDebugMode()
|
||||
|
||||
const wasmToUrl = wasm => {
|
||||
const blb = new Blob([tfwasm])
|
||||
return URL.createObjectURL(blb)
|
||||
}
|
||||
|
||||
const backendloaded = (async () => {
|
||||
try {
|
||||
// dead code elimination should occur here
|
||||
if (execution_mode === 'userscript') {
|
||||
weightsData = import('./model.weights.bin')
|
||||
|
||||
const tfwasmthreadedsimd = await import('./tfjs-backend-wasm-threaded-simd.wasm')
|
||||
const tfwasmsimd = await import('./tfjs-backend-wasm-simd.wasm')
|
||||
const tfwasm = await import('./tfjs-backend-wasm.wasm')
|
||||
setWasmPaths({
|
||||
'tfjs-backend-wasm.wasm': 'https://unpkg.com/@tensorflow/tfjs-backend-wasm@3.19.0/dist/tfjs-backend-wasm.wasm',
|
||||
'tfjs-backend-wasm-simd.wasm': 'https://unpkg.com/@tensorflow/tfjs-backend-wasm@3.19.0/dist/tfjs-backend-wasm-simd.wasm',
|
||||
'tfjs-backend-wasm-threaded-simd.wasm': 'https://unpkg.com/@tensorflow/tfjs-backend-wasm@3.19.0/dist/tfjs-backend-wasm-threaded-simd.wasm'
|
||||
}) // TODO: Figure out how the fuck to load the WASM modules locally from the extension.
|
||||
// setWasmPaths('https://unpkg.com/@tensorflow/tfjs-backend-wasm@3.19.0/dist/', true)
|
||||
tf.setBackend('wasm')
|
||||
'tfjs-backend-wasm.wasm': wasmToUrl(tfwasm),
|
||||
'tfjs-backend-wasm-simd.wasm': wasmToUrl(tfwasmsimd),
|
||||
'tfjs-backend-wasm-threaded-simd.wasm': wasmToUrl(tfwasmthreadedsimd)
|
||||
})
|
||||
} else {
|
||||
weightsData = await (await fetch(chrome.runtime.getURL('./model.weights.bin'))).text()
|
||||
const args = {
|
||||
'tfjs-backend-wasm.wasm': chrome.runtime.getURL('tfjs-backend-wasm.wasm'),
|
||||
'tfjs-backend-wasm-simd.wasm': chrome.runtime.getURL('tfjs-backend-wasm-simd.wasm'),
|
||||
'tfjs-backend-wasm-threaded-simd.wasm': chrome.runtime.getURL('tfjs-backend-wasm-threaded-simd.wasm')
|
||||
}
|
||||
setWasmPaths(args)
|
||||
}
|
||||
const l = await tf.setBackend('wasm')
|
||||
console.log('tf backend loaded', l)
|
||||
} catch (err) {
|
||||
console.log('tf err', err)
|
||||
}
|
||||
})()
|
||||
|
||||
function toggle (obj, v) {
|
||||
if (v) obj.style.display = ''
|
||||
|
@ -204,19 +231,19 @@ async function predict (img, bg, off) {
|
|||
if (!model) {
|
||||
model = await load()
|
||||
}
|
||||
image = imageFromCanvas(img, bg, off)
|
||||
tensor = tf.browser
|
||||
const image = imageFromCanvas(img, bg, off)
|
||||
const tensor = tf.browser
|
||||
.fromPixels(image, 1)
|
||||
.mul(-1 / 238)
|
||||
.add(1)
|
||||
prediction = await model.predict(tensor.expandDims(0)).data()
|
||||
const prediction = await model.predict(tensor.expandDims(0)).data()
|
||||
|
||||
return createSequence(prediction)
|
||||
}
|
||||
|
||||
function createSequence (prediction) {
|
||||
const csl = charsetJSON.charset.length
|
||||
sequence = []
|
||||
const sequence = []
|
||||
|
||||
for (let pos = 0; pos < prediction.length; pos += csl) {
|
||||
const preds = prediction.slice(pos, pos + csl)
|
||||
|
@ -240,8 +267,8 @@ function createSequence (prediction) {
|
|||
}
|
||||
|
||||
function postprocess (sequence, overrides) {
|
||||
csl = charsetJSON.charset.length
|
||||
possibilities = [{ sequence: [] }]
|
||||
const csl = charsetJSON.charset.length
|
||||
let possibilities = [{ sequence: [] }]
|
||||
|
||||
sequence.forEach(function (e, i) {
|
||||
let additions
|
||||
|
@ -255,7 +282,7 @@ function postprocess (sequence, overrides) {
|
|||
|
||||
if (additions.length === 1 && additions[0].sym === '') return
|
||||
|
||||
oldpos = possibilities
|
||||
const oldpos = possibilities
|
||||
possibilities = []
|
||||
oldpos.forEach(function (possibility) {
|
||||
additions.forEach(function (a) {
|
||||
|
@ -381,6 +408,8 @@ async function solve (force) {
|
|||
const help = document.getElementById('t-help')
|
||||
if (!help) return
|
||||
|
||||
await backendloaded
|
||||
|
||||
placeAfter(solveButton, resp)
|
||||
placeAfter(altsDiv, help)
|
||||
|
||||
|
|
BIN
src/tfjs-backend-wasm-simd.wasm
Normal file
BIN
src/tfjs-backend-wasm-simd.wasm
Normal file
Binary file not shown.
BIN
src/tfjs-backend-wasm-threaded-simd.wasm
Normal file
BIN
src/tfjs-backend-wasm-threaded-simd.wasm
Normal file
Binary file not shown.
BIN
src/tfjs-backend-wasm.wasm
Normal file
BIN
src/tfjs-backend-wasm.wasm
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user