Skip to content

Update C1_W4_Assignment.js #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions C1_Browser-based-TF-JS/W4/assignment/C1_W4_Assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,24 @@ async function train() {
// using ReLu activation functions where applicable.
model = tf.sequential({
layers: [

// YOUR CODE HERE

tf.layers.flatten({inputShape: mobilenet.outputs[0].shape.slice(1)}),
tf.layers.dense({units: 100, activation: 'relu'}),
tf.layers.dense({units: 50, activation: 'relu'}),
tf.layers.dense({units: 5, activation: 'softmax'})
]
});


// Set the optimizer to be tf.train.adam() with a learning rate of 0.0001.
const optimizer = // YOUR CODE HERE
const optimizer = tf.train.adam(0.0001);


// Compile the model using the categoricalCrossentropy loss, and
// the optimizer you defined above.
model.compile(// YOUR CODE HERE);
model.compile({
optimizer: optimizer,
loss: 'categoricalCrossentropy'
});

let loss = 0;
model.fit(dataset.xs, dataset.ys, {
Expand Down Expand Up @@ -71,12 +75,10 @@ function handleButton(elem){
spockSamples++;
document.getElementById("spocksamples").innerText = "Spock samples:" + spockSamples;
break;

// Add a case for lizard samples.
// HINT: Look at the previous cases.

// YOUR CODE HERE

case "4":
lizardSamples++;
document.getElementById("lizardsamples").innerText = "Lizard samples:" + lizardSamples;
break;

}
label = parseInt(elem.id);
Expand Down Expand Up @@ -108,12 +110,9 @@ async function predict() {
case 3:
predictionText = "I see Spock";
break;

// Add a case for lizard samples.
// HINT: Look at the previous cases.

// YOUR CODE HERE

case 4:
predictionText = "I see Lizard";
break;

}
document.getElementById("prediction").innerText = predictionText;
Expand Down Expand Up @@ -154,4 +153,4 @@ async function init(){
}


init();
init();