getting an Error. FileNotFoundError: [Errno 2] No such file or directory: 'data_images\\1 (1).jpg' - computer-vision

I'm working on object detection with YOLOV5. the last, when I saved the images and labels in the text in the folder, I got an Error. FileNotFoundError: [Errno 2] No such file or directory: 'data_images\\1 (1).jpg'
def save_data(filename, folder_path, group_obj):
src = os.path.join('data_images',filename)
dst = os.path.join(folder_path,filename)
move(src,dst) # move image to the destination folder
# save the labels
text_filename = os.path.join(folder_path, os.path.splitext(filename)[0]+'.txt')
group_obj.get_group(filename).set_index('filename').to_csv(text_filename,sep=' ',index=False,header=False)
How to solve. I checked the data is present.

Related

IsADirectoryError: [Errno 21] Is a directory: '/app' when deploying on Heroku

I've been having trouble deploying my Flask app on Heroku. My current problem is Heroku can't locate the files in my static folder. After trying suggestions on SO, I am now getting this error:
with open(file_dir, encoding="utf-8") as f:
IsADirectoryError: [Errno 21] Is a directory: '/app'
Here's one of the suggestions I found to help Heroku find the encouragement.txt file:
# Absolute path to the file
file_dir = os.path.dirname(os.path.abspath('encouragement.txt'))
# Absolute path to this file's root directory
parent_dir = os.path.join(file_dir, os.pardir)
app_dir = os.path.join(parent_dir, '/app')
The '/app' was added because one of the posts mentioned that Heroku had an app directory as the parent directory, so instead of 'static/encouragement.txt', it would be 'app/static/encouragement.txt'. The same error was given with and without joining '/app'.
Here's where the error came from:
#app.route("/")
def index():
# Read data from the file as str
with open(file_dir, encoding="utf-8") as f:
messages = f.read()
I tried using heroku bash command to check the file system structure and confirm the app directory but the command executed and returned blank.
My files are organized as follow:
MyProject
> static
> encouragement.txt
app.py
Not sure if it's needed, but I'm using windows. Thank you.
Update:
I tried adding index.php and composer.json as a couple tutorials suggested. They didn't work for the txt files; not sure if they helped with the other static files though. Not the best solution, but I ended up just copying and pasting all the txt content to my app.py.
I ran into this issue today after doing a bit of "clean-up" to my environment variables/configs. The issue is you're trying to open a directory itself as if it were a file, which causes the error. I recommend the answer in this article (as shown).
import os
# path to your file
file_name = r'/app/static/encouragement.txt'
print(os.path.isfile(file_name))
with open(file_name, 'r', encoding='utf-8') as f:
lines = f.readlines()
print(lines)

AWS: FileNotFoundError: [Errno 2] No such file or directory

I am trying to download a file to sagemaker from my S3 bucket.
the path of the file is
s3://vemyone/input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm
The path of that file is stored as a list element at train_fns[0].
the value of train_fns[0] is
input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm
I used the following code:
s3 = boto3.resource('s3')
bucketname = 'vemyone'
s3.Bucket(bucketname).download_file(train_fns[0][:], train_fns[0])
but I get the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm.5b003ba1'
I notice that some characters have appended itself at the end of the path.
how do I solve this problem?
please see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Bucket.download_file
by the doc, first argument is file key, second argument is path for local file:
s3 = boto3.resource('s3')
bucketname = 'vemyone'
s3.Bucket(bucketname).download_file(train_fns[0], '/path/to/local/file')

lmdb.open wont create new file

I'm learning about deep learning and start to follow a tutorial.
At the frist part when I try to run:
train_lmdb = '~/deeplearning-cats-dogs-tutorial/input/train_lmdb'
validation_lmdb = '~/deeplearning-cats-dogs-tutorial/input/validation_lmdb'
train_data = [img for img in glob.glob("../input/train/*jpg")]
test_data = [img for img in glob.glob("../input/test1/*jpg")]
#Shuffle train_data
random.shuffle(train_data)
print 'Creating train_lmdb'
in_db = lmdb.open(train_lmdb, map_size=int(1e12))
I got the erro:
OSError: [Errno 2] No such file or directory: '~/deeplearning-cats-dogs-tutorial/input/train_lmdb'
lmdb.open was supposed to create the file, right? I dont understand why it its trying to open it.
I just replace "~/" with "/home/user/" and it is working fine

IOError: [Errno 13] Permission denied using Python, but I can't see why?

I have been coding an App that needs to write some lines to a directory in Linux, but the output returned keeps showing the following error:
File "/home/p4user/flexclone/main/demo/flex.py", line 1305, in p4config
fh = open(path + "/.p4config", "w")
IOError: [Errno 13] Permission denied: '/p4flex/rickclone36/.p4config'
The user does have permission for this directory, and I have tried various filenames which exists and do not exist yet. I have been spinning around for the past 36 hours and this is a roadblock. Here is the code snippet causing the issue (I have throughly traced through the code snipped too):
def p4config(self, path, client):
p4config = os.getenv('P4CONFIG', '.p4config')
p4port = self.call.getPort()
p4user = self.call.getUser()
fh = open(path + "/.p4config", "w")
if fh:
The error occurs is seen at the fh=open() line. Does anyone have suggestions, or indications why the block may be occurring? When as a user I just touch files, it's all fine.
Thanks

Zipping a file from a directory and placing it in another Directory

I am trying to set up a program to put my minecraft server world into a zip and place it into another directory on another drive (/media/500gb/MinecraftWorldBackups)
But I keep getting this error
Although the folder doesn't contain a folder or file called 'h'
What do I need to do to fix this I believe it is due to file and folder?
#!/usr/bin/env python
import time, zipfile
while True:
FileName = 'MinecraftBackup_' + str(int(time.time()))
Path = '/home/bertie/Desktop/FeedTheBeastServer/world/'
print(FileName)
Zip = zipfile.ZipFile('/media/500gb/MinecraftWorldBackups/'+FileName+'.zip','w')
for each in Path:
print(each)
try: Zip.write(Path + each)
except IOError: None
Zip.Close()
print('Done')
time.sleep(60)