-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneural-net.py
More file actions
60 lines (43 loc) · 2.9 KB
/
neural-net.py
File metadata and controls
60 lines (43 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
"""--------------------------------------------------------------------------------------------------------------------------------------------------------------------
NEURAL NETWORKS PROGRAM
--------------------------------------------------------------------------------------------------------------------------------------------------------------------"""
# dataset
data = keras.datasets.fashion_mnist
# training and testing data
(train_images, train_labels), (test_images, test_labels) = data.load_data()
# there are ten labels for this specific dataset... between 0 and 9
# each image that we have will have a specific label assigned to it...
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
#print(train_labels[6])
# by dividing by 255.0, we shrink our data
train_images = train_images/255.0 # the data is in numpy arrays
test_images = test_images/255.0
#print(train_images[7])
#plt.imshow(train_images[6], cmap=plt.cm.binary)
#plt.show()
#print(class_names)
# defining the model and layers...in other words; the architecture.
# Whenever you''re passing information thats in 2d or 3d array, you need to flatten that
# information to pass it into an individual neuron as opposed to passing a whole list into a single neuron.
model = keras.Sequential([ # a sequence of layers
keras.layers.Flatten(input_shape=(28,28)), # flattened layer
keras.layers.Dense(128, activation="relu"), # dense layer...a fully connected layer which means, fully connected neural networks
keras.layers.Dense(10, activation="softmax") # notice the neuron count of 10....the previous neuron count is 128.
#(each neuron is connected to the next layer.)
]) # relu means: rectified linear unit for the activation function setting.
# what softmax does is it picks values for each neuron, so that all of those values add up to one.
# setting up parameters for our model...these are functions that use these algorithms.
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
# training our model
model.fit(train_images, train_labels, epochs=10) #epochs means how many times the model is going to see this information.
# epochs will randomly pick images and labels correspondent to each other, and its going to feed that through the neural network.
# how many epochs you decide is how many times you're going to see the same image.
# the order in which images will come in will influence how parameters and things are tweaked with the network.
# the epochs gives the images in a different order everytime randomly.
# test the model using the test images...to see how many images it gets correct....see if it is learning...
test_loss, test_acc = model.evaluate(test_images, test_labels)
print("Tested Acc: ", test_acc)