skip to Main Content

I have the following lines of code:

model_weight = "/home/Object-Detection-and-location-RealsenseD435/DNN/engine/yolov3.weights"
model_cfg = "/home/Object-Detection-and-location-RealsenseD435/DNN/engine/yolov3.cfg"
model_classname= "/home/Object-Detection-and-location-RealsenseD435/DNN/engine/classname.txt"

And when I try running it, I get the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/home/Object-Detection-and-location-RealsenseD435/DNN/engine/classname.txt'

The file that’s causing the error exists. I can access it via the File Application, but not through code.

Both Terminator and PyCharm give the same error messages. I am using Ubuntu 22.04.

3

Answers


  1. If the other paths exist, it means that classname.txt may not be in the intended directory. You can try checking that through the code by doing:

    os.listdir("/home/Object-Detection-and-location-RealsenseD435/DNN/engine/")
    

    This will show you the contents of this directory, to verify if it exists and is visible at that location.

    Another thing: It may be easier to not use an absolute path and instead access the the files from your current working directory.

    EDIT:

    As pointed out in the comments by Barmar, Linux file system is case-sensitive. Make sure that your file path and file name classname.txt is exactly correct.

    Login or Signup to reply.
  2. Could you try moving ‘classname.txt’ into the same parent directory as you python file. From there just call upon by file name Ex:

    model_classname = ‘classname.txt’

    Or you can try to put the full file path inside the model_classname variable.

    Login or Signup to reply.
  3. Most likely causes:

    1. File doesn’t actually exist. Just run ls <full path to filename> and see what you get.
    2. File exists but the effective user of the script doesn’t have permissions to access it. run sudo ls <full path to filename> and see which user and group own the file.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search