ML 1
ML 1
ML 1
PROJECT - M
IKA MODALEDUDAMA…?
PROJECT - M 1
okasari download chesaka open cheyyandi.
oka welcome page ostadi adi close chei! ne desktop meda normal ga oka folder
create chesi dani peru project ani pettu, and ah empty folder ni drag chesi vs code
lo padesey!
like this ➖
STEP1:- Installing Python:
3. Click on the link that says "Download Python" (this should lead to the official
Python website).
PROJECT - M 2
4. Choose the latest version of Python and download the installer.
5. Once the download is complete, open the downloaded file and follow the
installation instructions:
On Windows: Run the installer, check "Add Python to PATH," and follow the
setup wizard.
On Mac: Open the downloaded .pkg file and follow the installation
instructions.
1. Open the File Explorer (Windows), Finder (Mac), or your file manager
(Linux).
2. Navigate to a location where you want to create your project folder (e.g.,
Documents).
PROJECT - M 3
3.2 Installing Libraries:
1. In the terminal, type the following commands and press Enter after each
one:
import ssl
ssl._create_default_https_context = ssl._create_unverif
ied_context
import tensorflow as tf
from tensorflow.keras.datasets import mnist
import matplotlib.pyplot as plt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
PROJECT - M 4
from PIL import Image, ImageOps
import numpy as np
Code Explanation
import ssl
ssl._create_default_https_context = ssl._create_unverified
_context
import tensorflow as tf
from tensorflow.keras.datasets import mnist
import matplotlib.pyplot as plt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from PIL import Image, ImageOps
import numpy as np
Explanation:
1. SSL Context:
2. Import Libraries:
: The main library used for building and training the machine
tensorflow
learning model.
PROJECT - M 5
matplotlib.pyplot : A plotting library used to display images.
ah tarwata
Explanation:
Explanation:
PROJECT - M 6
Each pixel value in the images ranges from 0 to 255. Dividing by 255.0
normalizes these values to a range of 0 to 1, making the data easier for
the model to process.
next edi :-
Explanation:
1. plt.imshow(x_train[0], cmap='gray'):
This line tells our drawing tool (matplotlib) to show the first picture in
our training set.
2. plt.show():
This command tells the drawing tool to display the picture on the
screen.
Recap
We brought in special tools and a box of handwritten numbers.
PROJECT - M 7
We opened the box and separated the pictures and answers into
training and testing sets.
PROJECT - M 8
Code Explanation
Explanation:
Explanation:
2. Flatten(input_shape=(28, 28)):
PROJECT - M 9
3. Dense(128, activation='relu'):
4. Dense(10, activation='softmax'):
Explanation:
1. model.compile( ... ):
2. optimizer='adam':
3. loss='sparse_categorical_crossentropy':
PROJECT - M 10
loss is like the computer's way of measuring how wrong it
is. Sparse categorical crossentropy is a method to calculate this
error. It helps the computer understand how to improve its
guesses.
4. metrics=['accuracy']:
Recap
We brought in tools and ingredients to build our model.
4o
PROJECT - M 11
6.1 Writing Code to Train the Model:
2. Explanation:
fittrains the model using the training data for 5 epochs (iterations over
the dataset).
2. Explanation:
PROJECT - M 12
ah tarwata edi :
Explanation:
ah tarwata edi:-
PROJECT - M 13
# Path to the handwritten digit image
image_path = 'digit.png'
new_image = preprocess_image(image_path)
Explanation:
ah tarwata edi :
Explanation:
PROJECT - M 14
plt.imshow(new_image.reshape(28, 28), cmap='gray')
plt.title(f"Predicted Digit: {predicted_digit}")
plt.show()
Explanation:
The test image is displayed with the predicted digit as the title.
anni step by step okko line of code raskuntu pothe ne code konchem ela
kanabadtadi!:-
code in digits.py :
def preprocess_image(image_path):
img = Image.open(image_path).convert('L')
img = ImageOps.invert(img)
img = img.resize((28, 28))
img = np.array(img) / 255.0
PROJECT - M 15
img = img.reshape(1, 28, 28)
return img
Explanation:
e part daggara ‘digit.png’ unnadi kada so nuv em chestav ante oka pen paper
teskoni
PROJECT - M 16
0 nundi 9 daka oka 5 numbers rai. and danni photo tesi digit.png ani perutho ne
project folder lo padey!
digits.py :
import ssl
ssl._create_default_https_context = ssl._create_unverified_co
ntext
import tensorflow as tf
from tensorflow.keras.datasets import mnist
import matplotlib.pyplot as plt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from PIL import Image, ImageOps
import numpy as np
PROJECT - M 17
Dense(128, activation='relu'),
Dense(10, activation='softmax')
])
PROJECT - M 18
plt.imshow(new_image.reshape(28, 28), cmap='gray')
plt.title(f"Predicted Digit: {predicted_digit}")
plt.show()
Explanation:
1. Importing Libraries:
We load the MNIST dataset, which contains handwritten digit images and
their labels.
We display the first image from the training dataset to see what it looks
like.
We compile the model with the Adam optimizer, sparse categorical cross-
entropy loss function, and accuracy metric.
PROJECT - M 19
We evaluate the model's performance using the test data and print the
accuracy.
We use the model to predict the digit in the new image and print the
predicted digit.
By running this complete code, you will be able to train a neural network on the
MNIST dataset, evaluate its performance, and use it to predict new handwritten
digit images.
PROJECT - M 20
ela ante:-
On Windows:
.\env\Scripts\activate
On Mac/Linux:
source env/bin/activate
PROJECT - M 21
Run Your Python Script:
python digits.py
make sure edi run chese munde nuv ne project folder lo white paper meda oka
number ni rasi digit.png ane name tho save chesi pettali! ah tarwate run
cheyyali, cheyyagane oka image ostadi adi close cheyyagane modelk
automatic ga train iyyi oka number ni predict chestadi!
the more you train , the more accurate it gets in predicting it! simple as that!
PROJECT - M 22