Я изучаю глубокое обучение на веб-сайте kaggle. Я пытаюсь создать нейронную глубокую сеть, но на одном из первых шагов мне нужно выполнить предварительную обработку, и из-за того, что идентификатор изображения и идентификатор класса являются двумя отдельными объектами, их легче разделить на два столбца, но возникла проблема с этим. Мой код:
make_submission = False
load_pretrained_model = True
save_model = True
train_dir = './Desktop/severstal-steel-defect-detection/'
pretrained_model_path = './Desktop/severstal-pretrained-model/ResUNetSteel_z.h5'
model_save_path = './ResUNetSteel_w800e50_z.h5'
train_image_dir = os.path.join(train_dir, 'train_images')
train_df = pd.read_csv(os.path.join(train_dir, 'train.csv')).fillna(-1)
train_df['ImageId'] = train_df['ImageId_ClassId'].apply(lambda x: x.split('_')[0])
train_df['ClassId'] = train_df['ImageId_ClassId'].apply(lambda x: x.split('_')[1])
train_df['ClassId_EncodedPixels'] = train_df.apply(lambda row: (row['ClassId'], row['EncodedPixels']), axis = 1)
grouped_EncodedPixels = train_df.groupby('ImageId')['ClassId_EncodedPixels'].apply(list)
После применения этого кода я получаю такую ключевую ошибку:
KeyError Traceback (most recent call last)
~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2645 try:
-> 2646 return self._engine.get_loc(key)
2647 except KeyError:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'ImageId_ClassId'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-28-e1402e10fe66> in <module>
2 train_df = pd.read_csv(os.path.join(train_dir, 'train.csv')).fillna(-1)
3 # image id and class id are two seperate entities and it makes it easier to split them up in two columns
----> 4 train_df['ImageId'] = train_df['ImageId_ClassId'].apply(lambda x: x.split('_')[0])
5 train_df['ClassId'] = train_df['ImageId_ClassId'].apply(lambda x: x.split('_')[1])
6 # lets create a dict with class id and encoded pixels and group all the defaults per image
~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2798 if self.columns.nlevels > 1:
2799 return self._getitem_multilevel(key)
-> 2800 indexer = self.columns.get_loc(key)
2801 if is_integer(indexer):
2802 indexer = [indexer]
~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
-> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 if indexer.ndim > 1 or indexer.size > 1:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
* KeyError: 'ImageId_ClassId'
Кто-нибудь знает, как исправить такую ошибку и двигаться дальше?
train_df.head () дает мне такие данные: введите описание изображения здесь