From the course: Foundations of AI and Machine Learning for Java Developers
Sample VisRec code to use a PredAI model - Java Tutorial
From the course: Foundations of AI and Machine Learning for Java Developers
Sample VisRec code to use a PredAI model
- [Instructor] Now that we have built a binary classifier model of light colored Chihuahuas and non-light colored Chihuahuas, let's test it out on some new image files that the model has not seen yet. Here we have five image files. It looks like there are three cute light colored Chihuahuas at the top, a pizza, bottom left, and a picture of a cow. So let's test our model to see how well it does. So here's a JSR 381 code to do the prediction. It's very, very simple. Similarly to the training phase of this application, we used the builder pattern of an image classifier. We tell JSR 381 that we're using buffered images, which for vis rec is the standard input class. We give JSR 381 the dimensions of the new images for scaling purposes. The next thing we do is very important. We tell JSR 381, the name of the file that contains the model that we created in the training phase or the learning phase. To make it a little simpler, I've written a little utility method called classifyImage. This method's not part of JSR 381, it's merely a utility method for convenience. You pass in the classifier that JSR 381 returned and the name of an image file that you want to test. This method reads that image and then calls JSR 381's classify method. The classify method will return a map of a string and a float, representing the classification label and the probability of the image being of that type. Let's test it on Chihuahua 1, Chihuahua 2, Chihuahua 3, the pizza image, and the cow image. Here are the results. So for the three light color Chihuahuas, we got high probability results that they were indeed light color Chihuahuas. We got 90.8% for the first one, 90.7 for second one, 90.9 for the third one. That's pretty good results for only 872 images. For the pizza, our model is saying that there was a 13% chance that this image is a light colored Chihuahua, and clearly it is not, it's a pizza. So, but that's still a decent result given that we only have a small number of images. Now, notice the Chihuahua probability for the light colored cow, it is 49%. That's like flipping a coin. Clearly that cow is not a light color Chihuahua. So our first instinct is that we must have a bug in our code. Or do we? What do you think is wrong? How can we improve our application so it doesn't confuse a cow with a cute Chihuahua? This is not a code bug, it is a data bug. This is a very important point. What's critical for AI applications for both predictive AI and generative AI is the quality of the data used for training. If this happened in a production application, you'd have to contact the data engineering team and say, "We need additional good data to train the model." So now let's see this in action.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.