{"id":18638716,"url":"https://github.com/cseas/image-classifier","last_synced_at":"2026-04-29T01:03:12.824Z","repository":{"id":125781060,"uuid":"139298367","full_name":"cseas/image-classifier","owner":"cseas","description":"Deep Neural Network Classifier to recognise images based on custom training classes.","archived":false,"fork":false,"pushed_at":"2018-07-27T07:27:24.000Z","size":201,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-17T14:41:24.821Z","etag":null,"topics":["classify-images","deep-learning","deep-neural-networks","image-classifier","python","python3","tensorboard","tensorflow"],"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/cseas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"publiccode":null,"codemeta":null}},"created_at":"2018-07-01T03:46:33.000Z","updated_at":"2018-11-21T07:14:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"ef219ddd-a3e5-4108-9065-667767abb8f4","html_url":"https://github.com/cseas/image-classifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cseas/image-classifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cseas%2Fimage-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cseas%2Fimage-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cseas%2Fimage-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cseas%2Fimage-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cseas","download_url":"https://codeload.github.com/cseas/image-classifier/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cseas%2Fimage-classifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32405904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["classify-images","deep-learning","deep-neural-networks","image-classifier","python","python3","tensorboard","tensorflow"],"created_at":"2024-11-07T05:43:14.139Z","updated_at":"2026-04-29T01:03:12.810Z","avatar_url":"https://github.com/cseas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Image Classifier\n\nIn this project, I trained an image classifier with TensorFlow for Poets, starting from just a directory of images. TensorFlow is an open source library for numerical computation, specializing in machine learning applications. \n\nI created a classifier to tell the difference between five types of flowers: roses, sunflowers, tulips, dandelions, and daisies. To use this classifier to detect another class of images, create a directory inside flower_photos (specified in training.sh) with the label name and provide about a 100 images to start with.\n\nI've used Transfer Learning (Retraining), which means I started with a model that had been already trained on another problem. I then retrained it on a similar problem. Deep learning from scratch can take days, but transfer learning can be done in short order. Retraining saves a lot of time, and leverages prior work.\n\nI've used a model trained on the [ImageNet](http://image-net.org/) Large Visual Recognition Challenge [dataset](http://www.image-net.org/challenges/LSVRC/2012/). These models can differentiate between 1,000 different classes, like Dalmatian or dishwasher. We have a choice of model architectures, so we can determine the right tradeoff between speed, size and accuracy for our problem. I've used this same model, but retrained it to tell apart a small number of classes based on my own examples. I've used a [dataset](http://download.tensorflow.org/example_images/flower_photos.tgz) of creative-commons licensed flower photos.\n\nUnder the hood, TensorFlow Poets starts with an existing classifier called Inception. Inception is one of Google's best image classifiers and is open source. It is trained on 1.2 million images from a thousand different categories. Training Inception took about 2 weeks on a fast desktops with 8 GPUs.\n\nI concluded that Deep Learning has a major advantage when working with images. You don't need to extract features manually for classification. Instead, you can use the raw pixels of the image as features and the classifier will do the rest.\n\nTo train a good image classifier, the keywords to keep in mind are diversity and quantity. Diversity means the more different types of images of a class we have, the better off we'll be. In this example, our training set for roses has pictures of red, white and yellow roses. We also have pictures taken at different angles. Also, there are pictures of roses in the foreground as well as the background. Quantity means more the training data we have, the better a classifier we're likely to create.\n\n## Configure MobileNet\n\nI've retrained a [MobileNet](https://ai.googleblog.com/2017/06/mobilenets-open-source-models-for.html). MobileNet is a small efficient convolutional neural network. \"Convolutional\" just means that the same calculations are performed at each location in the image.\n\nThe MobileNet is configurable in two ways:\n\n    Input image resolution: 128,160,192, or 224px.  \n    Unsurprisingly, feeding in a higher resolution image takes more processing time, but results in better classification accuracy.  \n    The relative size of the model as a fraction of the largest MobileNet: 1.0, 0.75, 0.50, or 0.25.\n\nI've used 224 0.5 for this project.\n\nWith the recommended settings, it typically takes only a couple of minutes to retrain on a laptop. I've passed the settings inside Linux shell variables.\n\n## Start TensorBoard\n\nBefore starting the training, launch tensorboard in the background. TensorBoard is a monitoring and inspection tool included with tensorflow. You will use it to monitor the training progress.\n\n```shell\nsh tensorboard.sh\n```\n\nThis command will fail with the following error if you already have a tensorboard process running:\n\n```\nERROR:tensorflow:TensorBoard attempted to bind to port 6006, but it was already in use\n```\n\nYou can kill all existing TensorBoard instances with:\n\n```shell\npkill -f \"tensorboard\"\n```\n\n## Investigate the retraining script\n\nThe retrain script is from the TensorFlow Hub repo, but it is not installed as part of the pip package. So for simplicity I've included it in the codelab repository. You can run the script using the python command.\n\n## Run the training\n\nAs noted in the introduction, ImageNet models are networks with millions of parameters that can differentiate a large number of classes. We're only training the final layer of that network, so training will end in a reasonable amount of time.\n\nStart your retraining with the following command (note the --summaries_dir option, sending training progress reports to the directory that tensorboard is monitoring):\n\n```shell\nsh training.sh\n```\n\nNote that this step will take a while.\nThis script downloads the pre-trained model, adds a new final layer, and trains that layer on the flower photos.\n\nImageNet does not include any of these flower species we're training on here. However, the kinds of information that make it possible for ImageNet to differentiate among 1,000 classes are also useful for distinguishing other objects. By using this pre-trained network, we are using that information as input to the final classification layer that distinguishes our flower classes.\n\n## Using the Retrained Model\n\nThe retraining script writes data to the following two files:\n\n* `tf_files/retrained_graph.pb`, which contains a version of the selected network with a final layer retrained on your categories.\n* `tf_files/retrained_labels.txt`, which is a text file containing labels.\n\n## Classifying an image\n\nlabel_image.py script can be used to classify images. Take a minute to read the help for this script:\n```shell\npython -m scripts.label_image -h\n```\n\nTest a daisy image from the dataset using the following code:\n```shell\npython3 -m scripts.label_image \\\n    --graph=tf_files/retrained_graph.pb  \\\n    --image=tf_files/flower_photos/daisy/21652746_cc379e0eea_m.jpg\n```\n\nIf you chose a mobilenet that takes a smaller input size, then be sure to set the --input_size flag using the shell variable you set earlier.\n\n```shell\n--input_size=${IMAGE_SIZE}\n``` \n\nTest a downloaded image as follows:\n```shell\npython3 -m scripts.label_image --image=test.jpeg\n```\n\n## Trying Other Hyperparameters\n\nThe retraining script has several other command line options you can use. You can read about these options in the help for the retrain script:\n\n```shell\npython3 -m scripts.retrain -h\n```\n\nThe `--learning_rate` parameter controls the magnitude of the updates to the final layer during training. So far we have left it out, so the program has used the default `learning_rate` value of `0.01`. If you specify a small `learning_rate`, like `0.005`, the training will take longer, but the overall precision might increase. Higher values of `learning_rate`, like `1.0`, could train faster, but typically reduces precision, or even makes training unstable.\n\nYou may want to set the following two options together, so your results are clearly labeled:\n\n```shell\n--learning_rate=0.5\n--summaries_dir=training_summaries/LR_0.5\n```\n\n## Training on Your Own Categories\n\nYou can teach the network to recognize different categories.\n\nIn theory, all you need to do is run the tool, specifying a particular set of sub-folders. Each sub-folder is named after one of your categories and contains only images from that category.\n\nIf you complete this step and pass the root folder of the subdirectories as the argument for the `--image_dir` parameter, the script should train the images that you've provided, just like it did for the flowers.\n\nThe classification script uses the folder names as label names, and the images inside each folder should be pictures that correspond to that label, as you can see in the flower archive.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcseas%2Fimage-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcseas%2Fimage-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcseas%2Fimage-classifier/lists"}