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

342
Views
TypeError: Cannot read properties of undefined (reading 'color')

I am trying to work on a Facemask Detection System. I have trained the Images and I have my model. I have also converted the generated model to the TensorflowJS json file.

I am having a problem implementing the tfjs model via a REACT application. I have my model being loaded successfully. As I have console.log it but i am having some issues drawing the rectangular bounding boxes for the detected class. The browser is throwing an error TypeError: Cannot read properties of undefined (reading 'color').

Here is my utilities.js file which is throwing the error.

// Define our labelmap
const labelMap = [
  {id: 1, name:'with mask', color:'red'},
  {id: 2, name:'no mask', color:'yellow'},
  {id: 3, name:'incorrect', color:'lime'},
]

// Define a drawing function
export const drawRect = (boxes, classes, scores, threshold, imgWidth, imgHeight, ctx)=>{
  for(let i=0; i<=boxes.length; i++){
      if(boxes[i] && classes[i] && scores[i]>threshold){
          // Extract variables
          const [y,x,height,width] = boxes[i]
          const text = classes[i]
          
          // Set styling
          ctx.strokeStyle = labelMap[text]["color"]
          ctx.lineWidth = 10
          ctx.fillStyle = 'white'
          ctx.font = '30px Arial'         
          
          // DRAW!!
          ctx.beginPath()
          ctx.fillText(labelMap[text]['name'] + ' - ' + Math.round(scores[i]*100)/100, x*imgWidth, y*imgHeight-10)
          ctx.rect(x*imgWidth, y*imgHeight, width*imgWidth/2, height*imgHeight/2);
          ctx.stroke()
      }
  }
}

I know this error has to do with the way the labelMap color variable is referenced. It is throwing the error probably because i am not referencing the color variable well. Also if this error is fixed. I will also be having another error thrown in labelMap[text]['name'] because the referencing is done same way.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
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!