I am trying to use my own custom model to classify between dogs and cats in react native app. Three errors appears. Could you please help me to resolve these errors? Here is the URL of an Image.
backend.js:32 The shape of the input tensor ([null,50,50,32]) does not match the expectation of layer conv2d_1: [null,100,100,3] n @ backend.js:32 backend.js:32 The shape of the input tensor ([null,25,25,64]) does not match the expectation of layer conv2d_2: [null,100,100,3] n @ backend.js:32 backend.js:32 Possible Unhandled Promise Rejection (id: 0): RangeError: byte length of Float32Array should be a multiple of 4 RangeError: byte length of Float32Array should be a multiple of 4 at new Float32Array (<anonymous>) Here is my code:
async function getPrediction(url){ // setDisplayText("Loading Tensor Flow") setDisplayText("Loading Flow") await tf.ready() setDisplayText("Loading My model") const modelJson = require('../assets/model/model.json'); const modelWeights = require('../assets/model/group1-shard.bin'); const model = await tf.loadLayersModel(bundleResourceIO(modelJson, modelWeights)); setDisplayText("Fetching image"); const response =await fetch(url, {}, { isBinary : true}); setDisplayText("Getting image buffer") const imageData = await response.arrayBuffer() setDisplayText("Getting Image tensor") const imageTensor = imageToTensor(url); setDisplayText("Loading Result") const prediction = (await model.predict(imageTensor))[0]; setDisplayText("WOW") } function imageToTensor(rawImageData){ //Function to convert jpeg image to tensors const TO_UINT8ARRAY = true; const { width, height, data } = jpeg.decode(rawImageData, TO_UINT8ARRAY); // Drop the alpha channel info for mobilenet const buffer = new Uint8Array(width * height * 3); let offset = 0; // offset into original data for (let i = 0; i < buffer.length; i += 3) { buffer[i] = data[offset]; buffer[i + 1] = data[offset + 1]; buffer[i + 2] = data[offset + 2]; offset += 4; } return tf.tensor3d(buffer, [height, width, 3]); } https://stackoverflow.com/questions/66698901/rangeerror-byte-length-of-float32array-should-be-a-multiple-of-4-at-new-float32 March 19, 2021 at 04:48AM
没有评论:
发表评论