def __init__(self, config):
        """
        Args:
            config: config file of the current model
        """

        self.config = config
        # load data here
        d = DataLoader(self.config)
        # Get the filenames and labels
        self.filenames, self.labels = d.get_sub_dataset(self.config.image_size)
        # Create the Dataset using Tensorflow Data API
        self.dataset = tf.data.Dataset.from_tensor_slices(self.filenames)
        # Apply parse function to get the numpy array of the images
        self.dataset = self.dataset.map(
            map_func=self._parse_function,
            num_parallel_calls=self.config.num_parallel_calls)
        # Shuffle the dataset
        #self.dataset = self.dataset.shuffle(self.config.buffer_size)
        # Repeat the dataset indefinitely
        self.dataset = self.dataset.repeat(self.config.num_epochs)
        # Applying prefetch to increase the performance
        # Prefetch the next 10 batches
        self.dataset = self.dataset.prefetch(buffer_size=10 *
                                             config.batch_size)
        # Apply batching
        self.dataset = self.dataset.batch(config.batch_size)
        self.iterator = self.dataset.make_initializable_iterator()
        self.image = self.iterator.get_next()
Beispiel #2
0
 def __init__(self):
     # self.config = config
     # load data here
     d = DataLoader("./data")
     # Get the filenames and labels
     self.filenames, self.labels = d.get_sub_dataset(28)
     #assert len(self.filenames) == len(self.labels)
     # Create the Dataset using Tensorflow Data API
     self.dataset = tf.data.Dataset.from_tensor_slices(self.filenames)
     # Apply parse function to get the numpy array of the images
     self.dataset = self.dataset.map(self._parse_function)
     # Shuffle the dataset
     self.dataset = self.dataset.shuffle(self.filenames.get_shape()[0])
     # Apply batching
     self.dataset = self.dataset.batch(50)