2

I am running Yolov5 Model in flask file in AWS EC2 instance, Getting this weird error "DetectMultiBackend has no input_detail attribute. I am using this to load the Yolov5 Pytorch Model

model = torch.hub.load('.', 'custom', path='best.pt', source='local',force_reload=True)

Here is code

try:
            for i in range(0,len(filenameArr)):
                img = filenameArr[i]
                #with graph.as_default():
                if(CNC_res[i]>0 and "VIA" in img ):
                    #img=Image.open(UPLOADEDIMG_PATH+img.split(("/")[-1]))
                    #file_name=Path(img.split("/")[-1]).name
                    #file_name = Path(img.split("/")[-1])
                    #results = model(file_name, size=224)
                   # pil_img=Image.open(UPLOADEDIMG_PATH + img.split('/')[-1])
                    #pil_img=Image.open(UPLOADEDIMG_PATH + img.split([-1]))
                   # pil_img = Image.open(UPLOADEDIMG_PATH + img)
                    path = "/var/www/html/ml_flask/images/Segmented/27-06-2022-14-49-08_VIA.png"
                    pil_img=cv2.imread(path)
                    #print(pil_img)
                   # file_name=pil_img.split('/')

                   # print("It has been passed")
                    results = model(pil_img, size= 224)
                    #pil_img.save('/var/www/html/temp.jpg')
                    #results = model(pil_img, size=224)
                    print("Model is loaded")
                    #for debugging
                    data = results.pandas().xyxy[0].name.to_json(orient="records")

                    name=results.pandas().xyxy[0].name
                    confidence=results.pandas().xyxy[0].confidence
                    os.chdir(save_folder)
                    #results.save()
                    results.print()

                    results.save(save_dir=save_folder)

                    dictionary ={
                        'file':img,
                        'save_imgpath':os.path.join(save_folder,file_name),
                        'name':list(name),
                        'confidence':float(confidence)
                    }
                    list1.append(dictionary)

                    final_dictionary={
                            'status':True,
                            'code':200,
                            'output':list1
                        }
                else:
                    final_dictionary={
                            'status':False,
                            'code':300,
                            'error':"VIA Images does not exist"
                        }


            if list1==[]:
                final_dictionary={
                            'status':False,
                            'code':300,
                            'error':"VIA Images does not exist"
                        }
                with open(Order_ID+'_result.json', 'w') as factor:
                    json.dump(final_dictionary, factor,indent=4)

            else:
                for i in list1:
                    assessment_result.append(i['name'])
                    confidence_result.append(i['confidence'])
                print(assessment_result)
                print(confidence_result)
                tmp = max(confidence_result)

                idx = confidence_result.index(tmp)

                majority=assessment_result[idx]

                print(assessment_result)
                print(confidence_result)
                tmp = max(confidence_result)

                idx = confidence_result.index(tmp)

                majority=assessment_result[idx]

                element='red'
                element_in_lists = False
                for list in assessment_result:
                    if element in list:
                        element_in_lists = 'red'
                    else:

                        #print(majority)
                        element_in_lists = majority

                print(element_in_lists)
                new_assessment= copy.copy(element_in_lists)
                new_assessment.append(str(qualityParamFLG))

                final_dictionary.update({"final_assessment":new_assessment})
                #print(final_dictionary)


                with open(Order_ID+'_result.json', 'w') as factor:
                    json.dump(final_dictionary, factor,indent=4)
        except:
            final_dictionary={
                    'status':False,
                    'code':300,
                    'error':"Something went wrong"
                }
            with open(Order_ID+'_result.json', 'w') as factor:
                json.dump(final_dictionary, factor,indent=4)

Here is the complete error

Exception on /image/get [GET]
Traceback (most recent call last):
File "/var/www/html/ml_flask/Models_Version_Jun_2022/ml_app.py", line 221, in getImage
results = model(pil_img, size=224)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1207, in __getattr__
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'DetectMultiBackend' object has no attribute 'input_details'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2077, in wsgi_app
     response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1525, in full_dispatch_request
     rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1523, in full_dispatch_request
     rv = self.dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/var/www/html/ml_flask/Models_Version_Jun_2022/ml_app.py", line 302, in getImage
  with open(Order_ID+'_result.json', 'w') as factor:
 PermissionError: [Errno 13] Permission denied: '5555_result.json'
Amit Yadav
  • 21
  • 2

1 Answers1

0

A quick search in the Yolov5 issues gave me this:

https://github.com/ultralytics/yolov5/issues/8354

Mike B
  • 2,136
  • 2
  • 12
  • 31