Skip to content

3.2.4 has wrong env check in transformers.web.js #1259

@sanixa

Description

@sanixa

Question

Background

I have developed a chrome extension which is followed by the example. The example was used the package @xenova/transformers.

Motivation

It seems that multithreads is work now. Issue Issue2

Question

I change the package from @xenova/transformers@2.17.2 to @huggingface/transformers@3.4.1. It shows a error TypeError: sharp__WEBPACK_IMPORTED_MODULE_4__ is not a function which have no been shown before. Anyone can help?

Code (background.js)

// import { pipeline, env } from '@xenova/transformers';
// env.localModelPath = './';
// env.allowRemoteModels = false;
// env.backends.onnx.wasm.numThreads = 1;

import { env, pipeline } from '@huggingface/transformers';
env.localModelPath = './';

class ImagePipelineSingleton {
    static task = 'image-classification';
    static model = '/deepfake/';
    static instance = null;

    static async getInstance() {
        try {
            if (this.instance === null) {
                this.instance = await pipeline(this.task, this.model);
            }
        } catch (error) {
            console.error("Initialization error:", error);
        }
        return this.instance;
    }
}

...
try{
    let model = await ImagePipelineSingleton.getInstance();
    let classification = await model(url); 
}catch (error) {
    console.error("image processing error:", error); //error here
}
...

Folder Structure

  • deepfake
    • onnx
      • model_quantized.onnx

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions