- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我在 CNN 模型中从 2 个类别转变为 4 个类别时。我有错误。很多人帮助我解决了这些问题,比如我需要将损失更改为 sparse_categorical_crossentropy
和最后一层激活函数。
model.compile(loss='sparse_categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
history = model.fit_generator(
train_generator,
steps_per_epoch=nb_train_samples//batch_size,
epochs=epochs,
validation_data = validation_generator,
validation_steps = validation_generator.samples // batch_size,
)
我很困惑,因为我必须将损失函数从 binary_crossentropy
更改为 categorical_crossenpropy
。我想知道是否应该将 4 个类的 class_mode 从二进制更改为分类模式,还是应该将其保留为二进制。
train_datagen=ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip = True,
#vertical_flip = True,
validation_split=0.2,
brightness_range=[0.5, 1.5]
)
#test_datagen = ImageDataGenerator(
# rescale=1./255,
#
#)
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_width,img_height),
batch_size=batch_size,
shuffle=True,
class_mode='binary',
subset='training'
)
validation_generator = train_datagen.flow_from_directory(
train_data_dir, # same directory as training data
target_size=(img_height, img_width),
batch_size=batch_size,
class_mode='binary',
subset='validation'
#validation_data_dir,
#target_size=(img_width,img_height),
#batch_size=batch_size,
#class_mode='binary'
)
最佳答案
我想阅读documentation将是一个很好的起点。它会回答你所有的问题,然后是一些问题。
class_mode: One of "categorical", "binary", "sparse", "input", or None. Default: "categorical". Determines the type of label arrays that are returned: - "categorical" will be 2D one-hot encoded labels, - "binary" will be 1D binary labels, "sparse" will be 1D integer labels, - "input" will be images identical to input images (mainly used to work with autoencoders). - If None, no labels are returned (the generator will only yield batches of image data, which is useful to use with model.predict_generator()). Please note that in case of class_mode None, the data still needs to reside in a subdirectory of directory for it to work correctly.
因此,如果您为class_mode
选择categorical
,则应使用categorical_crossentropy
作为损失函数,如果您选择sparse_categorical_crossentropy
,则应使用sparse_categorical_crossentropy
作为损失函数选择稀疏
。
关于python - 是否在 Imagedatagenerator 中将 class_mode 从二进制更改为分类模式感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62090714/
我正在尝试学习Rust。我正在阅读一本书online,该书实现了unix程序cat。现在,我试图读取作为像cargo run file1.txt file2.txt这样的参数传递的文件的内容,但是程序
我在 GHC 8.0.1 中遇到了一个带有种类索引 (?) GADT 的奇怪情况,其中在类型与种类签名中引入 foralls 会产生不同的类型检查行为。 考虑以下数据类型: {-# LANGUAGE
我正在使用 Perl 5.10 开发应用程序,HTML::Mason和 Apache 2.2。这是我第一次在大型项目中使用 Perl 5.10。我每隔一段时间就会出现奇怪的行为。应用程序因一个非常奇怪
我正在尝试将文件上传到aws中的rust中,因为我使用的是 rusoto_s3 的s3 rust客户端,当这些部分从单个线程发送时,我设法使分段上传代码正常工作不是我想要的,我想上传大文件,并且希望能
我是一名优秀的程序员,十分优秀!