{"id":23102657,"url":"https://github.com/dataxujing/ssd-tensorflow","last_synced_at":"2025-08-16T14:33:01.198Z","repository":{"id":112306272,"uuid":"226492808","full_name":"DataXujing/SSD-Tensorflow","owner":"DataXujing","description":":art::art::art: SSD-Tensorflow目标检测基于医学影像的消化内镜活检钳","archived":false,"fork":false,"pushed_at":"2019-12-07T10:59:22.000Z","size":370,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T13:22:47.826Z","etag":null,"topics":["cv","detection","python3","ssd","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DataXujing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2019-12-07T10:25:18.000Z","updated_at":"2024-09-02T08:21:50.000Z","dependencies_parsed_at":"2023-05-03T01:45:32.986Z","dependency_job_id":null,"html_url":"https://github.com/DataXujing/SSD-Tensorflow","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/DataXujing/SSD-Tensorflow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataXujing%2FSSD-Tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataXujing%2FSSD-Tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataXujing%2FSSD-Tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataXujing%2FSSD-Tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DataXujing","download_url":"https://codeload.github.com/DataXujing/SSD-Tensorflow/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataXujing%2FSSD-Tensorflow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270723411,"owners_count":24634375,"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","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cv","detection","python3","ssd","tensorflow"],"created_at":"2024-12-17T00:00:16.795Z","updated_at":"2025-08-16T14:33:01.183Z","avatar_url":"https://github.com/DataXujing.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## **SSD**目标检测内镜活检钳\n\n**XuJing**\n\n### 1.:bookmark:数据标注及准备\n\n数据来源公司业务数据(**因涉及数据安全及隐私数据，不能公开！！！**),我们使用[LabelImg](https://github.com/tzutalin/labelImg)标注我们的数据。标注好的数据我们存放在`data`文件夹下，其文件结构如下：\n\n+ step1: 数据准备\n\n```\ndata\n├─tfrecord   # 生成的tfrecord\n└─train      # 准备的VOC样式的数据集\n    ├─Annotations   # 标注的训练集的标注文件\n    └─JPEGImages    # 标注的图像文件\n```\n\n+ step2: 修改和数据相关的代码\n\n```\n#修改dataset/convert_common.py\nVOC_LABELS = {\n    'Background': (0, 'Background'),\n    'biopsy forceps': (1, 'biopsy forceps')\n}\ndata_splits_num = {\n    'train': 22136,\n    'val': 4952,\n}\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cmark\u003e\u003cfont color=darkred\u003e修改train.py\u003c/font\u003e\u003c/mark\u003e\u003c/summary\u003e\n\u003cpre\u003e\u003ccode\u003e\n# hardware related configuration\ntf.app.flags.DEFINE_integer(\n    'num_readers', 8,\n    'The number of parallel readers that read data from the dataset.')\ntf.app.flags.DEFINE_integer(\n    'num_preprocessing_threads', 24,\n    'The number of threads used to create the batches.')\ntf.app.flags.DEFINE_integer(\n    'num_cpu_threads', 0,\n    'The number of cpu cores used to train.')\ntf.app.flags.DEFINE_float(\n    'gpu_memory_fraction', 0.9, 'GPU memory fraction to use.')\n# scaffold related configuration\ntf.app.flags.DEFINE_string(\n    'data_dir', './data/tfrecord',\n    'The directory where the dataset input data is stored.')\ntf.app.flags.DEFINE_integer(  # 类别个数包含背景\n    'num_classes', 2, 'Number of classes to use in the dataset.')\ntf.app.flags.DEFINE_string(\n    'model_dir', './logs/',\n    'The directory where the model will be stored.')\ntf.app.flags.DEFINE_integer(\n    'log_every_n_steps', 10,\n    'The frequency with which logs are printed.')\ntf.app.flags.DEFINE_integer(\n    'save_summary_steps', 500,\n    'The frequency with which summaries are saved, in seconds.')\ntf.app.flags.DEFINE_integer(\n    'save_checkpoints_secs', 7200,\n    'The frequency with which the model is saved, in seconds.')\n# model related configuration\ntf.app.flags.DEFINE_integer(\n    'train_image_size', 300,\n    'The size of the input image for the model to use.')\ntf.app.flags.DEFINE_integer(\n    'train_epochs', None,\n    'The number of epochs to use for training.')\ntf.app.flags.DEFINE_integer(\n    'max_number_of_steps', 120000,\n    'The max number of steps to use for training.')\ntf.app.flags.DEFINE_integer(\n    'batch_size', 32,\n    'Batch size for training and evaluation.')\ntf.app.flags.DEFINE_string(\n    'data_format', 'channels_first', # 'channels_first' or 'channels_last'\n    'A flag to override the data format used in the model. channels_first '\n    'provides a performance boost on GPU but is not always compatible '\n    'with CPU. If left unspecified, the data format will be chosen '\n    'automatically based on whether TensorFlow was built for CPU or GPU.')\ntf.app.flags.DEFINE_float(\n    'negative_ratio', 3., 'Negative ratio in the loss function.')\ntf.app.flags.DEFINE_float(\n    'match_threshold', 0.5, 'Matching threshold in the loss function.')\ntf.app.flags.DEFINE_float(\n    'neg_threshold', 0.5, 'Matching threshold for the negtive examples in the loss function.')\n# optimizer related configuration\ntf.app.flags.DEFINE_integer(\n    'tf_random_seed', 20180503, 'Random seed for TensorFlow initializers.')\ntf.app.flags.DEFINE_float(\n    'weight_decay', 5e-4, 'The weight decay on the model weights.')\ntf.app.flags.DEFINE_float(\n    'momentum', 0.9,\n    'The momentum for the MomentumOptimizer and RMSPropOptimizer.')\ntf.app.flags.DEFINE_float('learning_rate', 1e-3, 'Initial learning rate.')\ntf.app.flags.DEFINE_float(\n    'end_learning_rate', 0.000001,\n    'The minimal end learning rate used by a polynomial decay learning rate.')\n# for learning rate piecewise_constant decay\ntf.app.flags.DEFINE_string(\n    'decay_boundaries', '2000, 80000, 100000',\n    'Learning rate decay boundaries by global_step (comma-separated list).')\ntf.app.flags.DEFINE_string(\n    'lr_decay_factors', '0.1, 1, 0.1, 0.01',\n    'The values of learning_rate decay factor for each segment between boundaries (comma-separated list).')\n# checkpoint related configuration\ntf.app.flags.DEFINE_string(\n    'checkpoint_path', './model',\n    'The path to a checkpoint from which to fine-tune.')\ntf.app.flags.DEFINE_string(\n    'checkpoint_model_scope', 'vgg_16',\n    'Model scope in the checkpoint. None if the same as the trained model.')\ntf.app.flags.DEFINE_string(\n    'model_scope', 'ssd300',\n    'Model scope name used to replace the name_scope in checkpoint.')\ntf.app.flags.DEFINE_string(\n    'checkpoint_exclude_scopes', 'ssd300/multibox_head, ssd300/additional_layers, ssd300/conv4_3_scale',\n    'Comma-separated list of scopes of variables to exclude when restoring from a checkpoint.')\ntf.app.flags.DEFINE_boolean(\n    'ignore_missing_vars', True,\n    'When restoring a checkpoint would ignore missing variables.')\ntf.app.flags.DEFINE_boolean(\n    'multi_gpu', True,\n    'Whether there is GPU to use for training.')\n\u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n+ setp3: 生成tfrecord\n\n```\npython3 dataset/convert_tfrecords.py --dataset_directory=data\n    --output_directory=./data/tfrecord\n```\n\n如果想训练自己的数据集可以将标注的数据存放在上述文件结构中，这样SSD的训练模型的数据集即准备完成。\n\n### 2.:hammer:模型准备\n\n我们使用[SSD: Single Shot MultiBox Detector](https://arxiv.org/abs/1512.02325) ,使用Tensorflow 1.0深度学习框架。如果你想使用原paper的代码，请参考[Official Code](https://github.com/weiliu89/caffe/tree/ssd). 该框架提供了：\n\n+ VGG-16的预训练模型(SSD300-VGG16)\n\n+ 使用Tensorflow的高级API [tf.estimator](https://www.tensorflow.org/api_docs/python/tf/estimator/Estimator)，并且我们推荐你使用该高级API.\n\n+ 该框架全部使用Tensorflow实现.\n\n+ 使用和官方相同的数据增强策略.\n\n+ 使用[tf.layers](https://www.tensorflow.org/api_docs/python/tf/layers)，类似于Pytorch一样的易读.\n\n+ 支持多GPU并行.\n\n+ 使用Bounding Box的绝对坐标而不是标准化后的坐标[here](https://github.com/HiKapok/SSD.TensorFlow/tree/AbsoluteCoord).\n\n\n\u003e :fire: 下载预训练的模型[VGG-16](https://github.com/DataXujing/SSD-Tensorflow/releases/tag/v1.0)\n\n把下载的预训练的VGG16拷贝到`./model/pretrain`下，这样我们就准备好训练自己数据的全部过程。\n\n### 3.:chart_with_upwards_trend:模型训练\n\n```\npython3 train_ssd.py\n```\n\n### 4.:whale:模型测试\n\n+ 图像测试\n\n```\npython3 test_img.py\n```\n\n+ 视频测试\n\n```\npython3 test_video.py\n```\n\n### 5.:globe_with_meridians:DEMO\n\n![](./demo.jpg)\n\n### 6.:fire:目前存在的一些问题\n\n+ 目前并不支持SSD-512\n+ 目前并不支持其他的backbone\n+ 训练过程中Nan Loss： 增加warm-up\n    ```\n    tf.app.flags.DEFINE_string(\n        'decay_boundaries', '2000, 80000, 100000',\n        'Learning rate decay boundaries by global_step (comma-separated list).')\n    tf.app.flags.DEFINE_string(\n        'lr_decay_factors', '0.1, 1, 0.1, 0.01',\n        'The values of learning_rate decay factor for each segment between boundaries (comma-separated list).')\n    ```\n\n### 6.:tada:致谢\n\n|Name   | Url|\n|:-----|:------|\n|:white_check_mark:Changan Wang|https://github.com/HiKapok/SSD.TensorFlow|\n|:white_check_mark:Medcare|http://www.medicon.com.cn/|\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdataxujing%2Fssd-tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdataxujing%2Fssd-tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdataxujing%2Fssd-tensorflow/lists"}