Когда я попытался запустить модель, у меня возникла проблема:
Код: Выделить всё
Input 0 of layer "Conv1" is incompatible with the layer: expected axis -1 of input shape to
have value 3, but received input with shape (None, 200, 200, 1)
Код: Выделить всё
from tensorflow.keras.preprocessing import image as IMAGE
import numpy as np
import cv2
import os
os.environ["CUDA DEVICE ORDER"]="PCI BUS ID"
os.environ["CUDA VISIBLE DEVICES"]="0"
from tensorflow.keras import Model
from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2, preprocess_input
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing import image
import matplotlib.pyplot as plt
Код: Выделить всё
import tensorflow as tf
from PIL import Image
from google.colab.patches import cv2_imshow
Код: Выделить всё
!pip3 install tensorflowjs
Код: Выделить всё
import tensorflowjs as tfjs
Код: Выделить всё
train = ImageDataGenerator(rescale = 1/255)
test = ImageDataGenerator(rescale = 1/255)
val = ImageDataGenerator(rescale = 1/255)
Код: Выделить всё
training_set = train.flow_from_directory("/content/drive/MyDrive/mpox_data/Train",
target_size=(200,200),
batch_size = 15,
class_mode = "categorical",
color_mode='rgb'
)
testing_set = test.flow_from_directory("/content/drive/MyDrive/mpox_data/Test",
target_size=(200,200),
batch_size = 15,
class_mode = "categorical",
color_mode='rgb'
)
validation_set = val.flow_from_directory("/content/drive/MyDrive/mpox_data/Val",
target_size=(200,200),
batch_size=15,
class_mode = "categorical",
color_mode='rgb'
)
Код: Выделить всё
x, y = training_set[0]
a, b = testing_set[0]
d, c = validation_set[0]
Код: Выделить всё
base_model = MobileNetV2(weights = "imagenet", include_top = False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(42, activation="relu")(x)
x = Dense(64, activation = "relu")(x)
x = Dense(32, activation="relu")(x)
preds = Dense(2, activation = "sigmoid")(x)
model = Model(inputs = base_model.input, outputs = preds)
Код: Выделить всё
epochs = 5
optimizer = Adam(learning_rate = 0.0003)
model.compile(loss = "binary_crossentropy", optimizer = optimizer, metrics = ["Accuracy"])
model.fit(training_set, validation_data = validation_set, epochs = epochs, shuffle=True)
Почему моя программа не работает, и как это исправить, чтобы модель могла продолжить обучение на изображениях в оттенках серого?
Подробнее здесь: https://stackoverflow.com/questions/789 ... ale-images