我试图在每个检查点将我的 CNN 保存到一个文件中。但是我应该使用哪个扩展名作为我的文件目录?另外,我是否需要model.save(filepath)
在代码末尾调用,或者我的模型是否会自动保存ModelCheckpoint()
?
我将模型保存为 .h5 文件,但我不知道是否应该更改它。
from keras import Sequential
from keras_preprocessing.image import ImageDataGenerator
from keras.layers import *
from keras.callbacks import ModelCheckpoint
import numpy as np
import os
img_size = 500 # number of pixels for width and height
#Random Seed
np.random.seed(12321)
training_path = os.getcwd() + "/cats and dogs images/train"
testing_path = os.getcwd() + "/cats and dogs images/test"
#Defines the Model
model = Sequential([
Conv2D(filters=64, kernel_size=(3,3), activation="relu", padding="same", input_shape=(img_size,img_size,3)),
MaxPool2D(pool_size=(2,2), strides=2),
Conv2D(filters=64, kernel_size=(3,3), activation="relu", padding="same"),
MaxPool2D(pool_size=(2,2), …
Run Code Online (Sandbox Code Playgroud) 我已经构建并训练了我的 CNN 模型,我想测试它。我编写了一个脚本,该脚本从指定的目录路径中获取输入图像,然后对图像进行预处理并将像素值重新调整为 0 到 1 之间。我还将图像大小调整为正确的尺寸并使用 进行model.predict()
预测。但是当我运行代码时:
from keras.models import Sequential
from keras_preprocessing.image import *
from keras.layers import *
import tensorflow as tf
import numpy as np
from keras.layers.experimental.preprocessing import Rescaling
import os
import cv2
from keras.models import *
img_size = 250
#Load weights into new model
filepath = os.getcwd() + "/trained_model.h5"
model = load_model(filepath)
print("Loaded model from disk")
#Scales the pixel values to between 0 to 1
#datagen = ImageDataGenerator(rescale=1.0/255.0)
#Prepares Testing Data
testing_dataset = cv2.imread(os.getcwd() …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写这个非常简单的加法程序以供练习。
它接受输入列表并将其存储在向量中。然后它从向量中取出每个连续的元素并求和。
#include <iostream>
#include <vector>
int main()
{
std::vector<int> i;
int input;
int sum = 0;
int y = 0;
while (std::cin >> input && input != 0000) {
i.push_back(input);
}
for (y; y < sizeof(i); y++) {
sum = sum + i[y];
}
std::cout << sum;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我编译并运行程序时,它可以正常工作,直到 for 循环开始运行,然后编译器停止并吐出向量下标超出范围的消息?
我做错了什么?