Python x#u train=x#u train.astype(';float64';)值错误:使用序列设置数组元素

Python x#u train=x#u train.astype(';float64';)值错误:使用序列设置数组元素,python,settings,valueerror,Python,Settings,Valueerror,基于keras的Python图像分类 Error是ValueError:设置具有序列的数组元素。 请帮忙 从pathlib导入路径 进口干酪 在此处输入numpy作为npenter代码 从keras.models导入顺序 从keras.layers导入稠密、衰减、展平、Conv2D、MaxPoolig2D 从keras.preprocessing导入图像 # Path to folders with training data Empty_Morning = Path("images&

基于keras的Python图像分类 Error是ValueError:设置具有序列的数组元素。 请帮忙

从pathlib导入路径 进口干酪 在此处输入numpy作为npenter代码 从keras.models导入顺序 从keras.layers导入稠密、衰减、展平、Conv2D、MaxPoolig2D 从keras.preprocessing导入图像

# Path to folders with training data
Empty_Morning = Path("images") / "EmptyMorning"
not_Empty_Morning_Path = Path("images") / "PeoplePlayingMorning"

images = []
labels = []

# Not Plastic Bottles Images
for img in not_Empty_Morning_Path.glob("*.jpg"):
    # load the image from disk
    img = image.load_img(img)

    # convert the image to a numpy array
    img_array = image.img_to_array(img)

    # Add the image to the list of images
    images.append(img_array)

    # for each 'not plastic bottle image, the expected value should be 0
    labels.append(0)

# for all plastic bottles images
for img in Empty_Morning.glob("*.jpg"):
    # Load the image from disk
    img = image.load_img(img)

    # convert the image to an array
    img_array = image.img_to_array(img)

    # add image to the list of images
    images.append(img_array)

    # for all plastic bottles image (because it is another class), the expected value should be 1
    labels.append(1)

x_train = np.array(images)
y_train = np.array(labels)

x_train = x_train.astype('float34')
x_train /= 255

y_train = keras.utils.to_categorical(y_train, 2)

# Create a model and add layers
model = Sequential()

model.add(Conv2D(32, (3, 3), padding="same", activation="relu", input_shape=(190, 270, 3)))
model.add(Conv2D(32, (3, 3), activation="relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.15))

model.add(Conv2D(64, (3, 3), padding="same", activation="relu"))
model.add(Conv2D(64, (3, 3), activation="relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.15))

model.add(Flatten())
model.add(Dense(512, activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(2, activation="softmax"))

# Compile the Model
model.compile(
    loss="categorical_crossentropy",
    optimizer="adam",
    metrics=['accuracy']
)

# Train the model
model.fit(
    x_train,
    y_train,
    batch_size=32,
    epochs=30,
    validation_data=(x_train, y_train),
    shuffle=True
)

# save neutral network structure
model_structure = model.to_json()
p = Path("model_structure.json")
p.write_text(model_structure)

# save neutral network's trained weights
model.save_weights("model_weights.h5")

如果试图将列表中元素的数据类型更改为浮动:

X_train = list(map(float, X_train))

我建议您阅读有关如何在StackOverflow上制定问题的指南