{"id":13816471,"url":"https://github.com/mdietrichstein/tensorflow-open_nsfw","last_synced_at":"2025-04-05T16:10:29.382Z","repository":{"id":73366584,"uuid":"92968981","full_name":"mdietrichstein/tensorflow-open_nsfw","owner":"mdietrichstein","description":"Tensorflow Implementation of Yahoo's Open NSFW Model","archived":false,"fork":false,"pushed_at":"2020-09-16T11:49:05.000Z","size":21634,"stargazers_count":440,"open_issues_count":16,"forks_count":139,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-29T06:44:08.528Z","etag":null,"topics":["caffe","deep-learning","deep-neural-networks","tensorflow","tensorflow-models"],"latest_commit_sha":null,"homepage":"","language":"Python","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/mdietrichstein.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}},"created_at":"2017-05-31T16:59:42.000Z","updated_at":"2025-03-20T06:35:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"540197d8-cc43-4035-ba74-70f71ff74cdc","html_url":"https://github.com/mdietrichstein/tensorflow-open_nsfw","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/mdietrichstein%2Ftensorflow-open_nsfw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdietrichstein%2Ftensorflow-open_nsfw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdietrichstein%2Ftensorflow-open_nsfw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdietrichstein%2Ftensorflow-open_nsfw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdietrichstein","download_url":"https://codeload.github.com/mdietrichstein/tensorflow-open_nsfw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361695,"owners_count":20926643,"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":["caffe","deep-learning","deep-neural-networks","tensorflow","tensorflow-models"],"created_at":"2024-08-04T05:00:42.601Z","updated_at":"2025-04-05T16:10:29.358Z","avatar_url":"https://github.com/mdietrichstein.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Tensorflow Implementation of Yahoo's Open NSFW Model\n\nThis repository contains an implementation of [Yahoo's Open NSFW Classifier](https://github.com/yahoo/open_nsfw) rewritten in tensorflow.\n\nThe original caffe weights have been extracted using [Caffe to TensorFlow](https://github.com/ethereon/caffe-tensorflow). You can find them at `data/open_nsfw-weights.npy`.\n\n## Prerequisites\n\nAll code should be compatible with `Python 3.6` and `Tensorflow 1.x` (tested with 1.12). The model implementation can be found in `model.py`.\n\n### Usage\n\n```\n\u003e python classify_nsfw.py -m data/open_nsfw-weights.npy test.jpg\n\nResults for 'test.jpg'\n\tSFW score:\t0.9355766177177429\n\tNSFW score:\t0.06442338228225708\n```\n\n__Note:__ Currently only jpeg images are supported.\n\n`classify_nsfw.py` accepts some optional parameters you may want to play around with:\n\n```\nusage: classify_nsfw.py [-h] -m MODEL_WEIGHTS [-l {yahoo,tensorflow}]\n                        [-t {tensor,base64_jpeg}]\n                        input_jpeg_file\n\npositional arguments:\n  input_file            Path to the input image. Only jpeg images are\n                        supported.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -m MODEL_WEIGHTS, --model_weights MODEL_WEIGHTS\n                        Path to trained model weights file\n  -l {yahoo,tensorflow}, --image_loader {yahoo,tensorflow}\n                        image loading mechanism\n  -i {tensor,base64_jpeg}, --input_type {tensor,base64_jpeg}\n                        input type\n```\n\n__-l/--image-loader__\n\nThe classification tool supports two different image loading mechanisms. \n\n* `yahoo` (default) replicates yahoo's original image loading and preprocessing. Use this option if you want the same results as with the original implementation\n* `tensorflow` is an image loader which uses tensorflow exclusively (no dependencies on `PIL`, `skimage`, etc.). Tries to replicate the image loading mechanism used by the original caffe implementation, differs a bit though due to different jpeg and resizing implementations. See [this issue](https://github.com/mdietrichstein/tensorflow-open_nsfw/issues/2#issuecomment-346125345) for details.\n\n__Note:__ Classification results may vary depending on the selected image loader!\n\n__-i/--input_type__\n\nDetermines if the model internally uses a float tensor (`tensor` - `[None, 224, 224, 3]` - default) or a base64 encoded string tensor (`base64_jpeg` - `[None, ]`) as input. If `base64_jpeg` is used, then the `tensorflow` image loader will be used, regardless of the _-l/--image-loader_ argument.\n\n\n### Tools\n\nThe `tools` folder contains some utility scripts to test the model.\n\n__create_predict_request.py__\n\nTakes an input image and generates a json file suitable for prediction requests to a Open NSFW Model deployed with [Google Cloud ML Engine](https://cloud.google.com/ml-engine/docs/concepts/prediction-overview) (`gcloud ml-engine predict`) or [tensorflow-serving](https://www.tensorflow.org/serving/).\n\n\n__export_savedmodel.py__\n\nExports the model using the tensorflow serving export api (`SavedModel`). The export can be used to deploy the model on [Google Cloud ML Engine](https://cloud.google.com/ml-engine/docs/concepts/prediction-overview), [Tensorflow Serving]() or on mobile (haven't tried that one yet).\n\n__export_tflite.py__\n\nExports the model in [TFLite format](https://www.tensorflow.org/lite/). Use this one if you want to run inference on mobile or IoT devices. Please note that the `base64_jpeg` input type does not work with TFLite since the standard runtime lacks a number of required tensorflow operations.\n\n__export_graph.py__\n\nExports the tensorflow graph and checkpoint. Freezes and optimizes the graph per default for improved inference and deployment usage (e.g. Android, iOS, etc.). Import the graph with `tf.import_graph_def`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdietrichstein%2Ftensorflow-open_nsfw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdietrichstein%2Ftensorflow-open_nsfw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdietrichstein%2Ftensorflow-open_nsfw/lists"}