Skip to content

Instantly share code, notes, and snippets.

@oeway
Created September 21, 2021 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oeway/1f75ff6430be6ee21451e2bb88ab368f to your computer and use it in GitHub Desktop.
Save oeway/1f75ff6430be6ee21451e2bb88ab368f to your computer and use it in GitHub Desktop.
Read HPA images with jimp
import {InferenceSession, Tensor} from 'onnxruntime-web';
import Jimp from 'jimp/es';
const COLORS = ["red", "green", "blue", "yellow"]
async function handleRun(e) {
e.preventDefault();
// create an inference session, using WebGL backend. (default is 'wasm')
const baseURL = 'https://images.proteinatlas.org/115/672_E2_1_'
const imgTensor = new Float32Array(1024*1024*4)
for(let c=0;c<COLORS.length;c++){
let img = await Jimp.read(baseURL+COLORS[c]+'.jpg')
img = img.resize(1024, 1024, Jimp.RESIZE_BILINEAR).greyscale()
const data = img.bitmap.data
for(let i=0;i<1024*1024;i++){
imgTensor[c*1024*1024+i] = data[i*4]/255.0
}
}
const session = await InferenceSession.create('./densenet_model_fixed_shape_casted2.onnx', { executionProviders: ['webgl'] });
const imageTensor = new Tensor('float32', imgTensor, [1, 4, 1024, 1024]);
const results = await session.run(imageTensor);
console.log('===>', results)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment