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
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: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.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.
Most likely causes:
ls <full path to filename>
and see what you get.sudo ls <full path to filename>
and see which user and group own the file.