Tensorflow
Bul qóllanbada 10 taypa daǵı 70 000 kúl reń suwretti óz ishine alǵan Fashion
MNIST maǵlıwmatlar kompleksinen paydalanıladı. Súwretler bul jerde
kórsetilgeni sıyaqlı, tómen ólshem degi (28 x28 piksel) kiyimdiń bólek
buyımların kórsetedi:
Bul jerde tarmaqtı úyretiw ushın 60 000 súwret hám tarmaq suwretlerdi
klassifikaciyalawdı qanshellilik anıq úyrengenligin bahalaw ushın 10 000 súwret
isletiledi. FASHION MNIST-ga tuwrıdan- tuwrı TensorFlow-den kiriwińiz
múmkin. Fashion MNIST maǵlıwmatların tuwrıdan-tuwrı TensorFlow'dan import
etiń hám júkleń::
1- Bul jerde biz tensorflow, numpy, matplotlib kitapxanalarin shaqiramiz
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
Mag'liwmatlardi oqitiw
**Fashion mnistti oqitip oni traning_set ham test_set bolg'an 2 ozgeriwshige berip
to'mendegi listlerge beremis.**
RASMLAR
=
tf.keras.datasets.fashion_mnist
training_set,test_set=RASMLAR.load_data()
(rasmlar_massivi,rasmlar_javobi)=training_set
(tekshirish_rasmlari, tekshirish_javoblari)=test_set
Downloading data from
https://storage.googleapis.com/tensorflow/tf- keras-
datasets/train-labels-idx1-ubyte.gz
32768/29515 [=================================] - 0s 0us/step
40960/29515 [=========================================] - 0s
0us/step
Downloading data from
https://storage.googleapis.com/tensorflow/tf
-
keras-datasets/train-images-idx3-ubyte.gz
26427392/26421880 [==============================] - 0s 0us/step
26435584/26421880 [==============================] - 0s 0us/step
Downloading data from
https://storage.googleapis.com/tensorflow/tf- keras-
datasets/t10k-labels-idx1-ubyte.gz
16384/5148
[=========================================================
============
==========================] - 0s 0us/step
Downloading data from
https://storage.googleapis.com/tensorflow/tf- keras-
datasets/t10k-images-idx3-ubyte.gz
4423680/4422102 [==============================] - 0s 0us/step
4431872/4422102 [==============================] - 0s 0us/step
***"kategoriyalardin' sani bul jerde 10 bolip, bular fashion_mnist te berilgen.
olar 0,1,2,3,....9 ga shekem belgilenedi. Suwretlerdin' ati shig'iwi ushin olarg'a at
beremiz***
kiyimlar_nomlari=['Futbolka', #0
'Shalbar',
#1
'Sviter',
#2
'Erler kóylegi', #3
'Palto',
#4
'Sandalet', #5
'Kóylek',
#6
'Krossovka', #7
'Sumka',
#8
'Etik'
#9
]
Kitapxanadagi magliwmatti tanlap alamiz!!!
plt.imshow(tekshirish_rasmlari[99]) kiyimlar_nomlari[tekshirish_javoblari[99]]
{"type":"string"}
Mag'liwmatlar ushin su'wretler bizde matrica turinde boladi.Su'wretler ko'lemin
kishireytiw ushin olardi 255.0 ke bo'lemiz. 255.0ke bo'lgende ha'r bir element
bo'linedi.
**To'mende formula arqali berilgen kategoriyalardin' duris yamasa qateligi
tekseriledi. Tekseriw procesi su'wret penen onin ati birdey boliwi kerek.
rasmlar_massivi = rasmlar_massivi/255.0 tekshirish_rasmlari=tekshirish_rasmlari
/255.0
plt.figure(figsize=(15,15))
#15x15 dyum figsize(eni ham biyiklik)
for i in range(25):
plt.subplot(5,5,i+1)
#5x5 suwretler qatarin shigaradi
plt.xticks([])
plt.yticks([])
plt.imshow(rasmlar_massivi[i],
cmap=plt.cm.binary)
#imshow=korsetiw
cmap=renler xariytasin ozgertiw plt.cm.binary=kulren' cvet qiladi
plt.xlabel(kiyimlar_nomlari[rasmlar_javobi[i]])
# kiyimler atlarin x
kosherde shigaradi
plt.show()
* Modelin duziw*
•
qatlamda Su'wretimizdin' olsemi 28x28 bolganliqtan 784 neyronnan ibarat.
•
qatlam 128 neyron bolip ol 784 neyronnan signal qabillaydi. Ham
birinshi qatlamdag'i har bir neyron ekinshi qatlamdag'i neyronlar menen
baylanisadi.
•
qatlam 10 neyronnan turadi og'an 128 neyronnan signal keledi. 10 neyron
degenimiz bizde 10 kategoriya bar. Bunda RULE aktivacion funkciasinan
paydalandiq
model
=
tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28,28)),
tf.keras.layers.Dense(128,activation='relu'), tf.keras.layers.Dense(10)
])
loss qatelikti ko'rsetedi. 3-qatlamnan aling'an qa'teliklerdi alip salmaqlardi
o'zgertedi.
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy']) #aniqliq da'rejesi
Bul jerde oqitilg'an modeldin har birinin epochs dagi loss da'rejesi aniqliq
da'rejesin aliwg'a boladi. Keyin qaysi biri en' ulken bolsa soni bizge suwret
kategoriyasin jiberedi.
model.fit(rasmlar_massivi,rasmlar_javobi,epochs=10)
Epoch 1/10
1875/1875 [==============================] - 6s 3ms/step - loss:
0.4942 - accuracy: 0.8249
Epoch 2/10
1875/1875 [==============================] - 5s 3ms/step - loss:
0.3732 - accuracy: 0.8658
Epoch 3/10
1875/1875 [==============================] - 6s 3ms/step - loss:
0.3360 - accuracy: 0.8764
Epoch 4/10
1875/1875 [==============================] - 5s 3ms/step - loss:
0.3128 - accuracy: 0.8856
Epoch 5/10
1875/1875 [==============================] - 5s 3ms/step - loss:
0.2951 - accuracy: 0.8907
Epoch 6/10
1875/1875 [==============================] - 5s 3ms/step - loss:
0.2787 - accuracy: 0.8971
Epoch 7/10
1875/1875 [==============================] - 5s 3ms/step - loss:
0.2665 - accuracy: 0.9011
Epoch 8/10
1875/1875 [==============================] - 5s 3ms/step - loss:
0.2561 - accuracy: 0.9041
Epoch 9/10
1875/1875 [==============================] - 5s 3ms/step - loss:
0.2472 - accuracy: 0.9077
Epoch 10/10
1875/1875 [==============================] - 5s 3ms/step - loss:
0.2380 - accuracy: 0.9114
model_softmax=tf.keras.Sequential([
model, tf.keras.layers.Softmax()
]
)
predictions = model_softmax.predict(tekshirish_rasmlari)
plt.imshow(tekshirish_rasmlari[101])
plt.xlabel(kiyimlar_nomlari[np.argmax(predictions[101])])
Text(0.5, 0, 'Kóylek')
Do'stlaringiz bilan baham: |