{"id":24098431,"url":"https://github.com/matlab-deep-learning/pretrained-spatial-cnn","last_synced_at":"2025-10-08T08:49:38.651Z","repository":{"id":118345367,"uuid":"364803836","full_name":"matlab-deep-learning/pretrained-spatial-CNN","owner":"matlab-deep-learning","description":"Spatial-CNN for lane detection in MATLAB.","archived":false,"fork":false,"pushed_at":"2021-09-23T15:03:21.000Z","size":34061,"stargazers_count":24,"open_issues_count":0,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-14T21:51:22.755Z","etag":null,"topics":["autonomous-driving","computer-vision","deep-learning","deeplearning","detected-lanes","lane","lane-detection","lane-detector","lane-lines-detection","matlab","pretrained-models","scnn","scnn-network","spatial-cnn"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matlab-deep-learning.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-05-06T06:13:26.000Z","updated_at":"2024-09-23T09:36:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"830c3f3e-b988-437e-8ecf-e3644aeb6eb0","html_url":"https://github.com/matlab-deep-learning/pretrained-spatial-CNN","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fpretrained-spatial-CNN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fpretrained-spatial-CNN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fpretrained-spatial-CNN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab-deep-learning%2Fpretrained-spatial-CNN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matlab-deep-learning","download_url":"https://codeload.github.com/matlab-deep-learning/pretrained-spatial-CNN/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252942301,"owners_count":21829041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autonomous-driving","computer-vision","deep-learning","deeplearning","detected-lanes","lane","lane-detection","lane-detector","lane-lines-detection","matlab","pretrained-models","scnn","scnn-network","spatial-cnn"],"created_at":"2025-01-10T14:45:41.110Z","updated_at":"2025-10-08T08:49:33.575Z","avatar_url":"https://github.com/matlab-deep-learning.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lane Detection Using Deep Learning\n\nThis repository implements a pretrained Spatial-CNN (SCNN)[1] lane detection model in MATLAB\u0026reg;.\n\n## Requirements\n- MATLAB\u0026reg; R2021a or later.\n- Deep Learning Toolbox\u0026trade;.\n- Computer Vision Toolbox\u0026trade;.\n- Automated Driving Toolbox\u0026trade;.\n\n## Overview\nThis repository implements SCNN with VGG-16 as the backbone. The pretrained network is trained to detect lanes in the image. The network is trained using [CULane](https://xingangpan.github.io/projects/CULane.html) dataset[1].\n\nSpatial-CNN (SCNN) uses slice-by-slice convolutions on the feature maps obtained by layer-by-layer convolutions since the spatial information can be reinforced via inter-layer propagation. This helps in detecting objects with strong structure prior but less appearance clues such as lanes, poles, or trucks with occlusions.\n\n## Getting Started\nDownload or clone this repository to your machine and open it in MATLAB®.\n\n### Setup\nAdd path to the source directory.\n```\naddpath('src');\n```\n\n### Download and Load the Pretrained Network\nUse the below helper to download and load the pretrained network. The network will be downloaded and saved in `model` directory.\n```\nmodel = helper.downloadSCNNLaneDetection;\nnet = model.net;\n```\n\n### Detect Lanes Using SCNN\nThis snippet includes all the steps required to run SCNN model on a single RGB image in MATLAB®. Use the script `spatialCNNLaneDetectionExample.m` to run the inference on single image.\n\n```\n% Specify Detection Parameters.\nparams = helper.createSCNNDetectionParameters;\n\n% Specify the executionEnvironment as either \"cpu\", \"gpu\", or \"auto\".\nexecutionEnvironment = \"auto\";\n\n% Read the test image.\npath = fullfile(\"images\",\"testImage.jpg\");\nimage = imread(path);\n\n% Use detectLaneMarkings function to detect the lane markings.\nlaneMarkings = detectLaneMarkings(net, image, params, executionEnvironment);\n\n% Visualize the detected lanes.\nfig = figure;\nhelper.plotLanes(fig, image, laneMarkings);\n\n```\n\nAlternatively, you can also run the SCNN model on sample videos. Use the script `spatialCNNLaneDetectionVideoExample.m` to run the inference on a driving scene.\n\n\n### Result\nLeft-side image is the input and right-side image shows the detected lanes. The image is taken from the [Panda Set](https://scale.com/open-datasets/pandaset) dataset[2].\n\n\u003ctable\u003e\n\u003ctr\u003e\n    \u003ctd\u003e \u003cimg src=\"images/testImage.jpg\" width=\"550\" height=\"220\"/\u003e \u003c/td\u003e\n    \u003ctd\u003e \u003cimg src=\"images/result.jpg\" width=\"550\" height=\"220\"/\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nSample video output generated by the script `spatialCNNLaneDetectionVideoExample.m`.\n\n\u003cimg src=\"images/caltech_washington1.gif\" width=\"800\" height=\"300\"/\u003e \n\n## Evaluation Metrics\nThe model is evaluated using the method specified in [1].\n\n| Dataset  | Error Metric | IOU | Result | \n| ------------- | ------------- | ------------- | ------------- |\n| CULane  | F-measure  | 0.3 | 73.45 |\n| CULane  | F-measure | 0.5 | 43.41 |\n\n## Spatial-CNN Algorithm Details\nThe SCNN network architecture is illustrated in the following diagram.\n|\u003cimg src=\"images/SCNN_architecture.png\" width=\"949\" height=\"385\" title=\"Fig.1\" /\u003e|\n|:--:|\n|**Fig.1**|\n\n\nThe network takes RGB images as input and outputs a probability map and confidence score for each lane. The pre-trained SCNN model trained on [CULane](https://xingangpan.github.io/projects/CULane.html) can detect maximum of 4 lanes( 2 driving lanes and 2 lanes on either side of the driving lane). The probability map predicted by the network has 5 channels (4 lanes + 1 background). Lanes with confidence score less than 0.5 are ignored. To generate the detections the probability map is processed and curves are fit.\n\n\nSCNN network in this repository has 4 message passing layers in sequence in the directions top-to-bottom, bottom-to-top, left-to-right, and right-to-left with kernel size of 9 and are represented by up-down, down-up, left-right, and right-left respectively in Fig.1. The message passing layers are special layers that apply slice-by-slice convolutions within the feature map[1]. These layers are implemented as a custom nested deep learning layer. For more information about the custom nested deep learning layer, see [Define Nested Deep Learning Layer](https://www.mathworks.com/help/deeplearning/ug/define-nested-deep-learning-layer.html).\n\n## References\n\n[1] Xingang Pan, Jianping Shi, Ping Luo, Xiaogang Wang, and Xiaoou Tang. \"Spatial As Deep: Spatial CNN for Traffic Scene Understanding\" AAAI Conference on Artificial Intelligence (AAAI) - 2018\n\n[2] [Panda Set](https://scale.com/open-datasets/pandaset) is provided by Hesai and Scale under the [CC-BY-4.0 license](https://creativecommons.org/licenses/by/4.0)\n\n## See also\n[Visual Perception Using Monocular Camera](https://www.mathworks.com/help/driving/ug/visual-perception-using-monocular-camera.html)\n\nCopyright 2021 The MathWorks, Inc.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatlab-deep-learning%2Fpretrained-spatial-cnn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatlab-deep-learning%2Fpretrained-spatial-cnn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatlab-deep-learning%2Fpretrained-spatial-cnn/lists"}