mrjleo/boilernet

Implement model as chrome extentions

michaelshekasta opened this issue · 13 comments

Hi,

Thanks for sharing your work!
I want to create a chrome extension:

  1. I run the preprocess & train scripts
  2. I copied the files: model.js (after converting from Keras model), words.js, and tag.js
  3. I install node.js and run install & build scripts
  4. I imported the dist folder into chrome (chrome://extentions -> developer model -> load unpacked)

Then, I try to run it on chrome on this page. But, the content isn't highlighted. I saw that the extension created the Boilernet tags (even in the navigation menu):

image

What do I miss up?

Michael

Not sure what the problem is here, does the provided extension with the pre-trained model (download from the releases menu) work for you?

Nope, I had created the model by myself.
When I try to install the chrome extension from the releases menu, I got this error:
image

This might be a Chrome issue, if you unpack the .crx you should be able to install it.

I run it now with chrome extension in the releases menu and it's worked:
image

But, when I try to it by myself (try to create the chrome extension by myself), it doesn't work well. the model doesn't create the tag in head:
<style type="text/css">.boilernet_content {background-color: yellow;}</style>

In addition, there isn't any tag that has class boilernet_content.

Does it work when you take the pre-compiled extension and only replace the files corresponding to the trained model?

Nope, it doesn't work. I saw the same problem when I am putting my model.

any help?

I can not reproduce the problem. I just created a new environment, trained a new model and replaced the files in the chrome extension. Everything works as it should. This might be on your end.

How do you create the model.js?

I converted it like this:

import argparse

import tensorflowjs as tfjs
import tensorflow as tf


def convert(input_path, output_path):
    model = tf.keras.models.load_model(input_path)
    tfjs.converters.save_keras_model(model, output_path)


if __name__ == '__main__':
    ap = argparse.ArgumentParser()
    ap.add_argument('-l', '--input_file', help='The input file (where h5 model stored')
    ap.add_argument('-u', '--output_file', help='The output file (where to save model.js')
    args = ap.parse_args()
    convert(input_path=ap.input_file, output_path=ap.output_file)

You can just use tensorflowjs_converter as described here. I ran this command:

tensorflowjs_converter --input_format=keras train/ckpt/model.xxx.h5 tfjs_model

Now, It's work with the model that I trained. But, when I try to deploy a chrome extension I got errors.
I copy the model.js, words.js, and tags.js. Then I ran that commands in the terminal:

cd chrome-extension
npm install
npm run build

then, when I upload the whole folder, I got this error:
image

When I uploaded the dist folder only, it's work but I got this error in the chrome extension tab:
image

Can you help me with that?

Sorry, I can't reproduce this issue either. The steps you took are correct. Are you missing files in the dist/files directory? There should be 6 in total (3 binaries, model.json, tags.json, words.json).

Closing this due to inactivity.