tworzenie modelu
This commit is contained in:
parent
19aa09b897
commit
faba290bda
45
siec.py
Normal file
45
siec.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import numpy
|
||||||
|
from keras.datasets import mnist
|
||||||
|
from keras.layers import Conv2D, MaxPooling2D
|
||||||
|
from keras.layers import Dense, Dropout, Flatten
|
||||||
|
from keras.models import Sequential
|
||||||
|
from keras.utils import np_utils
|
||||||
|
from keras_preprocessing.image import load_img, img_to_array
|
||||||
|
|
||||||
|
|
||||||
|
img_rows, img_cols = 28, 28
|
||||||
|
input_shape = (img_rows, img_cols, 1)
|
||||||
|
|
||||||
|
producent = []
|
||||||
|
def imageClass(model):
|
||||||
|
model.add(Conv2D(75, kernel_size=(5, 5),
|
||||||
|
activation='relu',
|
||||||
|
input_shape=input_shape))
|
||||||
|
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||||
|
model.add(Dropout(0.2))
|
||||||
|
model.add(Conv2D(100, (5, 5), activation='relu'))
|
||||||
|
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||||
|
model.add(Dropout(0.2))
|
||||||
|
model.add(Flatten())
|
||||||
|
model.add(Dense(500, activation='relu'))
|
||||||
|
model.add(Dropout(0.5))
|
||||||
|
model.add(Dense(10, activation='softmax'))
|
||||||
|
|
||||||
|
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
|
||||||
|
|
||||||
|
nmodel = Sequential()
|
||||||
|
imageClass(nmodel)
|
||||||
|
nmodel.load_weights('model_weights.h5')
|
||||||
|
|
||||||
|
def imgSkan():
|
||||||
|
img_width, img_height = 28, 28
|
||||||
|
new_image = load_img('cyfra.png', target_size=(img_width, img_height), color_mode = "grayscale")
|
||||||
|
new_image = img_to_array(new_image)
|
||||||
|
new_image = new_image.reshape((1,) + new_image.shape)
|
||||||
|
|
||||||
|
prediction = nmodel.predict(new_image)
|
||||||
|
prediction = numpy.argmax(prediction)
|
||||||
|
print("Producent:", prediction)
|
||||||
|
producent.append(prediction)
|
||||||
|
|
||||||
|
imgSkan()
|
Loading…
Reference in New Issue
Block a user