Deep Learning Lab Manual PDF
Deep Learning Lab Manual PDF
DEEP LEARNING
B.Tech CSE 7th Semester
Practical 1: Create a Neural Network
<!DOCTYPE html>
<html>
<script src="//unpkg.com/brain.js"></script>
<body>
<div id="demo"></div>
<script>
network.train([
{input:[0,0], output:{zero:1}},
{input:[0,1], output:{one:1}},
{input:[1,0], output:{one:1}},
{input:[1,1], output:{zero:1}},
]);
document.getElementById("demo").innerHTML =
</script>
</body>
</html>
OUTPUT:
A Neural Network is created with: new brain.NeuralNetwork()
<html>
<style>
</style>
<body>
<div style="background-color:RGB(0,0,0)">
<p style="color:white">RGB(0,0,0)</p>
</div>
<div style="background-color:RGB(255,255,0)">
<p style="color:black">RGB(255,255,0)</p>
</div>
<div style="background-color:RGB(255,0,0)">
<p style="color:white">RGB(255,0,0)</p>
</div>
<div style="background-color:RGB(255,255,255)">
<p style="color:black">RGB(255,255,255)</p>
</div>
<div style="background-color:RGB(192,192,192)">
<p style="color:black">RGB(192,192,192)</p>
</div>
<div style="background-color:RGB(65,65,65)">
<p style="color:white">RGB(65,65,65)</p>
</div>
</body>
</html>
OUTPUT:
<!DOCTYPE html>
<html>
<script src="//unpkg.com/brain.js"></script>
<body>
<div id="demo"></div>
<script>
net.train([
// Lightgrey (192,192,192)
// Black (0, 0, 0)
]);
document.getElementById("demo").innerHTML =
</script>
</body>
</html>
OUTPUT:
With network.run([0,0,128/255]), you ask "What is the likely output of dark blue?"
Dark: 95%
Light: 4%
Practical 3. Introduction to TENSOR
Tensors
TensorFlow.js is a JavaScript library to define and operate on Tensors.
The main data type in TensorFlow.js is the Tensor.
A Tensor is much the same as a multidimensional array.
A Tensor contains values in one or more dimensions:
Property Description
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<body>
<h1>TensorFlow JavaScript</h1>
<h3>Creating a tensor:</h3>
<div id="demo"></div>
<script>
document.getElementById("demo").innerHTML = tensorA;
</script>
</body>
</html>
OUTPUT:
Tensor Shape
A Tensor can also be created from an array and a shape parameter:
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<body>
<h1>TensorFlow JavaScript</h1>
<div id="demo"></div>
<script>
const myArr = [1, 2, 3, 4];
document.getElementById("demo").innerHTML = tensorA;
</script>
</body>
</html>
OUTPUT:
Practical 5:Retrieve Tensor Values
You can get the data behind a tensor using tensor.data():
<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<body>
<h1>TensorFlow JavaScript</h1>
<div id="demo"></div>
<script>
// Result: 1,2,3,4
function display(data) {
document.getElementById("demo").innerHTML = data;
</script>
</body>
</html>
OUTPUT:
Practical 6: Tensor Data Types
A Tensor can have the following data types:
bool
int32
float32 (default)
complex64
string
When you create a tensor, you can specify the data type as the third parameter:
<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<body>
<h1>TensorFlow JavaScript</h1>
<div id="demo"></div>
<script>
document.getElementById("demo").innerHTML = tensorA.dtype;
</script>
</body>
</html>
OUTPUT:
Practical 7:TensorFlow Operations
Addition
You can add two tensors using tensorA.add(tensorB):
<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<body>
<h2>JavaScript</h2>
<div id="demo"></div>
<script>
// Tensor Addition
document.getElementById("demo").innerHTML = tensorNew;
</script>
</body>
</html>
OUTPUT:
Tensor Subtraction
You can subtract two tensors using tensorA.sub(tensorB):
<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<body>
<h2>JavaScript</h2>
<div id="demo"></div>
<script>
// Tensor Subtraction
document.getElementById("demo").innerHTML = tensorNew;
</script>
</body>
</html>
OUTPUT:
Tensor Division
You can divide two tensors using tensorA.div(tensorB):
// Tensor Division
const tensorNew = tensorA.div(tensorB);
// Result: [ 2, 2, 3, 4 ]
OUTPUT:
Practical 8:Tensorflow Models
Models and Layers are important building blocks in Machine Learning.
For different Machine Learning tasks you must combine different types of Layers into a
Model that can be trained with data to predict future values.
A Tensorflow Project
Collecting Data
Creating a Model
Adding Layers to the Model
Compiling the Model
Training the Model
Using the Model
<html>
<script
src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js
"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<body>
<h2>TensorFlow.js</h2>
<script>
const ys = xs.mul(1.2).add(5);
model.add(tf.layers.dense({units:1, inputShape:[1]}));
function myFunction() {
result.data().then(y => {
xArr.push(x);
yArr.push(Number(y));
});
document.getElementById('message').style.display="none";
// Define Data
// Define Layout
const layout = {
};
// Display Plot
</script>
</body>
</html>
OUTPUT:
Practical 9 :Predicts 10 y values, given 10 x values, and calls a
function to plot the predictions in a graph
Scatter Plots
<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tfjs-
vis.umd.min.js"></script>
<body>
<h2>TensorFlow Visor</h2>
<div id="demo"></div>
<script>
tfvis.render.scatterplot(surface, data);
</script>
</body>
</html>
OUTPUT:
Bar Graphs
<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tfjs-
vis.umd.min.js"></script>
<body>
<h2>Tensorflow Visor</h2>
<div id="demo"></div>
<script>
const data = [
];
tfvis.render.barchart(surface, data);
</script>
</body>
</html>
OUTPUT:
Line Graphs
<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tfjs-
vis.umd.min.js"></script>
<body>
<h2>Tensorflow Visor</h2>
<div id="demo"></div>
<script>
let values = [
{x: 1, y: 20},
{x: 2, y: 30},
{x: 3, y: 15},
{x: 4, y: 12}
];
tfvis.render.linechart(surface, {values});
</script>
</body>
</html>
OUTPUT: