コード例 #1
0
    def load_paths_to_images(self, paths):
        images = np.empty(
            [len(paths), IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_CHANNELS])

        for k, path in enumerate(paths):
            images[k] = utils.load_img_from_path(data_dir=self.data_dir,
                                                 image_name=path,
                                                 is_gray_scale=self.gray_scale)
        return images
コード例 #2
0
    def predict(self, data, number_of_steps):
        predictions = np.empty(shape=(number_of_steps,))
        data_shape = data.shape

        for i in range(predictions.shape[0]):
            predicted_value = self.model.predict(data)
            predictions[i] = predicted_value.item()
            # remove first element and add the prediction
            data = np.reshape(np.append(data[0][1:], predicted_value.item()), newshape=data_shape)
        return predictions
コード例 #3
0
    def __getitem__(self, index):
        start_index = index * self.batch_size
        end_index = start_index + self.batch_size
        batch_paths = self.path_to_pictures[start_index:end_index]
        steering_angles = self.steering_angles[start_index:end_index]

        images = np.empty([len(batch_paths), IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_CHANNELS])
        steers = np.empty([len(batch_paths)])
        for i, paths in enumerate(batch_paths):
            center, left, right = batch_paths[i]
            steering_angle = steering_angles[i]
            # augmentation
            if self.is_training and np.random.rand() < 0.6:
                image, steering_angle = augment(self.args.data_dir, center, left, right, steering_angle)
            else:
                image = load_image(self.args.data_dir, center)
            # add the image and steering angle to the batch
            images[i] = preprocess(image)
            steers[i] = steering_angle
        return images, steers
コード例 #4
0
    def __getitem__(self, index):
        start_index = index * self.batch_size
        end_index = start_index + self.batch_size
        batch_paths = self.path_to_pictures[start_index:end_index]
        input_shape = self.model.get_input_shape()
        x_shape = (len(batch_paths), ) + (input_shape)
        x = np.empty(shape=x_shape)
        for i, path in enumerate(batch_paths):

            # apply augmentation to 60% of the images, if enabled
            if APPLY_DATA_AUGMENTATION and np.random.rand() < 0.6:
                # data augmentation
                img = load_image(self.data_dir, path)
                img = augment(img)
                img = preprocess(img)  # crop + resize + rgb2yuv
            else:
                img = load_image(self.data_dir, path)
                img = resize(img)

            x[i] = self.model.normalize_and_reshape(img)
        return x, x
コード例 #5
0
 def empty_batch_array(self, this_batch_y_paths):
     return np.empty([
         len(this_batch_y_paths), self.sequence_length, IMAGE_HEIGHT,
         IMAGE_WIDTH, IMAGE_CHANNELS
     ])