1st approach: I am trying to make the below code work since morning. I have read many answers here in stackoverflow and tutorials on google about python, I have done 0 progress. Can you help me with this error:
Using TensorFlow backend.
Traceback (most recent call last):
File "source_code_modified.py", line 65, in <module>
dict1 = pickle.load(f1,encoding='bytes')
TypeError: file must have 'read' and 'readline' attributes
The code that explodes is this part:
class load_train_data:
os.open("/home/just_learning/Desktop/CNN/datasets/training_data/images", os.O_RDONLY)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
pass
class load_test_data:
os.open("/home/just_learning/Desktop/CNN/datasets/test_data/images",os.O_RDONLY)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
pass
with load_train_data() as f1:
dict1 = pickle.load(f1,encoding='bytes')
2nd approach:
Ok, I did that, the error is:
Using TensorFlow backend.
Traceback (most recent call last):
File "source_code_modified.py", line 74, in <module>
with open_train_data() as f1:
File "source_code_modified.py", line 47, in open_train_data
return open('/home/just_learning/Desktop/CNN/datasets/training_data/images','rb')
IsADirectoryError: [Errno 21] Is a directory: '/home/just_learning/Desktop/CNN/datasets/training_data/images'
And the code explodes on these points:
def open_train_data():
return open('/home/just_learning/Desktop/CNN/datasets/training_data/images','rb') <--- explodes here
def open_test_data():
return open('/home/just_learning/Desktop/CNN/datasets/test_data/images','rb')
with open_train_data() as f1:
dict1 = pickle.load(f1) <--- explodes here
3rd approach: I found this: "IsADirectoryError: [Errno 21] Is a directory: " It is a file
and I changed the code to this:
def open_train_data():
return os.listdir('/home/just_learning/Desktop/CNN/datasets/training_data/images')
def open_test_data():
return os.listdir('/home/just_learning/Desktop/CNN/datasets/test_data/images')
with open_train_data() as f1: <-------------- explodes here
dict1 = pickle.load(f1) #,encoding='bytes')
and the error is this:
Using TensorFlow backend.
Traceback (most recent call last):
File "source_code_modified.py", line 74, in <module>
with open_train_data() as f1:
AttributeError: __enter__
and this error I solved it by searching in github/google and was the result depicted on the first approach, that I have posted above...