Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的价值损失是波动的,每5步我的价值很高_Python_Tensorflow_Keras_Tf.keras - Fatal编程技术网

Python 我的价值损失是波动的,每5步我的价值很高

Python 我的价值损失是波动的,每5步我的价值很高,python,tensorflow,keras,tf.keras,Python,Tensorflow,Keras,Tf.keras,我找到了一个非常有用的网站来学习ResNet,我用他的代码来训练我的形象,但是我发现我的val_损失是波动的,每5圈我的val_损失会很高,你可以看到我的val_损失会很高每5个历元 我的批量大小是5,我的历元是32,我使用的优化器是sgd=opt=sgd(lr=1e-1,动量=0.9,衰减=1e-1/NUM_历元) 有人能解释一下为什么会这样吗?多谢各位 这是我的代码`#用法 #python save_model.py--数据集疟疾--模型保存的_model.model import mat

我找到了一个非常有用的网站来学习ResNet,我用他的代码来训练我的形象,但是我发现我的val_损失是波动的,每5圈我的val_损失会很高,你可以看到我的val_损失会很高每5个历元

我的批量大小是5,我的历元是32,我使用的优化器是
sgd=opt=sgd(lr=1e-1,动量=0.9,衰减=1e-1/NUM_历元)

有人能解释一下为什么会这样吗?多谢各位 这是我的代码`#用法 #python save_model.py--数据集疟疾--模型保存的_model.model

 import matplotlib
 matplotlib.use("Agg")

 # import the necessary packages
from keras.preprocessing.image import ImageDataGenerator
from keras.optimizers import SGD
from pyimagesearch.resnet import ResNet
from sklearn.metrics import classification_report
from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import os

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", type=str, required=True,
help="path dataset of input images")
ap.add_argument("-m", "--model", type=str, required=True,
help="path to trained model")
ap.add_argument("-p", "--plot", type=str, default="plot.png",
help="path to output loss/accuracy plot")
args = vars(ap.parse_args())

# initialize the number of training epochs and batch size
NUM_EPOCHS = 25
BS = 5

TRAIN_PATH = os.path.sep.join([args["dataset"], "training"])
VAL_PATH = os.path.sep.join([args["dataset"], "validation"])
TEST_PATH = os.path.sep.join([args["dataset"], "testing"])



totalTrain = len(list(paths.list_images(TRAIN_PATH)))
totalVal = len(list(paths.list_images(VAL_PATH)))
totalTest = len(list(paths.list_images(TEST_PATH)))

trainAug = ImageDataGenerator(
  rescale=1 / 255.0,
  rotation_range=20,
  zoom_range=0.05,
  width_shift_range=0.05,
  height_shift_range=0.05,
  shear_range=0.05,
  horizontal_flip=True,
  fill_mode="nearest")

 # initialize the validation (and testing) data augmentation object
  valAug = ImageDataGenerator(rescale=1 / 255.0)


  trainGen = trainAug.flow_from_directory(
   TRAIN_PATH,
   class_mode="categorical",
   target_size=(64, 64),
   color_mode="rgb",
   shuffle=True,
   batch_size=32)


  valGen = valAug.flow_from_directory(
     VAL_PATH,
     class_mode="categorical",
     target_size=(64, 64),
     color_mode="rgb",
     shuffle=False,
     batch_size=BS)


    testGen = valAug.flow_from_directory(
     TEST_PATH,
     class_mode="categorical",
     target_size=(64, 64),
     color_mode="rgb",
     shuffle=False,
     batch_size=BS)

   model = ResNet.build(64, 64, 3, 2, (2, 2, 3),
   (32, 64, 128, 256), reg=0.0005)
   opt = SGD(lr=1e-1, momentum=0.9, decay=1e-1 / NUM_EPOCHS)
   model.compile(loss="binary_crossentropy", optimizer=opt,
     metrics=["accuracy"])

      H = model.fit_generator(
        trainGen,
        steps_per_epoch=totalTrain // BS,
        validation_data=valGen,
        validation_steps=totalVal // BS,
        epochs=NUM_EPOCHS)



         print("[INFO] evaluating network...")
         testGen.reset()
          predIdxs = model.predict_generator(testGen,
         steps=(totalTest // BS) + 1)


        predIdxs = np.argmax(predIdxs, axis=1)

      print(classification_report(testGen.classes, predIdxs,
          target_names=testGen.class_indices.keys()))

您的验证步骤是什么,您介意发布代码吗?这可能与您访问数据的方式有关,我可以假设154个图像用于trainig,24和23个图像用于验证和测试…但这只是假设…因此…发布您的培训代码我添加了代码,是的154个用于培训24个用于验证,23个用于测试,请你给我解释一下好吗谢谢我不是很确定,但你能保证批量大小一致吗。。您的列车发电机批次尺寸是否符合BS?验证批大小为1只是为了看看它是如何进行的,我怀疑,因为你的图像数量不能被5整除,这意味着另一批可能会不一致地加载。我用相同的批大小编辑,但我得到了流动的val损失,如果我的模型过拟合不是我的val损失应该增加吗?如果我的图片是10,那么我的批量大小应该是5?如果我的图像是奇数怎么办?非常感谢您的回答您的验证步骤是什么,您介意发布代码吗?这可能与您访问数据的方式有关,我可以假设154个图像用于trainig,24和23个图像用于验证和测试…但这只是假设…因此…发布您的培训代码我添加了我的代码,是的154个用于培训24个用于验证,23个用于测试,请你给我解释一下好吗谢谢我不是很确定,但是你能保证批量大小一致吗。。您的列车发电机批次尺寸是否符合BS?验证批大小为1只是为了看看它是如何进行的,我怀疑,因为你的图像数量不能被5整除,这意味着另一批可能会不一致地加载。我用相同的批大小编辑,但我得到了流动的val损失,如果我的模型过拟合不是我的val损失应该增加吗?如果我的图片是10,那么我的批量大小应该是5?如果我的图像是奇数怎么办?非常感谢你的回答