So when I type:
pic = Path(test_hang.loc[879:880, 'location'].values[0])
image = self.train_transform(Image.open(pic))
in the console, I get a transformed tensor back.
When I run what is in my custom data set, I get the following error:
File "<ipython-input-23-9f4883f14d32>", line 175, in <module>
for image, label, policy, categorical_data, numerical_data in test_loader_roof:
File "C:\Users\JORDAN.HOWELL.GITDIR\AppData\Local\Continuum\anaconda3\envs\torch_env\lib\site-packages\torch\utils\data\dataloader.py", line 345, in __next__
data = self._next_data()
File "C:\Users\JORDAN.HOWELL.GITDIR\AppData\Local\Continuum\anaconda3\envs\torch_env\lib\site-packages\torch\utils\data\dataloader.py", line 385, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "C:\Users\JORDAN.HOWELL.GITDIR\AppData\Local\Continuum\anaconda3\envs\torch_env\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "C:\Users\JORDAN.HOWELL.GITDIR\AppData\Local\Continuum\anaconda3\envs\torch_env\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "<ipython-input-23-9f4883f14d32>", line 32, in __getitem__
pic = Path(self.image_frame.loc[idx, 'location'].values[0])
AttributeError: 'str' object has no attribute 'values'
Here is my getitem
once more:
class image_Dataset(Dataset):
'''
image class data set
'''
def __init__(self, data, transform = None):
'''
Args:
------------------------------------------------------------
data = dataframe
image = column in dataframe with absolute path to the image
label = column in dataframe that is the target classification variable
numerical_columns = numerical columns from data
categorical_columns = categorical columns from data
policy = ID variable
'''
self.image_frame = data
self.transform = transform
def __len__(self):
return len(self.image_frame)
def __getitem__(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
label = self.image_frame.loc[idx, 'target']
label = np.asarray(label)
pic = Path(self.image_frame.loc[idx, 'location'].values[0])
image = self.transform(Image.open(pic))
policy = self.image_frame.loc[idx, 'policy']
policy = np.asarray(policy)
numerical_data = self.image_frame.loc[idx, numerical_columns]
numerical_data = torch.tensor(numerical_data, dtype = torch.float)
for category in non_loca_cat_columns:
self.image_frame[category] = self.image_frame[category].astype('category')
self.image_frame[category] = self.image_frame[category].astype('category').cat.codes.values
categorical_data = self.image_frame.loc[idx, non_loca_cat_columns]
categorical_data = np.asarray(categorical_data)
return image, label, policy, categorical_data , numerical_data
The image seems to be working in the console but no the custom data set. Is the index right under the getitem
coded correct?