Created
September 21, 2021 18:20
-
-
Save oeway/1f75ff6430be6ee21451e2bb88ab368f to your computer and use it in GitHub Desktop.
Read HPA images with jimp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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