# Install necessary libraries
!pip install opencv-python-headless
!pip install tensorflow
!pip install kaggle
!pip install imgaug

import cv2
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, UpSampling2D, concatenate, BatchNormalization, Dropout
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint
import matplotlib.pyplot as plt
from google.colab import files
import os
import imgaug.augmenters as iaa

# Ensure compatibility with GPU
tf.config.experimental.enable_tensor_float_32_execution(False)

#### 2. Upload kaggle.json with Kaggle API credentials

# Upload your kaggle.json file containing the API credentials
uploaded = files.upload()

# Move the kaggle.json file to the correct location
!mkdir -p ~/.kaggle
!mv kaggle.json ~/.kaggle/
!chmod 600 ~/.kaggle/kaggle.json

#### 3. Download and Prepare Dataset

# Set Kaggle API credentials
os.environ['KAGGLE_USERNAME'] = 'saisai6567'
os.environ['KAGGLE_KEY'] = '8d9d719ac56b061414987781f974f03a'

# Download the dataset from Kaggle
!kaggle datasets download -d kpgeek/kitti-roadlane-detection-dataset-224-x-224
!unzip -oq kitti-roadlane-detection-dataset-224-x-224.zip -d kitti_road

# Verify the directory structure
!ls kitti_road
!ls kitti_road/data_road_224/training
!ls kitti_road/data_road_224/training/image_2
!ls kitti_road/data_road_224/training/gt_image_2

#### 4. Define Enhanced U-Net Model

def unet_model(input_size=(224, 224, 3)):
    inputs = Input(input_size)
    # Encoder
    conv1 = Conv2D(64, 3, activation='relu', padding='same')(inputs)
    conv1 = BatchNormalization()(conv1)
    conv1 = Conv2D(64, 3, activation='relu', padding='same')(conv1)
    conv1 = BatchNormalization()(conv1)
    pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
    pool1 = Dropout(0.5)(pool1)

    conv2 = Conv2D(128, 3, activation='relu', padding='same')(pool1)
    conv2 = BatchNormalization()(conv2)
    conv2 = Conv2D(128, 3, activation='relu', padding='same')(conv2)
    conv2 = BatchNormalization()(conv2)
    pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
    pool2 = Dropout(0.5)(pool2)

    # Decoder
    conv3 = Conv2D(256, 3, activation='relu', padding='same')(pool2)
    conv3 = BatchNormalization()(conv3)
    conv3 = Conv2D(256, 3, activation='relu', padding='same')(conv3)
    conv3 = BatchNormalization()(conv3)
    up3 = UpSampling2D(size=(2, 2))(conv3)
    up3 = concatenate([up3, conv2], axis=-1)
    up3 = Dropout(0.5)(up3)

    conv4 = Conv2D(128, 3, activation='relu', padding='same')(up3)
    conv4 = BatchNormalization()(conv4)
    conv4 = Conv2D(128, 3, activation='relu', padding='same')(conv4)
    conv4 = BatchNormalization()(conv4)
    up4 = UpSampling2D(size=(2, 2))(conv4)
    up4 = concatenate([up4, conv1], axis=-1)
    up4 = Dropout(0.5)(up4)

    # Output layer
    conv5 = Conv2D(1, 1, activation='sigmoid')(up4)

    model = Model(inputs=[inputs], outputs=[conv5])
    model.compile(optimizer=Adam(learning_rate=1e-4), loss='binary_crossentropy', metrics=['accuracy'])
    return model

# Load the U-Net model
unet = unet_model()

# Image Augmentation
seq = iaa.Sequential([
    iaa.Fliplr(0.5),  # horizontal flips
    iaa.Crop(percent=(0, 0.1)),  # random crops
    iaa.GaussianBlur(    # Image Augmentation (continued)
    sigma=(0, 0.5)),  # blur images with a sigma from 0 to 0.5
    iaa.Affine(
        scale={"x": (0.8, 1.2), "y": (0.8, 1.2)},  # scale images to 80-120% of their size
        translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},  # translate by -20 to +20 percent (per axis)
        rotate=(-20, 20),  # rotate by -20 to +20 degrees
        shear=(-8, 8),  # shear by -8 to +8 degrees
    )
])

#### 5. Data Preprocessing and Augmentation

def load_data(image_dir, mask_dir, img_size=(224, 224)):
    images = []
    masks = []
    for img_file in os.listdir(image_dir):
        if img_file.endswith('.png'):
            img = cv2.imread(os.path.join(image_dir, img_file))
            img = cv2.resize(img, img_size)
            images.append(img)

            mask_file = img_file.replace('image_224', 'gt_image_224')
            mask = cv2.imread(os.path.join(mask_dir, mask_file), cv2.IMREAD_GRAYSCALE)
            if mask is not None:
                mask = cv2.resize(mask, img_size)
                mask = np.where(mask == 255, 1, 0)  # Ensure binary mask
            else:
                mask = np.zeros(img_size)  # if mask not found, create a blank mask
            masks.append(mask)
    images = np.array(images)
    masks = np.array(masks)
    images = images.astype('float32') / 255.0
    masks = masks.astype('float32')
    masks = np.expand_dims(masks, axis=-1)
    
    # Augment Dataset
    aug_images, aug_masks = [], []
    for _ in range(2):  # augment each image twice
        for img, msk in zip(images, masks):
            seq_det = seq.to_deterministic()
            aug_img = seq_det.augment_image(img)
            aug_msk = seq_det.augment_image(msk)
            aug_images.append(aug_img)
            aug_masks.append(aug_msk)
    
    images = np.concatenate((images, np.array(aug_images)), axis=0)
    masks = np.concatenate((masks, np.array(aug_masks)), axis=0)

    return images, masks

# Load training data
train_images, train_masks = load_data('kitti_road/data_road_224/training/image_2', 'kitti_road/data_road_224/training/gt_image_2')

# Callbacks for early stopping and saving the best model
callbacks = [
    EarlyStopping(patience=10, verbose=1),
    ModelCheckpoint('best_model.h5', verbose=1, save_best_only=True, save_weights_only=True)
]

# Train the U-Net model
unet.fit(train_images, train_masks, validation_split=0.2, epochs=50, batch_size=16, callbacks=callbacks)

#### 6. Define Dehazing and Segmentation Functions

def dehaze_image(image):
    # Step 1: Apply Improved Retinex Algorithm
    def retinex_ssr(img, sigma):
        img = img.astype(np.float32) + 1.0
        retinex = np.log10(img) - np.log10(cv2.GaussianBlur(img, (0, 0), sigma))
        return retinex

    def retinex_msr(img, sigma_list):
        msr = np.zeros_like(img, dtype=np.float32)
        for sigma in sigma_list:
            msr += retinex_ssr(img, sigma)
        msr = msr / len(sigma_list)
        return msr

    sigma_list = [15, 80, 250]
    img_msr = retinex_msr(image, sigma_list)
    img_msr = np.uint8(cv2.normalize(img_msr, None, 0, 255, cv2.NORM_MINMAX))

    # Step 2: Apply Hessian Matrix for Lane Line Strengthening
    gray = cv2.cvtColor(img_msr, cv2.COLOR_BGR2GRAY)
    hessian = cv2.cornerHarris(gray, 2, 3, 0.04)
    hessian = cv2.dilate(hessian, None)
    img_msr[hessian > 0.01 * hessian.max()] = [0, 0, 255]

    return img_msr

def preprocess_image_segmentation(image):
    image = cv2.resize(image, (224, 224))
    image = image.astype('float32') / 255.0
    image = np.expand_dims(image, axis=0)
    return image

def segment_road(image, model):
    image = preprocess_image_segmentation(image)
    mask = model.predict(image)
    mask = (mask[0] > 0.5).astype('uint8') * 255
    mask = cv2.resize(mask, (original_width, original_height), interpolation=cv2.INTER_NEAREST)
    return mask

def highlight_road(image, mask):
    contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    highlighted_image = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
    return highlighted_image


#### 7. Upload and Process an Image

# Upload the image
uploaded = files.upload()
image_path = list(uploaded.keys())[0]
image = cv2.imread(image_path)
original_height, original_width = image.shape[:2]

# Dehaze the image
dehazed_image = dehaze_image(image)

# Segment the road in the dehazed image
road_mask = segment_road(dehazed_image, unet)
highlighted_image = highlight_road(dehazed_image, road_mask)

# Display the result
plt.figure(figsize=(15, 15))
plt.subplot(1, 3, 1)
plt.title("Original Image")
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.axis('off')

plt.subplot(1, 3, 2)
plt.title("Dehazed Image")
plt.imshow(cv2.cvtColor(dehazed_image, cv2.COLOR_BGR2RGB))
plt.axis('off')

plt.subplot(1, 3, 3)
plt.title("Road Highlighted")
plt.imshow(cv2.cvtColor(highlighted_image, cv2.COLOR_BGR2RGB))
plt.axis('off')

plt.show()


_image_224 (101).png'  'gt_image_224 (18).png'   'gt_image_224 (277).png'
'gt_image_224 (102).png'  'gt_image_224 (190).png'  'gt_image_224 (278).png'
'gt_image_224 (103).png'  'gt_image_224 (191).png'  'gt_image_224 (279).png'
'gt_image_224 (104).png'  'gt_image_224 (192).png'  'gt_image_224 (27).png'
'gt_image_224 (105).png'  'gt_image_224 (193).png'  'gt_image_224 (280).png'
'gt_image_224 (106).png'  'gt_image_224 (194).png'  'gt_image_224 (281).png'
'gt_image_224 (107).png'  'gt_image_224 (195).png'  'gt_image_224 (282).png'
'gt_image_224 (108).png'  'gt_image_224 (196).png'  'gt_image_224 (283).png'
'gt_image_224 (109).png'  'gt_image_224 (197).png'  'gt_image_224 (284).png'
'gt_image_224 (10).png'   'gt_image_224 (198).png'  'gt_image_224 (285).png'
'gt_image_224 (110).png'  'gt_image_224 (199).png'  'gt_image_224 (286).png'
'gt_image_224 (111).png'  'gt_image_224 (19).png'   'gt_image_224 (287).png'
'gt_image_224 (112).png'  'gt_image_224 (1).png'    'gt_image_224 (288).png'
'gt_image_224 (113).png'  'gt_image_224 (200).png'  'gt_image_224 (289).png'
'gt_image_224 (114).png'  'gt_image_224 (201).png'  'gt_image_224 (28).png'
'gt_image_224 (115).png'  'gt_image_224 (202).png'  'gt_image_224 (29).png'
'gt_image_224 (116).png'  'gt_image_224 (203).png'  'gt_image_224 (2).png'
'gt_image_224 (117).png'  'gt_image_224 (204).png'  'gt_image_224 (30).png'
'gt_image_224 (118).png'  'gt_image_224 (205).png'  'gt_image_224 (31).png'
'gt_image_224 (119).png'  'gt_image_224 (206).png'  'gt_image_224 (32).png'
'gt_image_224 (11).png'   'gt_image_224 (207).png'  'gt_image_224 (33).png'
'gt_image_224 (120).png'  'gt_image_224 (208).png'  'gt_image_224 (34).png'
'gt_image_224 (121).png'  'gt_image_224 (209).png'  'gt_image_224 (35).png'
'gt_image_224 (122).png'  'gt_image_224 (20).png'   'gt_image_224 (36).png'
'gt_image_224 (123).png'  'gt_image_224 (210).png'  'gt_image_224 (37).png'
'gt_image_224 (124).png'  'gt_image_224 (211).png'  'gt_image_224 (38).png'
'gt_image_224 (125).png'  'gt_image_224 (212).png'  'gt_image_224 (39).png'
'gt_image_224 (126).png'  'gt_image_224 (213).png'  'gt_image_224 (3).png'
'gt_image_224 (127).png'  'gt_image_224 (214).png'  'gt_image_224 (40).png'
'gt_image_224 (128).png'  'gt_image_224 (215).png'  'gt_image_224 (41).png'
'gt_image_224 (129).png'  'gt_image_224 (216).png'  'gt_image_224 (42).png'
'gt_image_224 (12).png'   'gt_image_224 (217).png'  'gt_image_224 (43).png'
'gt_image_224 (130).png'  'gt_image_224 (218).png'  'gt_image_224 (44).png'
'gt_image_224 (131).png'  'gt_image_224 (219).png'  'gt_image_224 (45).png'
'gt_image_224 (132).png'  'gt_image_224 (21).png'   'gt_image_224 (46).png'
'gt_image_224 (133).png'  'gt_image_224 (220).png'  'gt_image_224 (47).png'
'gt_image_224 (134).png'  'gt_image_224 (221).png'  'gt_image_224 (48).png'
'gt_image_224 (135).png'  'gt_image_224 (222).png'  'gt_image_224 (49).png'
'gt_image_224 (136).png'  'gt_image_224 (223).png'  'gt_image_224 (4).png'
'gt_image_224 (137).png'  'gt_image_224 (224).png'  'gt_image_224 (50).png'
'gt_image_224 (138).png'  'gt_image_224 (225).png'  'gt_image_224 (51).png'
'gt_image_224 (139).png'  'gt_image_224 (226).png'  'gt_image_224 (52).png'
'gt_image_224 (13).png'   'gt_image_224 (227).png'  'gt_image_224 (53).png'
'gt_image_224 (140).png'  'gt_image_224 (228).png'  'gt_image_224 (54).png'
'gt_image_224 (141).png'  'gt_image_224 (229).png'  'gt_image_224 (55).png'
'gt_image_224 (142).png'  'gt_image_224 (22).png'   'gt_image_224 (56).png'
'gt_image_224 (143).png'  'gt_image_224 (230).png'  'gt_image_224 (57).png'
'gt_image_224 (144).png'  'gt_image_224 (231).png'  'gt_image_224 (58).png'
'gt_image_224 (145).png'  'gt_image_224 (232).png'  'gt_image_224 (59).png'
'gt_image_224 (146).png'  'gt_image_224 (233).png'  'gt_image_224 (5).png'
'gt_image_224 (147).png'  'gt_image_224 (234).png'  'gt_image_224 (60).png'
'gt_image_224 (148).png'  'gt_image_224 (235).png'  'gt_image_224 (61).png'
'gt_image_224 (149).png'  'gt_image_224 (236).png'  'gt_image_224 (62).png'
'gt_image_224 (14).png'   'gt_image_224 (237).png'  'gt_image_224 (63).png'
'gt_image_224 (150).png'  'gt_image_224 (238).png'  'gt_image_224 (64).png'
'gt_image_224 (151).png'  'gt_image_224 (239).png'  'gt_image_224 (65).png'
'gt_image_224 (152).png'  'gt_image_224 (23).png'   'gt_image_224 (66).png'
'gt_image_224 (153).png'  'gt_image_224 (240).png'  'gt_image_224 (67).png'
'gt_image_224 (154).png'  'gt_image_224 (241).png'  'gt_image_224 (68).png'
'gt_image_224 (155).png'  'gt_image_224 (242).png'  'gt_image_224 (69).png'
'gt_image_224 (156).png'  'gt_image_224 (243).png'  'gt_image_224 (6).png'
'gt_image_224 (157).png'  'gt_image_224 (244).png'  'gt_image_224 (70).png'
'gt_image_224 (158).png'  'gt_image_224 (245).png'  'gt_image_224 (71).png'
'gt_image_224 (159).png'  'gt_image_224 (246).png'  'gt_image_224 (72).png'
'gt_image_224 (15).png'   'gt_image_224 (247).png'  'gt_image_224 (73).png'
'gt_image_224 (160).png'  'gt_image_224 (248).png'  'gt_image_224 (74).png'
'gt_image_224 (161).png'  'gt_image_224 (249).png'  'gt_image_224 (75).png'
'gt_image_224 (162).png'  'gt_image_224 (24).png'   'gt_image_224 (76).png'
'gt_image_224 (163).png'  'gt_image_224 (250).png'  'gt_image_224 (77).png'
'gt_image_224 (164).png'  'gt_image_224 (251).png'  'gt_image_224 (78).png'
'gt_image_224 (165).png'  'gt_image_224 (252).png'  'gt_image_224 (79).png'
'gt_image_224 (166).png'  'gt_image_224 (253).png'  'gt_image_224 (7).png'
'gt_image_224 (167).png'  'gt_image_224 (254).png'  'gt_image_224 (80).png'
'gt_image_224 (168).png'  'gt_image_224 (255).png'  'gt_image_224 (81).png'
'gt_image_224 (169).png'  'gt_image_224 (256).png'  'gt_image_224 (82).png'
'gt_image_224 (16).png'   'gt_image_224 (257).png'  'gt_image_224 (83).png'
'gt_image_224 (170).png'  'gt_image_224 (258).png'  'gt_image_224 (84).png'
'gt_image_224 (171).png'  'gt_image_224 (259).png'  'gt_image_224 (85).png'
'gt_image_224 (172).png'  'gt_image_224 (25).png'   'gt_image_224 (86).png'
'gt_image_224 (173).png'  'gt_image_224 (260).png'  'gt_image_224 (87).png'
'gt_image_224 (174).png'  'gt_image_224 (261).png'  'gt_image_224 (88).png'
'gt_image_224 (175).png'  'gt_image_224 (262).png'  'gt_image_224 (89).png'
'gt_image_224 (176).png'  'gt_image_224 (263).png'  'gt_image_224 (8).png'
'gt_image_224 (177).png'  'gt_image_224 (264).png'  'gt_image_224 (90).png'
'gt_image_224 (178).png'  'gt_image_224 (265).png'  'gt_image_224 (91).png'
'gt_image_224 (179).png'  'gt_image_224 (266).png'  'gt_image_224 (92).png'
'gt_image_224 (17).png'   'gt_image_224 (267).png'  'gt_image_224 (93).png'
'gt_image_224 (180).png'  'gt_image_224 (268).png'  'gt_image_224 (94).png'
'gt_image_224 (181).png'  'gt_image_224 (269).png'  'gt_image_224 (95).png'
'gt_image_224 (182).png'  'gt_image_224 (26).png'   'gt_image_224 (96).png'
'gt_image_224 (183).png'  'gt_image_224 (270).png'  'gt_image_224 (97).png'
'gt_image_224 (184).png'  'gt_image_224 (271).png'  'gt_image_224 (98).png'
'gt_image_224 (185).png'  'gt_image_224 (272).png'  'gt_image_224 (99).png'
'gt_image_224 (186).png'  'gt_image_224 (273).png'  'gt_image_224 (9).png'
'gt_image_224 (187).png'  'gt_image_224 (274).png'   resize.m
'gt_image_224 (188).png'  'gt_image_224 (275).png'
Epoch 1/50
44/44 [==============================] - ETA: 0s - loss: 0.9131 - accuracy: 0.5063
Epoch 1: val_loss improved from inf to 0.62133, saving model to best_model.h5
44/44 [==============================] - 26s 488ms/step - loss: 0.9131 - accuracy: 0.5063 - val_loss: 0.6213 - val_accuracy: 0.9993
Epoch 2/50
44/44 [==============================] - ETA: 0s - loss: 0.7870 - accuracy: 0.5437
Epoch 2: val_loss improved from 0.62133 to 0.53396, saving model to best_model.h5
44/44 [==============================] - 20s 463ms/step - loss: 0.7870 - accuracy: 0.5437 - val_loss: 0.5340 - val_accuracy: 0.9998
Epoch 3/50
44/44 [==============================] - ETA: 0s - loss: 0.7238 - accuracy: 0.5927
Epoch 3: val_loss improved from 0.53396 to 0.52226, saving model to best_model.h5
44/44 [==============================] - 21s 471ms/step - loss: 0.7238 - accuracy: 0.5927 - val_loss: 0.5223 - val_accuracy: 0.9997
Epoch 4/50
44/44 [==============================] - ETA: 0s - loss: 0.6691 - accuracy: 0.6487
Epoch 4: val_loss improved from 0.52226 to 0.48417, saving model to best_model.h5
44/44 [==============================] - 21s 473ms/step - loss: 0.6691 - accuracy: 0.6487 - val_loss: 0.4842 - val_accuracy: 0.9999
Epoch 5/50
44/44 [==============================] - ETA: 0s - loss: 0.6208 - accuracy: 0.7157
Epoch 5: val_loss improved from 0.48417 to 0.46487, saving model to best_model.h5
44/44 [==============================] - 21s 474ms/step - loss: 0.6208 - accuracy: 0.7157 - val_loss: 0.4649 - val_accuracy: 1.0000
Epoch 6/50
44/44 [==============================] - ETA: 0s - loss: 0.5749 - accuracy: 0.7867
Epoch 6: val_loss improved from 0.46487 to 0.36628, saving model to best_model.h5
44/44 [==============================] - 21s 470ms/step - loss: 0.5749 - accuracy: 0.7867 - val_loss: 0.3663 - val_accuracy: 1.0000
Epoch 7/50
44/44 [==============================] - ETA: 0s - loss: 0.5283 - accuracy: 0.8602
Epoch 7: val_loss improved from 0.36628 to 0.32841, saving model to best_model.h5
44/44 [==============================] - 21s 471ms/step - loss: 0.5283 - accuracy: 0.8602 - val_loss: 0.3284 - val_accuracy: 1.0000
Epoch 8/50
44/44 [==============================] - ETA: 0s - loss: 0.4852 - accuracy: 0.9166
Epoch 8: val_loss did not improve from 0.32841
44/44 [==============================] - 21s 476ms/step - loss: 0.4852 - accuracy: 0.9166 - val_loss: 0.3394 - val_accuracy: 1.0000
Epoch 9/50
44/44 [==============================] - ETA: 0s - loss: 0.4485 - accuracy: 0.9451
Epoch 9: val_loss improved from 0.32841 to 0.21390, saving model to best_model.h5
44/44 [==============================] - 21s 477ms/step - loss: 0.4485 - accuracy: 0.9451 - val_loss: 0.2139 - val_accuracy: 1.0000
Epoch 10/50
44/44 [==============================] - ETA: 0s - loss: 0.4064 - accuracy: 0.9717
Epoch 10: val_loss improved from 0.21390 to 0.10375, saving model to best_model.h5
44/44 [==============================] - 21s 476ms/step - loss: 0.4064 - accuracy: 0.9717 - val_loss: 0.1038 - val_accuracy: 1.0000
Epoch 11/50
44/44 [==============================] - ETA: 0s - loss: 0.3690 - accuracy: 0.9839
Epoch 11: val_loss improved from 0.10375 to 0.10141, saving model to best_model.h5
44/44 [==============================] - 21s 477ms/step - loss: 0.3690 - accuracy: 0.9839 - val_loss: 0.1014 - val_accuracy: 1.0000
Epoch 12/50
44/44 [==============================] - ETA: 0s - loss: 0.3329 - accuracy: 0.9902
Epoch 12: val_loss improved from 0.10141 to 0.09273, saving model to best_model.h5
44/44 [==============================] - 21s 473ms/step - loss: 0.3329 - accuracy: 0.9902 - val_loss: 0.0927 - val_accuracy: 1.0000
Epoch 13/50
44/44 [==============================] - ETA: 0s - loss: 0.2995 - accuracy: 0.9936
Epoch 13: val_loss did not improve from 0.09273
44/44 [==============================] - 21s 471ms/step - loss: 0.2995 - accuracy: 0.9936 - val_loss: 0.1775 - val_accuracy: 1.0000
Epoch 14/50
44/44 [==============================] - ETA: 0s - loss: 0.2687 - accuracy: 0.9950
Epoch 14: val_loss did not improve from 0.09273
44/44 [==============================] - 21s 476ms/step - loss: 0.2687 - accuracy: 0.9950 - val_loss: 0.1582 - val_accuracy: 1.0000
Epoch 15/50
44/44 [==============================] - ETA: 0s - loss: 0.2421 - accuracy: 0.9963
Epoch 15: val_loss did not improve from 0.09273
44/44 [==============================] - 21s 475ms/step - loss: 0.2421 - accuracy: 0.9963 - val_loss: 0.1640 - val_accuracy: 1.0000
Epoch 16/50
44/44 [==============================] - ETA: 0s - loss: 0.2145 - accuracy: 0.9974
Epoch 16: val_loss did not improve from 0.09273
44/44 [==============================] - 21s 469ms/step - loss: 0.2145 - accuracy: 0.9974 - val_loss: 0.1099 - val_accuracy: 1.0000
Epoch 17/50
44/44 [==============================] - ETA: 0s - loss: 0.1914 - accuracy: 0.9977
Epoch 17: val_loss did not improve from 0.09273
44/44 [==============================] - 21s 469ms/step - loss: 0.1914 - accuracy: 0.9977 - val_loss: 0.1008 - val_accuracy: 1.0000
Epoch 18/50
44/44 [==============================] - ETA: 0s - loss: 0.1716 - accuracy: 0.9983
Epoch 18: val_loss did not improve from 0.09273
44/44 [==============================] - 21s 474ms/step - loss: 0.1716 - accuracy: 0.9983 - val_loss: 0.1153 - val_accuracy: 1.0000
Epoch 19/50
44/44 [==============================] - ETA: 0s - loss: 0.1522 - accuracy: 0.9986
Epoch 19: val_loss improved from 0.09273 to 0.08718, saving model to best_model.h5
44/44 [==============================] - 21s 469ms/step - loss: 0.1522 - accuracy: 0.9986 - val_loss: 0.0872 - val_accuracy: 1.0000
Epoch 20/50
44/44 [==============================] - ETA: 0s - loss: 0.1362 - accuracy: 0.9988
Epoch 20: val_loss improved from 0.08718 to 0.08646, saving model to best_model.h5
44/44 [==============================] - 21s 469ms/step - loss: 0.1362 - accuracy: 0.9988 - val_loss: 0.0865 - val_accuracy: 1.0000
Epoch 21/50
44/44 [==============================] - ETA: 0s - loss: 0.1215 - accuracy: 0.9990
Epoch 21: val_loss did not improve from 0.08646
44/44 [==============================] - 21s 467ms/step - loss: 0.1215 - accuracy: 0.9990 - val_loss: 0.0942 - val_accuracy: 1.0000
Epoch 22/50
44/44 [==============================] - ETA: 0s - loss: 0.1117 - accuracy: 0.9990
Epoch 22: val_loss improved from 0.08646 to 0.08055, saving model to best_model.h5
44/44 [==============================] - 21s 469ms/step - loss: 0.1117 - accuracy: 0.9990 - val_loss: 0.0806 - val_accuracy: 1.0000
Epoch 23/50
44/44 [==============================] - ETA: 0s - loss: 0.0995 - accuracy: 0.9990
Epoch 23: val_loss improved from 0.08055 to 0.07356, saving model to best_model.h5
44/44 [==============================] - 21s 474ms/step - loss: 0.0995 - accuracy: 0.9990 - val_loss: 0.0736 - val_accuracy: 1.0000
Epoch 24/50
44/44 [==============================] - ETA: 0s - loss: 0.0891 - accuracy: 0.9992
Epoch 24: val_loss improved from 0.07356 to 0.07237, saving model to best_model.h5
44/44 [==============================] - 21s 473ms/step - loss: 0.0891 - accuracy: 0.9992 - val_loss: 0.0724 - val_accuracy: 1.0000
Epoch 25/50
44/44 [==============================] - ETA: 0s - loss: 0.0818 - accuracy: 0.9992
Epoch 25: val_loss did not improve from 0.07237
44/44 [==============================] - 21s 472ms/step - loss: 0.0818 - accuracy: 0.9992 - val_loss: 0.0727 - val_accuracy: 1.0000
Epoch 26/50
44/44 [==============================] - ETA: 0s - loss: 0.0735 - accuracy: 0.9994
Epoch 26: val_loss improved from 0.07237 to 0.06379, saving model to best_model.h5
44/44 [==============================] - 21s 468ms/step - loss: 0.0735 - accuracy: 0.9994 - val_loss: 0.0638 - val_accuracy: 1.0000
Epoch 27/50
44/44 [==============================] - ETA: 0s - loss: 0.0662 - accuracy: 0.9995
Epoch 27: val_loss improved from 0.06379 to 0.05483, saving model to best_model.h5
44/44 [==============================] - 21s 473ms/step - loss: 0.0662 - accuracy: 0.9995 - val_loss: 0.0548 - val_accuracy: 1.0000
Epoch 28/50
44/44 [==============================] - ETA: 0s - loss: 0.0608 - accuracy: 0.9995
Epoch 28: val_loss improved from 0.05483 to 0.05100, saving model to best_model.h5
44/44 [==============================] - 21s 473ms/step - loss: 0.0608 - accuracy: 0.9995 - val_loss: 0.0510 - val_accuracy: 1.0000
Epoch 29/50
44/44 [==============================] - ETA: 0s - loss: 0.0550 - accuracy: 0.9996
Epoch 29: val_loss improved from 0.05100 to 0.04640, saving model to best_model.h5
44/44 [==============================] - 21s 472ms/step - loss: 0.0550 - accuracy: 0.9996 - val_loss: 0.0464 - val_accuracy: 1.0000
Epoch 30/50
44/44 [==============================] - ETA: 0s - loss: 0.0504 - accuracy: 0.9996
Epoch 30: val_loss improved from 0.04640 to 0.04118, saving model to best_model.h5
44/44 [==============================] - 21s 467ms/step - loss: 0.0504 - accuracy: 0.9996 - val_loss: 0.0412 - val_accuracy: 1.0000
Epoch 31/50
44/44 [==============================] - ETA: 0s - loss: 0.0461 - accuracy: 0.9997
Epoch 31: val_loss improved from 0.04118 to 0.03428, saving model to best_model.h5
44/44 [==============================] - 21s 473ms/step - loss: 0.0461 - accuracy: 0.9997 - val_loss: 0.0343 - val_accuracy: 1.0000
Epoch 32/50
44/44 [==============================] - ETA: 0s - loss: 0.0424 - accuracy: 0.9997
Epoch 32: val_loss improved from 0.03428 to 0.03226, saving model to best_model.h5
44/44 [==============================] - 21s 467ms/step - loss: 0.0424 - accuracy: 0.9997 - val_loss: 0.0323 - val_accuracy: 1.0000
Epoch 33/50
44/44 [==============================] - ETA: 0s - loss: 0.0388 - accuracy: 0.9998
Epoch 33: val_loss improved from 0.03226 to 0.02619, saving model to best_model.h5
44/44 [==============================] - 21s 468ms/step - loss: 0.0388 - accuracy: 0.9998 - val_loss: 0.0262 - val_accuracy: 1.0000
Epoch 34/50
44/44 [==============================] - ETA: 0s - loss: 0.0360 - accuracy: 0.9998
Epoch 34: val_loss did not improve from 0.02619
44/44 [==============================] - 20s 466ms/step - loss: 0.0360 - accuracy: 0.9998 - val_loss: 0.0300 - val_accuracy: 1.0000
Epoch 35/50
44/44 [==============================] - ETA: 0s - loss: 0.0360 - accuracy: 0.9998
Epoch 35: val_loss improved from 0.02619 to 0.01500, saving model to best_model.h5
44/44 [==============================] - 21s 468ms/step - loss: 0.0360 - accuracy: 0.9998 - val_loss: 0.0150 - val_accuracy: 1.0000
Epoch 36/50
44/44 [==============================] - ETA: 0s - loss: 0.0324 - accuracy: 0.9998
Epoch 36: val_loss did not improve from 0.01500
44/44 [==============================] - 21s 467ms/step - loss: 0.0324 - accuracy: 0.9998 - val_loss: 0.0187 - val_accuracy: 1.0000
Epoch 37/50
44/44 [==============================] - ETA: 0s - loss: 0.0298 - accuracy: 0.9998
Epoch 37: val_loss did not improve from 0.01500
44/44 [==============================] - 21s 471ms/step - loss: 0.0298 - accuracy: 0.9998 - val_loss: 0.0188 - val_accuracy: 1.0000
Epoch 38/50
44/44 [==============================] - ETA: 0s - loss: 0.0276 - accuracy: 0.9998
Epoch 38: val_loss did not improve from 0.01500
44/44 [==============================] - 21s 472ms/step - loss: 0.0276 - accuracy: 0.9998 - val_loss: 0.0179 - val_accuracy: 1.0000
Epoch 39/50
44/44 [==============================] - ETA: 0s - loss: 0.0256 - accuracy: 0.9999
Epoch 39: val_loss did not improve from 0.01500
44/44 [==============================] - 21s 472ms/step - loss: 0.0256 - accuracy: 0.9999 - val_loss: 0.0162 - val_accuracy: 1.0000
Epoch 40/50
44/44 [==============================] - ETA: 0s - loss: 0.0237 - accuracy: 0.9999
Epoch 40: val_loss did not improve from 0.01500
44/44 [==============================] - 20s 465ms/step - loss: 0.0237 - accuracy: 0.9999 - val_loss: 0.0153 - val_accuracy: 1.0000
Epoch 41/50
44/44 [==============================] - ETA: 0s - loss: 0.0221 - accuracy: 0.9999
Epoch 41: val_loss improved from 0.01500 to 0.01462, saving model to best_model.h5
44/44 [==============================] - 21s 473ms/step - loss: 0.0221 - accuracy: 0.9999 - val_loss: 0.0146 - val_accuracy: 1.0000
Epoch 42/50
44/44 [==============================] - ETA: 0s - loss: 0.0208 - accuracy: 0.9999
Epoch 42: val_loss improved from 0.01462 to 0.01295, saving model to best_model.h5
44/44 [==============================] - 21s 468ms/step - loss: 0.0208 - accuracy: 0.9999 - val_loss: 0.0129 - val_accuracy: 1.0000
Epoch 43/50
44/44 [==============================] - ETA: 0s - loss: 0.0194 - accuracy: 0.9999
Epoch 43: val_loss improved from 0.01295 to 0.01216, saving model to best_model.h5
44/44 [==============================] - 21s 472ms/step - loss: 0.0194 - accuracy: 0.9999 - val_loss: 0.0122 - val_accuracy: 1.0000
Epoch 44/50
44/44 [==============================] - ETA: 0s - loss: 0.0182 - accuracy: 0.9999
Epoch 44: val_loss did not improve from 0.01216
44/44 [==============================] - 20s 465ms/step - loss: 0.0182 - accuracy: 0.9999 - val_loss: 0.0135 - val_accuracy: 1.0000
Epoch 45/50
44/44 [==============================] - ETA: 0s - loss: 0.0182 - accuracy: 0.9999
Epoch 45: val_loss improved from 0.01216 to 0.00995, saving model to best_model.h5
44/44 [==============================] - 21s 471ms/step - loss: 0.0182 - accuracy: 0.9999 - val_loss: 0.0100 - val_accuracy: 1.0000
Epoch 46/50
44/44 [==============================] - ETA: 0s - loss: 0.0165 - accuracy: 0.9999
Epoch 46: val_loss did not improve from 0.00995
44/44 [==============================] - 21s 470ms/step - loss: 0.0165 - accuracy: 0.9999 - val_loss: 0.0107 - val_accuracy: 1.0000
Epoch 47/50
44/44 [==============================] - ETA: 0s - loss: 0.0153 - accuracy: 0.9999
Epoch 47: val_loss did not improve from 0.00995
44/44 [==============================] - 21s 470ms/step - loss: 0.0153 - accuracy: 0.9999 - val_loss: 0.0114 - val_accuracy: 1.0000
Epoch 48/50
44/44 [==============================] - ETA: 0s - loss: 0.0143 - accuracy: 0.9999
Epoch 48: val_loss did not improve from 0.00995
44/44 [==============================] - 21s 469ms/step - loss: 0.0143 - accuracy: 0.9999 - val_loss: 0.0116 - val_accuracy: 1.0000
Epoch 49/50
44/44 [==============================] - ETA: 0s - loss: 0.0136 - accuracy: 0.9999
Epoch 49: val_loss did not improve from 0.00995
44/44 [==============================] - 21s 469ms/step - loss: 0.0136 - accuracy: 0.9999 - val_loss: 0.0119 - val_accuracy: 1.0000
Epoch 50/50
44/44 [==============================] - ETA: 0s - loss: 0.0127 - accuracy: 0.9999
Epoch 50: val_loss did not improve from 0.00995
44/44 [==============================] - 21s 470ms/step - loss: 0.0127 - accuracy: 0.9999 - val_loss: 0.0112 - val_accuracy: 1.0000
th (1).jpg
th (1).jpg(image/jpeg) - 3856 bytes, last modified: 6/9/2024 - 100% done
Saving th (1).jpg to th (1) (5).jpg
1/1 [==============================] - 0s 248ms/step
this code doesnt give me full road segmented in a color like it is in the dataset
data_road_224(2 directories)
About this directory

Add Suggestion
The classic KITTI urban road dataset resized to 224 x 224 image resolution for using in transfer learning models like GoogleNet, Resnet-50, MobileNet-V2, etc, which expect the input of size 224 x 224.

testing

2 directories
training

3 directories
training(3 directories)
About this directory

Add Suggestion
gt_image_2 consist of the Labeled ground truth images and image_2 consist of original road images.

calib

289 files
gt_image_2

290 files
image_2

289 files
testing(2 directories)
About this directory

Add Suggestion
Test images directory

calib

290 files
image_2

291 files
like wise in gt folder unet is good in segmentation so i need road segmented and hightlight it in output