Well thank you
!
I just pulled the file system line from another Pytorch forum question that seemed to have a similar issue.
This is all the code that’s running and causing the errors at this point. I’m not opening files in any other part of the code right now.
Annotations.txt has data that looks like:
1, 205, 5.976959, 9.223372E+18, 13.00167, 9.223372E+18, 9.223372E+18, 2.116816, 3.283184, 9.223372E+18
1, 210, 2.403473, 9.223372E+18, 13.00638, 9.223372E+18, 9.223372E+18, 2.744155, 2.655845, 9.223372E+18
with each newline being a new input vector.
And just to be safe I’ve moved the targets outside of the folder I’m loading from so I only call images.
so the folders are now
…/sample_data2/images/image files.bmp
…/sample_data/annotations.txt
data_loc = '/Users/markmartinez/Downloads/sample_data2/'
torch.multiprocessing.set_sharing_strategy('file_system')
"""
Getting the targets
"""
with open('/Users/markmartinez/Downloads/sample_data/annotations.txt') as f:
content = f.readlines()
#makes each one a float
targets = [x.split(',') for x in content]
for a in targets:
for ind,val in enumerate(a):
#a[ind] = int(float(val))
a[ind] = float(val)
targets = torch.FloatTensor(targets)
def load_file(file,index):
temp = Image.open(file)
keep = temp.copy()
temp.close()
data = tuple(keep,targets[index])
return data
class MyDataset(Data.Dataset):
def __init__(self, data_files):
self.data_files = sorted(data_files)
def __getitem__(self, index):
return load_file(self.data_files[index],index)
def __len__(self):
return len(self.data_files)
set_test = MyDataset(data_loc)
loader = Data.DataLoader(set_test,batch_size = BATCH_SIZE, num_workers=8)
and this is the error I’m getting
Traceback (most recent call last):
File "/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2847, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-53-eb2d61b6aaa1>", line 7, in <module>
with open('/Users/markmartinez/Downloads/sample_data/annotations.txt') as f:
OSError: [Errno 24] Too many open files: '/Users/markmartinez/Downloads/sample_data/annotations.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 1795, in showtraceback
stb = value._render_traceback_()
AttributeError: 'OSError' object has no attribute '_render_traceback_'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda/lib/python3.5/site-packages/IPython/core/ultratb.py", line 1092, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
File "/anaconda/lib/python3.5/site-packages/IPython/core/ultratb.py", line 312, in wrapped
return f(*args, **kwargs)
File "/anaconda/lib/python3.5/site-packages/IPython/core/ultratb.py", line 347, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "/anaconda/lib/python3.5/inspect.py", line 1454, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
File "/anaconda/lib/python3.5/inspect.py", line 1411, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
File "/anaconda/lib/python3.5/inspect.py", line 671, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
File "/anaconda/lib/python3.5/inspect.py", line 700, in getmodule
file = getabsfile(object, _filename)
File "/anaconda/lib/python3.5/inspect.py", line 684, in getabsfile
return os.path.normcase(os.path.abspath(_filename))
File "/anaconda/lib/python3.5/posixpath.py", line 362, in abspath
cwd = os.getcwd()
OSError: [Errno 24] Too many open files```