Смотрите. У меня есть файл с таким кодом: import numpy as np
import matplotlib.pyplot as plt
import streamlit as st
from PIL import Image
import tensorflow as tf
from tensorflow.keras.datasets import cifar10
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Flatten, Dense
from tensorflow.keras.utils import to_categorical
def create_model():
(x_train, y_train), (x_val, y_val) = cifar10.load_data()
x_train = x_train / 255
x_val = x_val / 255
y_train = to_categorical(y_train, 10)
y_val = to_categorical(y_val, 10)
model = Sequential([Flatten(input_shape=(32, 32, 3)), Dense(1000, activation='relu'), Dense(10, activation='softmax')])
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=64, epochs=61, validation_data=(x_val, y_val))
model.save('my_model.keras')
def main():
st.title('Классификатор на основе Cifar10 ')
st.write('Загрузи картинку')
file = st.file_uploader('Загрузи .jpg или .png', type=['jpg', 'png'])
if not file:
st.text('Это не .jpg или .png')
else:
image = Image.open(file)
st.image(image, use_column_width=True)
resized = image.resize((32, 32))
img_array = np.array(resized) / 255
img_array = img_array.reshape((1, 32, 32, 3))
model = tf.keras.models.load_model('my_model.keras')
predictions = model.predict(img_array)
classes = ['самолёт', 'автомобиль', 'птица', 'кошка', 'олень', 'собака', 'лягушка', 'лошадь', 'корабль', 'грузовик']
fig, ax = plt.subplots()
y_pos = np.arange(len(classes))
ax.barh(y_pos, predictions[0], align='center')
ax.set_yticks(y_pos)
ax.set_yticklabels(classes)
ax.invert_yaxis()
ax.set_xlabel('Вероятность')
ax.set_title('Что это')
st.pyplot(fig)
if name == 'main':
main()
И мне выдаёт такую ошибку: C:\Users\lenovo.venv\Scripts\python.exe "C:\Users\lenovo\AppData\Roaming\JetBrains\PyCharmCE2023.3\scratches\Приложение для распознавания объектов.py"
2024-10-13 08:00:32.909439: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
2024-10-13 08:00:35.385881: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
C:\Users\lenovo.venv\Lib\site-packages\keras\src\layers\reshaping\flatten.py:37: UserWarning: Do not pass an input_shape/input_dim argument to a layer. When using Sequential models, prefer using an object as the first layer in the model instead.
super().(**kwargs)
2024-10-13 08:00:56.566130: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
File "C:\Users\lenovo\AppData\Roaming\JetBrains\PyCharmCE2023.3\scratches\Приложение для распознавания объектов.py", line 20, in
create_model()
File "C:\Users\lenovo\AppData\Roaming\JetBrains\PyCharmCE2023.3\scratches\Приложение для распознавания объектов.py", line 18, in create_model
model.fit(x_train, y_train, batch_size=64, epochs=61, validation_data=(x_val, y_val))
File "C:\Users\lenovo.venv\Lib\site-packages\keras\src\utils\traceback_utils.py", line 122, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\lenovo.venv\Lib\site-packages\tensorflow\python\framework\constant_op.py", line 96, in convert_to_eager_tensor
value = value.copy()
^^^^^^^^^^^^
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 586. MiB for an array with shape (50000, 32, 32, 3) and data type float32