diff --git a/components/ImageCanvas.tsx b/components/ImageCanvas.tsx index f1d0c6f..a49f57d 100644 --- a/components/ImageCanvas.tsx +++ b/components/ImageCanvas.tsx @@ -1,7 +1,7 @@ -import {useRef, useState} from 'react'; -import {IMAGE_URLS} from '../data/sample-image-urls'; -import { inferenceSqueezenet } from '../utils/predict' -import styles from '../styles/Home.module.css' +import { useRef, useState } from 'react'; +import { IMAGE_URLS } from '../data/sample-image-urls'; +import { inferenceSqueezenet } from '../utils/predict'; +import styles from '../styles/Home.module.css'; interface Props { height: number; diff --git a/pages/index.tsx b/pages/index.tsx index b62bba0..73f3818 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,6 +1,6 @@ -import type { NextPage } from 'next' -import Head from 'next/head' -import styles from '../styles/Home.module.css' +import type { NextPage } from 'next'; +import Head from 'next/head'; +import styles from '../styles/Home.module.css'; import ImageCanvas from "../components/ImageCanvas"; diff --git a/utils/imageHelper.ts b/utils/imageHelper.ts index 7e58c26..0d1c629 100644 --- a/utils/imageHelper.ts +++ b/utils/imageHelper.ts @@ -1,8 +1,7 @@ -import Jimp from 'jimp/*'; +import * as Jimp from 'jimp'; import { Tensor } from 'onnxruntime-web'; -const jimp = require('jimp'); -export default async function getImageTensorFromPath(path: string, dims: number[] = [1, 3, 224, 224]): Promise { +export async function getImageTensorFromPath(path: string, dims: number[] = [1, 3, 224, 224]): Promise { // 1. load the image var image = await loadImagefromPath(path, dims[2], dims[3]); // 2. convert to tensor @@ -13,7 +12,7 @@ export default async function getImageTensorFromPath(path: string, dims: number[ async function loadImagefromPath(path: string, width: number = 224, height: number= 224): Promise { // Use Jimp to load the image and resize it. - var imageData = await jimp.default.read(path).then((imageBuffer: Jimp) => { + var imageData = await Jimp.default.read(path).then((imageBuffer: Jimp) => { return imageBuffer.resize(width, height) }); diff --git a/utils/modelHelper.ts b/utils/modelHelper.ts index d8090ab..b6fc56e 100644 --- a/utils/modelHelper.ts +++ b/utils/modelHelper.ts @@ -1,7 +1,6 @@ import * as ort from 'onnxruntime-web'; import _ from 'lodash'; -import {imagenetClasses} from '../data/imagenet'; -import { InferenceSession } from 'onnxruntime-web'; +import { imagenetClasses } from '../data/imagenet'; export async function runSqueezenetModel(preprocessedData: any): Promise<[any, number]> { @@ -20,7 +19,7 @@ import { InferenceSession } from 'onnxruntime-web'; } - async function runInference(session: InferenceSession, preprocessedData: any): Promise<[any, number]> { + async function runInference(session: ort.InferenceSession, preprocessedData: any): Promise<[any, number]> { // Get start time to calculate inference time. const start = new Date(); diff --git a/utils/predict.ts b/utils/predict.ts index 30fea26..8bcd46d 100644 --- a/utils/predict.ts +++ b/utils/predict.ts @@ -1,7 +1,7 @@ // Language: typescript // Path: react-next\utils\predict.ts -import getImageTensorFromPath from './imageHelper'; -import {runSqueezenetModel} from './modelHelper'; +import { getImageTensorFromPath } from './imageHelper'; +import { runSqueezenetModel } from './modelHelper'; export async function inferenceSqueezenet(path: string): Promise<[any,number]> { // 1. Convert image to tensor