{"id":23080705,"url":"https://github.com/chen0040/scala-tensorflow-samples","last_synced_at":"2026-05-02T04:39:57.769Z","repository":{"id":85884751,"uuid":"123512036","full_name":"chen0040/scala-tensorflow-samples","owner":"chen0040","description":"Scala samples codes on how to load tensorflow pb model and use them to predict","archived":false,"fork":false,"pushed_at":"2018-03-04T01:36:30.000Z","size":51333,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T13:47:59.767Z","etag":null,"topics":["pretrained-models","scala","tensorflow"],"latest_commit_sha":null,"homepage":null,"language":"Scala","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/chen0040.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,"publiccode":null,"codemeta":null}},"created_at":"2018-03-02T01:11:58.000Z","updated_at":"2019-01-20T01:42:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c82c933-b12d-4361-9ebc-81b6186873cd","html_url":"https://github.com/chen0040/scala-tensorflow-samples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chen0040/scala-tensorflow-samples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fscala-tensorflow-samples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fscala-tensorflow-samples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fscala-tensorflow-samples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fscala-tensorflow-samples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chen0040","download_url":"https://codeload.github.com/chen0040/scala-tensorflow-samples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fscala-tensorflow-samples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32523428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"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":["pretrained-models","scala","tensorflow"],"created_at":"2024-12-16T13:16:06.764Z","updated_at":"2026-05-02T04:39:57.762Z","avatar_url":"https://github.com/chen0040.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scala-tensorflow-samples\n\nScala samples codes on how to load tensorflow pb model and use them to predict\n\n\n\n# Usage\n\n### Image Classification using Cifar10\n\nBelow show the [demo codes](image-classifier/src/main/scala/com/github/chen0040/tensorflow/classifiers/demo/Cifar10ImageClassifierDemo.scala)\nof the  Cifar10ImageClassifier which loads the [cnn_cifar10.pb](image-classifier/src/main/resources/tf_models/cnn_cifar10.pb)\ntensorflow model file, and uses it to do image classification:\n\n```scala\npackage com.github.chen0040.tensorflow.classifiers.demo\n\nimport java.io.IOException\n\nimport com.github.chen0040.tensorflow.classifiers.cifar10.Cifar10ImageClassifier\nimport com.github.chen0040.tensorflow.classifiers.utils.ResourceUtils\nimport org.slf4j.LoggerFactory\n\nclass Cifar10ImageClassifierDemo() {\n\n}\n\nobject Cifar10ImageClassifierDemo {\n  private val logger = LoggerFactory.getLogger(classOf[Cifar10ImageClassifierDemo])\n\n  @throws[IOException]\n  def main(args: Array[String]): Unit = {\n    val inputStream = ResourceUtils.getInputStream(\"tf_models/cnn_cifar10.pb\")\n    val classifier = new Cifar10ImageClassifier\n    classifier.load_model(inputStream)\n    val image_names = Array[String](\"airplane1\", \"airplane2\", \"airplane3\", \"automobile1\", \"automobile2\", \"automobile3\", \"bird1\", \"bird2\", \"bird3\", \"cat1\", \"cat2\", \"cat3\")\n    for (image_name \u003c- image_names) {\n      val image_path = \"images/cifar10/\" + image_name + \".png\"\n      val img = ResourceUtils.getImage(image_path)\n      val predicted_label = classifier.predict_image(img)\n      System.out.println(\"predicted class for \" + image_name + \": \" + predicted_label)\n    }\n  }\n}\n```\n\n### Image Classification using Inception \n\nBelow show the [demo codes](image-classifier/src/main/scala/com/github/chen0040/tensorflow/classifiers/demo/InceptionImageClassifierDemo.scala)\nof the  InceptionImageClassifier which loads the [tensorflow_inception_graph.pb](image-classifier/src/main/resources/tf_models/tensorflow_inception_graph.pb)\ntensorflow model file, and uses it to do image classification:\n\n```scala\npackage com.github.chen0040.tensorflow.classifiers.demo\n\nimport java.io.IOException\n\nimport com.github.chen0040.tensorflow.classifiers.inception.InceptionImageClassifier\nimport com.github.chen0040.tensorflow.classifiers.utils.ResourceUtils\nimport org.slf4j.LoggerFactory\n\nclass InceptionImageClassifierDemo {\n\n}\n\nobject InceptionImageClassifierDemo {\n  private val logger = LoggerFactory.getLogger(classOf[InceptionImageClassifierDemo])\n\n  @throws[IOException]\n  def main(args: Array[String]): Unit = {\n    val classifier = new InceptionImageClassifier\n    classifier.load_model(ResourceUtils.getInputStream(\"tf_models/tensorflow_inception_graph.pb\"))\n    classifier.load_labels(ResourceUtils.getInputStream(\"tf_models/imagenet_comp_graph_label_strings.txt\"))\n    val image_names = Array[String](\"tiger\", \"lion\")\n    for (image_name \u003c- image_names) {\n      val image_path = \"images/inception/\" + image_name + \".jpg\"\n      val img = ResourceUtils.getImage(image_path)\n      val predicted_label = classifier.predict_image(img)\n      System.out.println(\"predicted class for \" + image_name + \": \" + predicted_label)\n    }\n  }\n}\n```\n\n### Sentiment Analysis using 1D CNN\n\nBelow show the [demo codes](sentiment-analysis/src/main/scala/com/github/chen0040/tensorflow/classifiers/demo/CnnSentimentClassifierDemo.scala)\nof the  CnnSentimentClassifier which loads the [wordvec_cnn.pb](sentiment-analysis/src/main/resources/tf_models/wordvec_cnn.pb)\ntensorflow model file, and uses it to do sentiment analysis:\n\n```scala\npackage com.github.chen0040.tensorflow.classifiers.demo\n\nimport com.github.chen0040.tensorflow.classifiers.sentiment.BidirectionalLstmSentimentClassifier\nimport com.github.chen0040.tensorflow.classifiers.utils.ResourceUtils\n\nimport scala.collection.JavaConversions._\n\nobject BidirectionalLstmSentimentClassifierDemo {\n  def main(args: Array[String]): Unit = {\n    val classifier = new BidirectionalLstmSentimentClassifier()\n    classifier.load_model(ResourceUtils.getInputStream(\"tf_models/bidirectional_lstm_softmax.pb\"))\n    classifier.load_vocab(ResourceUtils.getInputStream(\"tf_models/bidirectional_lstm_softmax.csv\"))\n\n    val lines = ResourceUtils.getLines(\"data/umich-sentiment-train.txt\")\n\n    for(line \u003c- lines){\n      val label = line.split(\"\\t\")(0)\n      val text = line.split(\"\\t\")(1)\n      val predicted = classifier.predict(text)\n      val predicted_label = classifier.predict_label(text)\n      System.out.println(text)\n      System.out.println(\"Outcome: \" + predicted(0) + \", \" + predicted(1))\n      System.out.println(\"Predicted: \" + predicted_label + \" Actual: \" + label)\n    }\n  }\n}\n\n\n```\n\n### Sentiment Analysis using Bi-directional LSTM\n\nBelow show the [demo codes](sentiment-analysis/src/main/scala/com/github/chen0040/tensorflow/classifiers/demo/BidirectionalLstmSentimentClassifierDemo.scala)\nof the  BidirectionalLstmSentimentClassifier which loads the [wordvec_bidirectional_lstm.pb](sentiment-analysis/src/main/resources/tf_models/wordvec_bidirectional_lstm.pb)\ntensorflow model file, and uses it to do sentiment analysis:\n\n```scala\npackage com.github.chen0040.tensorflow.classifiers.demo\n\nimport com.github.chen0040.tensorflow.classifiers.sentiment.BidirectionalLstmSentimentClassifier\nimport com.github.chen0040.tensorflow.classifiers.utils.ResourceUtils\n\nimport scala.collection.JavaConversions._\n\nobject BidirectionalLstmSentimentClassifierDemo {\n  def main(args: Array[String]): Unit = {\n    val classifier = new BidirectionalLstmSentimentClassifier()\n    classifier.load_model(ResourceUtils.getInputStream(\"tf_models/bidirectional_lstm_softmax.pb\"))\n    classifier.load_vocab(ResourceUtils.getInputStream(\"tf_models/bidirectional_lstm_softmax.csv\"))\n\n    val lines = ResourceUtils.getLines(\"data/umich-sentiment-train.txt\")\n\n    for(line \u003c- lines){\n      val label = line.split(\"\\t\")(0)\n      val text = line.split(\"\\t\")(1)\n      val predicted = classifier.predict(text)\n      val predicted_label = classifier.predict_label(text)\n      System.out.println(text)\n      System.out.println(\"Outcome: \" + predicted(0) + \", \" + predicted(1))\n      System.out.println(\"Predicted: \" + predicted_label + \" Actual: \" + label)\n    }\n  }\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchen0040%2Fscala-tensorflow-samples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchen0040%2Fscala-tensorflow-samples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchen0040%2Fscala-tensorflow-samples/lists"}