Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
TensorFlowJS says (Error: Requested texture size [4327x4328] greater than WebGL maximum on this browser / GPU [4096x4096])

When I attempt to use model.predict(tensor) to get a result from the model, I get the error stated in the title. I know the WebGL texture size is a hardware limitation that cannot be overcome, so I was wondering if there are any ways to reduce the texture size of a tensorflow model or somehow do it in tensorflowjs. I tried using the Web Assembly backend, but it doesn't work very well for my use cause.

Are there any pointers that I could use to manage the texture size of my model?

Thanks in advance, and any help would be appreciated. Below is my tensorflowjs code.

import { Dimensions } from 'react-native';
import * as ImageManipulator from 'expo-image-manipulator';
import * as tf from '@tensorflow/tfjs';
import { bundleResourceIO, decodeJpeg } from '@tensorflow/tfjs-react-native';
import { Base64Binary } from '../utils/b64';
import { image } from '@tensorflow/tfjs';
import * as FileSystem from 'expo-file-system';

const results = ['Not Melanoma', 'Melanoma'];

const transformImageToTensor = async (uri) => {
  //.ts: const transformImageToTensor = async (uri:string):Promise<tf.Tensor>=>{
  //read the image as base64
  const img64 = await FileSystem.readAsStringAsync(uri, {
    encoding: FileSystem.EncodingType.Base64,
  });
  const imgBuffer = tf.util.encodeString(img64, 'base64').buffer;
  const raw = new Uint8Array(imgBuffer);
  let imgTensor = decodeJpeg(raw);
  const scalar = tf.scalar(255);
  //resize the image
  imgTensor = tf.image.resizeNearestNeighbor(imgTensor, [300, 300]);
  //normalize; if a normalization layer is in the model, this step can be skipped
  const tensorScaled = imgTensor.div(scalar);
  //final shape of the rensor
  const img = tf.reshape(tensorScaled, [-1, 50, 50, 1]);
  return img;
};

const predict = async (model, tensor) => {
  const output = await model.predict(tensor);
  return output.dataSync();
};

export const process = async (image, setDiagnosis, setLoading) => {
  console.log('inside process btw');
  await tf.ready();
  const modelJSON = require('../assets/models/model.json');
  const modelWeights = require('../assets/models/group1-shard1of1.bin');
  const model = await tf.loadLayersModel(
    bundleResourceIO(modelJSON, modelWeights)
  );
  console.log('model loaded');

  const tensor = await transformImageToTensor(image);

  console.log('converted to tensor');
  const prediction = await predict(model, tensor);

  console.log('converted to tensor and prediction happened');
  const highestPrediction = prediction.indexOf(
    Math.max.apply(null, prediction)
  );

  console.log(highestPrediction);
  setDiagnosis(results[highestPrediction]);
  setLoading(false);
};

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda