I have an issue with the following functions. "dummy_load_data" loads the dummy dataset.
#function of the module: model.tests.unet_test
def dummy_load_data(*args, **kwargs):
with tfds.testing.mock_data(num_examples=1):
return tfds.load(CFG['data']['path'], with_info=True)
#function of the class: model.tests.unet_test.UnetTest
@patch('model.unet.DataLoader.load_data')
def test_load_data(self, mock_data_loader):
mock_data_loader.side_effect = dummy_load_data
shape = tf.TensorShape([None, self.unet.image_size, self.unet.image_size, 3])
self.unet.load_data()
mock_data_loader.assert_called()
self.assertItemsEqual(self.unet.train_dataset.element_spec[0].shape, shape)
self.assertItemsEqual(self.unet.test_dataset.element_spec[0].shape, shape)
#functions (which are supposed to be tested with test_load_data function above) "load_data" and "_preprocess_data" of the class: model.unet.Unet
def load_data(self):
"""Loads and Preprocess data """
self.dataset, self.info = DataLoader().load_data(self.config.data)
self._preprocess_data()
def _preprocess_data(self):
""" Splits into training and test and set training parameters"""
train = self.dataset['train'].map(self._load_image_train, num_parallel_calls=tf.data.experimental.AUTOTUNE)
test = self.dataset['test'].map(self._load_image_test)
self.train_dataset = train.cache().shuffle(self.buffer_size).batch(self.batch_size).repeat()
self.train_dataset = self.train_dataset.prefetch(buffer_size=tf.data.experimental.AUTOTUNE)
self.test_dataset = test.batch(self.batch_size)
When I´m testing the function "load_data" of the class model.unet, I get the following error:
train = self.dataset["train"].map(map_func =self._load_image_train, num_parallel_calls=tf.data.AUTOTUNE) KeyError: 'train'