tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

Error: Requested texture size [-1536x512] is invalid

Open mkaufmann84 opened this issue 3 years ago • 2 comments

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows
  • TensorFlow.js installed from (npm or script link): script link
  • TensorFlow.js version (use command below): 3.9.0
  • Browser version: Chrome 94.0.4606.54
  • Tensorflow.js Converter Version: Most recent

Describe the current behavior I am running two object detection models. The first locates where a sudoku board is in an image, and the second model locates where each grid is on the sudoku board. The first model works fine. However, when I call executeAsync to the model to find where each grid is on sliced tensor (This comes from the predictions made from the first model) I get an error. So the first object detection models works, but upon calling the second object detection model I get the error : tf.min.js:17 Uncaught (in promise) Error: Requested texture size [-1536x512] is invalid. at tf.min.js:17 at jX (tf.min.js:17) at tf.min.js:17 at e.t.createFloat32MatrixTexture (tf.min.js:17) at e.t.acquireTexture (tf.min.js:17) at t.n.acquireTexture (tf.min.js:17) at t.n.uploadToGPU (tf.min.js:17) at t.n.runWebGLProgram (tf.min.js:17) at Object.kernelFunc (tf.min.js:17) at n (tf.min.js:17)

Describe the expected behavior It is should work exactly how the first model works. Its weird because the first model is able to make predictions but for the second model it fails.

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/CodePen/any notebook.--This is the image I was loading to the html input

test_img

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

Code: HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TF JS example</title>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
</head>
<body>
<form method="POST" action="/upload" enctype="multipart/form-data">
  <p><input type="file" id="file1" name="file"></p>
</form>
<canvas style="border: 10px solid black " id="canvas"  >
  <img id ="display" width = "..."  height="..." >
</canvas>

<script src="main.js"></script>
    
</body>
</html>

main.js:

async function load() {
  const model = await tf.loadGraphModel('https://big-g.s3.us-east.cloud-object-storage.appdomain.cloud/model.json');
    return model;
  };
async function load_s(){
  const model_s = await tf.loadGraphModel('https://small-g.s3.us-east.cloud-object-storage.appdomain.cloud/model.json');
  return model_s

}
async function load_class(){
  const model_class = await tf.loadGraphModel("https://classy.s3.us-east.cloud-object-storage.appdomain.cloud/model.json");
  return model_class

}


var model = load();
var model_s = load_s();
//var model_class =load_class();

console.log("laoded")
document.querySelector('input').addEventListener('change', function() {
  console.log("change")
  var reader = new FileReader();
  const fileInput = document.getElementById("file1").files[0];
  console.log(fileInput);


  readerDim = new FileReader();
  readerDim.readAsDataURL(fileInput);

  readerDim.onload = function (e) {

    //Initiate the JavaScript Image object.
    var image = new Image();

    //Set the Base64 string return from FileReader as source.
    image.src = e.target.result;

    //Validate the File Height and Width.
    image.onload = function () {
      var height = this.height;
      var width = this.width;
      console.log(width,height);//width,height  
      var a = tf.browser.fromPixels(image);
      //convert image into 3 channel grayscale
      var g_scale =a.mean(2).expandDims(-1);
      var a = tf.image.grayscaleToRGB(g_scale).cast("int32");

      a=a.expandDims();

      model.then(model => {
      
      async function pred() {
        console.log('Start');
        const result = await model.executeAsync(a);
        console.log('End')
        //console.log( await result[6].array());
        //const classes = await result[2].array();
        //const accuracy = await result[4].array();
        const boxes = await result[6].array(); //y,x,height,width
        
        //Time to draw 
        const canvas = document.querySelector('#canvas');
        const ctx = canvas.getContext('2d');
        //resize

        canvas.height = image.height;
        canvas.width= image.width;
  
       // ctx.drawImage(image,0,0);
       tf.browser.toPixels(a.squeeze(),canvas);
        const [y,x,height,width] =boxes[0][0];
        //console.log(y);
        console.log("drawing...");
        const xc = Math.round(x*image.width);
        const yc = Math.round(y*image.height);
        const x2c = Math.round(width*image.width);
        const y2c = Math.round(height*image.height);

        console.log(xc,yc,x2c ,y2c);//x1, y1, x2, y2, not height or width
        //ctx.rect(xc, yc, x2c-xc, y2c-yc);
        //ctx.stroke();
        console.log(a.shape)
        sliced = a.slice([0,yc,xc,0],[1,y2c-yc,x2c-xc,3] );
        console.log(sliced)
        //await new Promise(r => setTimeout(r, 1000));
        //ctx.clearRect(0, 0, canvas.width, canvas.height)
        tf.browser.toPixels(sliced.squeeze(),canvas);


        model_s.then(model_s =>{
          async function small_g(sliced){
            console.log("predicting small",sliced);
            const result_s = await model_s.executeAsync(sliced);
            return result_s
          }
          const result_s = small_g(sliced);
          console.log(result_s);

        });
        };
      console.log('Predicting')
      var box =  pred();

      });

    };
  };
}, false);

Logs:

change main.js:27 File {name: 'test_img.png', lastModified: 1631819149502, lastModifiedDate: Thu Sep 16 2021 15:05:49 GMT-0400 (Eastern Daylight Time), webkitRelativePath: '', size: 259253, …} main.js:45 1268 784 main.js:104 Predicting main.js:56 Start main.js:58 End main.js:76 drawing... main.js:82 117 81 660 624 main.js:85 (4) [1, 784, 1268, 3] main.js:87 e {kept: false, isDisposedInternal: false, shape: Array(4), dtype: 'int32', size: 884547, …} main.js:95 predicting small e {kept: false, isDisposedInternal: false, shape: Array(4), dtype: 'int32', size: 884547, …} main.js:100 Promise {} tf.min.js:17 Uncaught (in promise) Error: Requested texture size [-1536x512] is invalid. at tf.min.js:17 at jX (tf.min.js:17) at tf.min.js:17 at e.t.createFloat32MatrixTexture (tf.min.js:17) at e.t.acquireTexture (tf.min.js:17) at t.n.acquireTexture (tf.min.js:17) at t.n.uploadToGPU (tf.min.js:17) at t.n.runWebGLProgram (tf.min.js:17) at Object.kernelFunc (tf.min.js:17) at n (tf.min.js:17) (anonymous) @ tf.min.js:17 jX @ tf.min.js:17 (anonymous) @ tf.min.js:17 t.createFloat32MatrixTexture @ tf.min.js:17 t.acquireTexture @ tf.min.js:17 n.acquireTexture @ tf.min.js:17 n.uploadToGPU @ tf.min.js:17 n.runWebGLProgram @ tf.min.js:17 kernelFunc @ tf.min.js:17 n @ tf.min.js:17 (anonymous) @ tf.min.js:17 t.scopedRun @ tf.min.js:17 t.runKernelFunc @ tf.min.js:17 t.runKernel @ tf.min.js:17 stridedSlice_ @ tf.min.js:17 stridedSlice__op @ tf.min.js:17 (anonymous) @ tf.min.js:17 (anonymous) @ tf.min.js:17 (anonymous) @ tf.min.js:17 t.scopedRun @ tf.min.js:17 t.tidy @ tf.min.js:17 qI @ tf.min.js:17 (anonymous) @ tf.min.js:17 pW @ tf.min.js:17 p @ tf.min.js:17 t.processStack @ tf.min.js:17 (anonymous) @ tf.min.js:17 c @ tf.min.js:17 (anonymous) @ tf.min.js:17 (anonymous) @ tf.min.js:17 bv @ tf.min.js:17 o @ tf.min.js:17 async function (async) small_g @ main.js:96 (anonymous) @ main.js:99 Promise.then (async) pred @ main.js:93 async function (async) pred @ main.js:57 (anonymous) @ main.js:105 Promise.then (async) image.onload @ main.js:53 load (async) readerDim.onload @ main.js:42 load (async) (anonymous) @ main.js:33 Show 2 more frames

mkaufmann84 avatar Sep 25 '21 20:09 mkaufmann84

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Sep 25 '21 20:09 google-ml-butler[bot]

Any tensor I use even a random one gives this error. I tried recreating the model from the tfjs-converter but that didn't work. I think the error is that this is a center-net model. so I will just use a different model

mkaufmann84 avatar Sep 27 '21 12:09 mkaufmann84

Hi, @mkaufmann84

Apologize for the delayed response and we're re-visiting our older issues and checking whether those issues got resolved or not as of now so May I know are you still looking for the solution or your issue got resolved ?

If issue still persists after trying with latest version of TFJs please let us know with error log and code snippet to replicate the same issue from our end ?

Could you please confirm if this issue is resolved for you ? Please feel free to close the issue if it is resolved ? Thank you!

gaikwadrahul8 avatar May 23 '23 07:05 gaikwadrahul8

I think what I did is I used a different model. Idc about this issue anymore u can resolve it

On Tue, May 23, 2023 at 3:30 AM gaikwadrahul8 @.***> wrote:

Hi, @mkaufmann84 https://github.com/mkaufmann84

Apologize for the delayed response and we're re-visiting our older issues and checking whether those issues got resolved or not as of now so May I know are you still looking for the solution or your issue got resolved ?

If issue still persists after trying with latest version of TFJs please let us know with error log and code snippet to replicate the same issue from our end ?

Could you please confirm if this issue is resolved for you ? Please feel free to close the issue if it is resolved ? Thank you!

— Reply to this email directly, view it on GitHub https://github.com/tensorflow/tfjs/issues/5664#issuecomment-1558694285, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE7SXDSIG3JCL4HS5FVWJNLXHRRQTANCNFSM5EX6UGBQ . You are receiving this because you were mentioned.Message ID: @.***>

mkaufmann84 avatar May 23 '23 13:05 mkaufmann84

Hi, @mkaufmann84

Apologize for the delayed response and Good to hear that your problem got solved by using different model. Could you please confirm if this issue is resolved for you ? Please feel free to close the issue if it is resolved ? Thank you!

gaikwadrahul8 avatar Jun 05 '23 16:06 gaikwadrahul8

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Jun 05 '23 17:06 google-ml-butler[bot]

I same error: Unhandled Promise Rejection: Error: Requested texture size [0x0] is invalid. image

hktalent avatar Jul 19 '23 05:07 hktalent