{"id":13857115,"url":"https://github.com/HasnainRaz/Skin-Segmentation-TensorFlow","last_synced_at":"2025-07-13T20:30:51.341Z","repository":{"id":123466005,"uuid":"119887250","full_name":"HasnainRaz/Skin-Segmentation-TensorFlow","owner":"HasnainRaz","description":"A modified SegNet Convolutional Neural Net for segmenting human skin from images ","archived":false,"fork":false,"pushed_at":"2020-07-14T20:16:34.000Z","size":44,"stargazers_count":58,"open_issues_count":0,"forks_count":12,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-05-19T23:36:11.077Z","etag":null,"topics":["autoencoder","convolutional-neural-networks","segmentation","segnet","semantic-segmentation","skin-detection","tensorflow","tensorflow-models"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HasnainRaz.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-02-01T20:06:49.000Z","updated_at":"2024-03-30T12:22:27.000Z","dependencies_parsed_at":"2024-02-09T01:36:43.986Z","dependency_job_id":"9cd7ae04-be48-455c-8e5a-6b267c04825e","html_url":"https://github.com/HasnainRaz/Skin-Segmentation-TensorFlow","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/HasnainRaz%2FSkin-Segmentation-TensorFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HasnainRaz%2FSkin-Segmentation-TensorFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HasnainRaz%2FSkin-Segmentation-TensorFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HasnainRaz%2FSkin-Segmentation-TensorFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HasnainRaz","download_url":"https://codeload.github.com/HasnainRaz/Skin-Segmentation-TensorFlow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213988318,"owners_count":15666963,"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":["autoencoder","convolutional-neural-networks","segmentation","segnet","semantic-segmentation","skin-detection","tensorflow","tensorflow-models"],"created_at":"2024-08-05T03:01:26.336Z","updated_at":"2024-08-05T03:02:48.581Z","avatar_url":"https://github.com/HasnainRaz.png","language":"Python","readme":"# Skin-Segmentation-TensorFlow\nThis is a modified [SegNet](https://arxiv.org/abs/1511.00561) convolutional neural net for segmenting human skin from images.\nThe model was trained on only 40 images, and while it manages an F1 score 0.90, it is in no way extremely generalizable, it was done as a simple project, to test if a CNN could be trained from scratch on a small dataset.\n\n# Main Idea:\nThe code emphasizes readability, simplicity and ease of understanding. It is meant to be looked at if you are starting out with TensorFlow and looking into building your own model. There are only two files, one for data loading, and one for the model definition, training and testing.\n\n# Examples:\n![alt text](example/image.jpg \"Input image\") ![alt text](example/prediction.png \"Predicted segmentation\")\n\nFree stock image taken from [Pixabay](https://pixabay.com/)\n\n# Explanation of Code Snippets:\nConvolution is done with the tf.layers.conv2d layer, like so:\n```python\ndef conv_with_bn(x, no_of_filters, kernel_size, training, strides=[1, 1], activation=tf.nn.relu, use_bias=True, name=None):\n    conv = tf.layers.conv2d(x, no_of_filters, kernel_size, strides, padding='SAME', activation=activation,\n                            use_bias=use_bias, kernel_initializer=tf.contrib.layers.xavier_initializer(), name=name)\n    conv = tf.layers.batch_normalization(conv, training=training)\n\n    return conv\n```\nDownsampling is done again with the same convolutional layer, only with the strides changed to 2.\n\nUpsampling is done via transpose convolutions:\n```python\ndef trans_conv_with_bn(x, no_of_filters, kernel_size, training, strides=[2, 2], activation=tf.nn.relu, use_bias=True, name=None):\n    conv = tf.layers.conv2d_transpose(x, no_of_filters, kernel_size, strides, padding='SAME', activation=activation,\n                                      use_bias=use_bias, kernel_initializer=tf.contrib.layers.xavier_initializer(), name=name)\n    conv = tf.layers.batch_normalization(conv, training=training)\n    return conv\n```\n\nThe model itself is defined in the inference function:\n```python\ndef inference(image_tensor, is_training):\n    \"\"\"Runs image through the network and returns predicted mask.\"\"\"\n\n    print('Building Network for Inference...')\n\n    conv0 = conv_with_bn(image_tensor, 64, [3, 3], is_training, name='conv0')\n    down0 = conv_with_bn(conv0, 64, [3, 3], is_training, [2, 2], name='down0')\n\n    conv1 = conv_with_bn(down0, 128, [3, 3], is_training, name='conv1')\n    down1 = conv_with_bn(conv1, 128, [3, 3], is_training, [2, 2], name='down1')\n\n    conv2 = conv_with_bn(down1, 256, [3, 3], is_training, name='conv2')\n    down2 = conv_with_bn(conv2, 256, [3, 3], is_training, [2, 2], name='down2')\n\n    conv3 = conv_with_bn(down2, 512, [3, 3], is_training, name='conv3')\n    down3 = conv_with_bn(conv3, 512, [3, 3], is_training, [2, 2], name='down3')\n\n    up3 = trans_conv_with_bn(down3, 512, [3, 3], is_training, name='up3')\n    unconv3 = conv_with_bn(up3, 512, [3, 3], is_training, name='unconv3')\n\n    up2 = trans_conv_with_bn(unconv3, 256, [3, 3], is_training, name='up2')\n    unconv2 = conv_with_bn(up2, 256, [3, 3], is_training, name='unconv2')\n\n    up1 = trans_conv_with_bn(unconv2, 128, [3, 3], is_training, name='up1')\n    unconv1 = conv_with_bn(up1, 128, [3, 3], is_training, name='unconv1')\n\n    up0 = trans_conv_with_bn(unconv1, 64, [3, 3], is_training, name='up0')\n    unconv0 = conv_with_bn(up0, 64, [3, 3], is_training, name='unconv0')\n\n    pred = conv_with_bn(unconv0, NUM_CLASSES, [\n                        3, 3], is_training, activation=None, use_bias=False, name='pred')\n\n    print('Done, network built.')\n    return pred\n```\nAs can be seen, the model has 9 convolutional layers and calculates upto 512 feature maps. The architecture is simple to understand, the focus here is on readability.\n\n# TODOs:\n1. Add model graph for visualization.\n2. Comment code for further readability.\n3. Extend and explain the input pipeline.\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHasnainRaz%2FSkin-Segmentation-TensorFlow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHasnainRaz%2FSkin-Segmentation-TensorFlow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHasnainRaz%2FSkin-Segmentation-TensorFlow/lists"}