Skip to content

Commit

Permalink
upload files
Browse files Browse the repository at this point in the history
  • Loading branch information
ErniW committed Apr 10, 2023
1 parent b94c770 commit 0299941
Show file tree
Hide file tree
Showing 6 changed files with 764 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dataset/images
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# CNN-Image-segmentation-for-CARLA-with-U-Net
Implementation of image segmentation task for autonomous car driving via U-Net architecture.

- Dataset comes with pickle files for images and masks separately. They were downsized to speed training time at cost of quality (I'm aware of it).
- You can use any kind of data for U-Net. For dataset preparation please refer to `pack_images.py` script (to run script type `python pack_images.py "./dataset/images"` - there you should have images and masks folder).
Binary file added dataset/dataset_images.pickle
Binary file not shown.
Binary file added dataset/dataset_masks.pickle
Binary file not shown.
62 changes: 62 additions & 0 deletions pack_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import argparse
import imageio
import numpy as np
import pickle as pkl
from PIL import Image, ImageOps

RESIZE_WIDTH = 128
RESIZE_HEIGHT = 96

def load_images(dir):

path = dir
IMAGE_PATH = os.path.join(path, 'images/')
MASK_PATH = os.path.join(path, 'masks/')

images_list = os.listdir(IMAGE_PATH)
masks_list = os.listdir(MASK_PATH)

images_list = [IMAGE_PATH + i for i in images_list]
masks_list = [MASK_PATH + i for i in masks_list]

images = []
masks = []
amount = len(images_list)

print(f"Starting conversion of {amount} images")

for i in range(amount):
img = Image.open(images_list[i])
mask = Image.open(masks_list[i])

img = img.resize((RESIZE_WIDTH, RESIZE_HEIGHT), Image.NEAREST)
mask = mask.resize((RESIZE_WIDTH, RESIZE_HEIGHT), Image.NEAREST)

img = np.array(img)
mask = np.array(mask)

images.append(img)
masks.append(mask[:,:,0])

return images, masks


if __name__ == '__main__':

parser = argparse.ArgumentParser(prog="Pack images into a single file")
parser.add_argument('input_dir')
args = parser.parse_args()

images, masks = load_images(args.input_dir)

images = np.array(images)
masks = np.array(masks)

with open('dataset_images.pickle', 'wb') as f:
pkl.dump(images, f)

with open('dataset_masks.pickle', 'wb') as f:
pkl.dump(masks, f)

print(f"Done saving - Images Shape: {images.shape}, Masks Shape: {masks.shape}")
698 changes: 698 additions & 0 deletions unet_image_segmentation_notebook.ipynb

Large diffs are not rendered by default.

0 comments on commit 0299941

Please sign in to comment.