0

I have a YOLO pre-trained model placed in Google Drive. I want to read that model in my local Python IDE and perform predictions. I have something as follows:

import cv2
import requests

urlsrc='https://drive.google.com/file/d/1-Mj6c9ctPoYx3akhvqPJojSl3T-ihey_/view?usp=sharing'
rsrc=requests.get(urlsrc)
net = cv2.dnn.readNetFromDarknet('files//yolov3-spp.cfg', rsrc)

But this does not work. readNetFromDarknet is not able to read the rsrc file. I do not want to download the Model, instead I just want to read it from Google Drive. Any idea of what I am doing wrong. Thanks.

Junaid
  • 159
  • 1
  • 15
  • Maybe this will help you: https://stackoverflow.com/a/59476845/13597101 – 0x5961736972 Nov 17 '21 at 08:47
  • I don't want to download the file. I want to read it from Google Drive. Made the necessary edits to the question – Junaid Nov 17 '21 at 08:55
  • I don't think that would be possible, if you want to read a file, you have to download it, even if temporarily. You can try using your model on Google Colab. – 0x5961736972 Nov 17 '21 at 09:08

1 Answers1

0

If you do type(rsrc) you will see that rsrc has the type requests.models.Response. You can get the contents of such a response with:

>>> rsrc.text
<!DOCTYPE html><html><head><meta name="google" content="notranslate"><meta http-equiv="X-UA-Compatible" content="IE=edge;"><style nonce="UHrvWsqb8JI0negLQeFQ4A">@font-face{font-family:'Roboto';font-style:italic;font-weight:400;src:url(//fonts.gstatic.com/s/roboto/v18/KFOkCnqEu92Fr1Mu51xIIzc.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:normal;font-weight:300;src:url(//fonts.gstatic.com/s/roboto/v18/KFOlCnqEu92Fr1MmSU5fBBc9.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:normal;font-weight:400;src:url(//fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxP.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:normal;font-weight:700;src:url(//fonts.gstatic.com/s/roboto/v18/KFOlCnqEu92Fr1MmWUlfBBc9.ttf)format('truetype');}</style><meta name="referrer" content="origin"><title>yolov3_last.weights - Google Drive</title><meta property="og:title" content="yolov3_last.weights"><meta property="og:type" content="article"><meta property="og:site_name" content="Google Docs">
[...]</script></body></html>

So you see that you downloaded a html page, but not the contents of your yolov3_last.weights file itself.

You wil need to use a library like PyDrive to connect to Google Drive and download your file, see here for a tutorial. Or you can use the code in this answer.

BioGeek
  • 21,897
  • 23
  • 83
  • 145
  • Thanks for responding. Actually, I don't want to download the file. I want to read it from Google Drive. Any idea on how to achieve it. – Junaid Nov 17 '21 at 08:52
  • `cv2.dnn.readNetFromDarknet` expects a path to a file, it doesn't know how to read from Google Drive. So you will need to download the file locally. – BioGeek Nov 17 '21 at 08:57
  • It means it is impossible? Can't be done in anyway?? – Junaid Nov 17 '21 at 08:59
  • what if we store the Google Drive path to a temporary variable and then pass it to `readNetFromDarkNet`. Can it be done?? – Junaid Nov 17 '21 at 09:00
  • A Google Drive path is not the same as a path to a file on your local file system, Google Drive requires authentication with a token and so on and `readNetFromDarkNet` doesn't know how to do that. Why are you so opposed to just downloading the file? – BioGeek Nov 17 '21 at 09:16
  • 1
    I have created an application that lets the user predict 80 classes. I am deploying this app on free servers, but the free server won't allow me to upload file greater than 100 MB. The model here is 237 MB. So, I thought this is the way to go to upload file on Google Drive and read it from there. Any free server provider that you can guide that helps me upload files greater than 100 MB – Junaid Nov 17 '21 at 09:23
  • It's probably better asking a new question describing your specific situation and constraints. More people would see that new question then this comment thread. – BioGeek Nov 17 '21 at 09:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/239305/discussion-between-junaid-and-biogeek). – Junaid Nov 17 '21 at 09:37