Question
Getting started. Before you begin coding, do the following: Read Sections 3.1 and 3.2 of the textbook to learn the basics of object-oriented programming and
Getting started. Before you begin coding, do the following:
Read Sections 3.1 and 3.2 of the textbook to learn the basics of object-oriented programming and how to use the Picture(https://introcs.cs.princeton.edu/java/11cheatsheet/%23Picture) and Color data types.
Download the project files - classifier.zip (https://www.cs.princeton.edu/courses/archive/fall20/cos126/assignments/classifier/classifier.zip)
Overall Requirements
In Part 1 of this assignment, we provide a ML library - MultiPerceptron - for classifying vectors of n real numbers into one of m classes. In Part 2 (next week), you will implement this ML library using perceptrons.
Your task is to write an image classifier client, named ImageClassifier.java, that classifies images using the MultiPerceptron data type.
Note that you will not implement MultiPerceptron.java until Part 2 of this assignment. The focus of Part 1 is on using data types, whereas the focus of Part 2 is on creating data types. For now, you must use (the pre-compiled) MultiPerceptron.class that is included in the project folder.
Organize your client according to the following API:
public class ImageClassifier {
// Creates a feature vector (1D array) from the given picture.
public static double[] extractFeatures(Picture picture)
// See below.
public static void main(String[] args) }
1.Download/unzip the (classifier.zip) project folder. (https://www.cs.princeton.edu/courses/archive/fall20/cos126/assignments/classifier/classifier.zip)
Feature extraction.
a) Review Section 3.1 of the textbook, especially Program 3.1.4 (Grayscale.java) for using the Picture and Color data types. Note that the images are already grayscale, so you dont need to use Luminance.java. In particular, the red, green, and blue components are equal, so you can use any of getRed() or getGreen(), or getBlue() to get the grayscale value.
b) Create a Picture object for the image 49785.png (in the project folder) and display it in a window. (Remove or comment out this code after you have successfully displayed the image.)
c) Create a Picture object for the image image3-by-3.png (in the project folder) corresponding to the 3-by-3 example given below. Extract its width and height and print the values to standard output. Then, extract the grayscale values of the pixels and print. If its not already in row-major order, adjust your code so that it prints the values in the specified order.
If you are using IntelliJ, do not type the import java.awt.Color; statement that is normally needed to access Javas color data type. IntelliJ is pre-configured to automatically add import statements when needed (and remove them when not needed).
d) Create a one-dimensional array of length width height and copy the grayscale values to the array. Print the values of this array to confirm you can create a vector (row-major order) of values from a Picture object.
e) Using the code from steps (c) and (d) as a guide, implement the static method extractFeatures() that takes a Picture as an argument and returns the grayscale values as a double[] in row-major order.
f) Write a main() method that tests extractFeatures().
Parsing input files.
a) Review the In data type from Section 3.1, which is an object-oriented version of StdIn. You need the object-oriented version in this program since you will be reading from two different files in the same program.
b) Create an In object for the training file digits-training20.txt. Read the integers m, width and height, and print them to standard output. Read pairs of filenames (strings) and labels (integers) and print them to standard output.
c) For each image, create a new Picture object and display in its own window. (Note - the image displays may overlap!)
d) Repeat the previous two steps for the testing file digits-testing10.txt.
e) Modify your program to take the names of the testing and training files as command-line arguments.
Classifying images.
a) Classifier. After reading m, width, and height from the training file, create a MultiPerceptron object of the correct dimensions.
b) Training. For each training image, train the classifier using the corresponding label.
c) Testing. For each testing image, predict its class. Print each misclassified image to standard output and tabulate statistics on the number of misclassified images.
d) Error rate. After training and testing, print the error rate to standard output in the
specified format.
e) Test. Test your program on some small data files, such as digits-training20.txt and digits-testing10.txt.
Now, the fun part. Use large training and testing input files. Be prepared to wait for 1 minute (or more) while your program processes 60,000 images.
Here is the MultiPerceptron API that you will use:
public class MultiPerceptron {
// Creates a multi-perceptron object with m classes // and size of the feature vector n. public MultiPerceptron(int m, int n)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started