Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
Tensorflow.js selecting specific part of Tensor

In javascript, I'm successfully converting a RGB video frame from my webcam to a tensor using TensorFlowJS's function tf.browser.fromPixels(). Now, I'd like to select only a part of this tensor according to values I've previously obtained. specifically a rectangle from the video frame with coordinates [x1,y1,x2,y2] but I'm struggling to do so using TFJS function tf.stridedSlice(), because I can't figure out how the function's parameters works.

For example, the video frame tensor has shape [480,640,3], and I'd like to cut a whole rectangle from it with shape [270,202,3], of which I know the upper left (x1,y1) and bottom right (x2,y2) coordinates, how can I achieve this in some manner like:

tensorImg     = tf.browser.fromPixels(videoFrame);
tensorCropped = tf.stridedSlice(tensorImg,[x1,y1],[x1+x2,y1+y2]); ???

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This should work:

const cropBox = [[0.15, 0.15, 0.85, 0.85]]; // top,left,bottom,right in range 0..1 (not in pixel range)
const outputSize = [200, 200]; // how large we want output to be
const resize = tf.image.cropAndResize(inputTensor, cropBox, [0], outputSize);

Note that cropBox itself is array of arrays and then second param says which entry to actually use [0])

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!