O'ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI MUHAMMAD AL-XORAZMIYNOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Kafedra:Marketing va menejment
Fan: Boshqaruv tamoyillari
Amaliy mashg’ulot
Guruh: 712-19
Bajardi:Yo`ldoshev Xushnudbek
Tekshirdi:Ochilov Mannon
import os
import json
import numpy as np
import pandas as pd
import keras
from keras.callbacks import Callback
from keras.datasets import cifar10
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D
from sklearn.metrics import confusion_matrix, f1_score, precision_score, recall_score
from sklearn.model_selection import train_test_split
Using TensorFlow backend.
os.listdir('../input')
['reducing-image-sizes-to-32x32', 'iwildcam-2019-fgvc6']
# The data, split between train and test sets:
x_train = np.load('../input/reducing-image-sizes-to-32x32/X_train.npy')
x_test = np.load('../input/reducing-image-sizes-to-32x32/X_test.npy')
y_train = np.load('../input/reducing-image-sizes-to-32x32/y_train.npy')
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')
x_train shape: (196299, 32, 32, 3)
196299 train samples
153730 test samples
# Convert the images to float and scale it to a range of 0 to 1
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255.
x_test /= 255.
In [5]:
linkcode
class Metrics(Callback):
def on_train_begin(self, logs={}):
self.val_f1s = []
self.val_recalls = []
self.val_precisions = []
def on_epoch_end(self, epoch, logs={}):
X_val, y_val = self.validation_data[:2]
y_pred = self.model.predict(X_val)
y_pred_cat = keras.utils.to_categorical(
y_pred.argmax(axis=1),
num_classes=num_classes
)
_val_f1 = f1_score(y_val, y_pred_cat, average='macro')
_val_recall = recall_score(y_val, y_pred_cat, average='macro')
_val_precision = precision_score(y_val, y_pred_cat, average='macro')
self.val_f1s.append(_val_f1)
self.val_recalls.append(_val_recall)
self.val_precisions.append(_val_precision)
print((f"val_f1:
Dostları ilə paylaş: |