qq_52930497 2022-11-04 19:14 采纳率: 0%
浏览 5

使用keras+tf训练神经网络莫名退出程序

使用keras + tf训练神经网络时出现错误,没有报错直接退出程序
import keras

from keras.optimizers import adam_v2
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Convolution2D
from keras.layers import Flatten
from keras.layers import MaxPooling2D
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
from keras.layers import Input, Conv2D, Dense, concatenate,MaxPooling2D,Dropout
from keras.models import Model
from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping
from collections import Counter
from keras.callbacks import EarlyStopping
import tensorflow as tf

train_loc ='D:/Lung_sound_classification-main/Feature_extraction/picture_for_cnn/train/'
validation_loc = 'D:/Lung_sound_classification-main/Feature_extraction/picture_for_cnn/validation/'
trdata = ImageDataGenerator(rescale=1 / 255.0)

traindata = trdata.flow_from_directory(directory=train_loc, target_size=(224,224),batch_size=5,shuffle=False)

valdata = ImageDataGenerator(rescale=1 / 255.0)
validationdata = valdata.flow_from_directory(directory=validation_loc, target_size=(224,224),batch_size=5,shuffle=False)

img_inputs = Input(shape=(224,224, 3))

classifier=Conv2D(64, (5, 5), activation = 'relu')(img_inputs)

classifier=MaxPooling2D(pool_size = (2, 2))(classifier)

classifier=Conv2D(64, (3, 3), activation = 'relu')(classifier)

classifier=MaxPooling2D(pool_size = (2, 2))(classifier)

classifier=Conv2D(96, (3, 3), activation = 'relu')(classifier)

classifier=MaxPooling2D(pool_size = (2, 2))(classifier)

classifier=Conv2D(96, (3, 3), activation = 'relu')(classifier)

classifier=MaxPooling2D(pool_size = (2, 2))(classifier)

classifier=Flatten()(classifier)

classifier=Dense(units = 256, activation = 'relu')(classifier)
classifier=Dropout(0.6)(classifier)
classifier=Dense(units = 128, activation = 'relu')(classifier)
classifier=Dropout(0.3)(classifier)
classifier=Dense(units = 64, activation = 'relu')(classifier)
classifier=Dropout(0.15)(classifier)
classifier=Dense(units = 32, activation = 'relu')(classifier)
classifier=Dropout(0.075)(classifier)
classifier=Dense(units = 16, activation = 'relu')(classifier)
classifier=Dropout(0.0325)(classifier)
classifier=Dense(units = 8, activation = 'relu')(classifier)
outputs=Dense(units = 5, activation = 'softmax')(classifier)

model = Model(inputs=img_inputs, outputs=outputs, name="LS_model")

opt = adam_v2.Adam(learning_rate=0.00001)
print(opt)
model.compile(optimizer = opt, loss = 'categorical_crossentropy', metrics = ['accuracy'])

STEP_SIZE_TRAIN=traindata.n//traindata.batch_size

STEP_SIZE_VALID=validationdata.n//validationdata.batch_size

checkpoint = ModelCheckpoint("working/best_model.h5", monitor='val_accuracy', verbose=1,
save_best_only=True, save_weights_only=False, mode='auto')

early = EarlyStopping(monitor='val_accuracy', min_delta=0, patience=20, verbose=1, mode='auto')
model.summary()

histore = model.fit(traindata,epochs=600,steps_per_epoch=STEP_SIZE_TRAIN,validation_data=validationdata,validation_steps=STEP_SIZE_VALID,callbacks=[checkpoint,early])

img

我的解答思路和尝试过的方法
有没有哥们回答一下啊!急死啦
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 创建了问题 11月4日

      悬赏问题

      • ¥15 请问DenseNet图像输入大小是否是固定的?
      • ¥15 template模板的参数问题
      • ¥50 搭建青柚H5过程中出现的问题
      • ¥15 查找处理学生信息问题,含多个文件,显示问题是无法调用其中一个文件
      • ¥15 simulink生成代码后提示告警
      • ¥16 jieba提取高频词,生成文件是空的
      • ¥15 怎么读取服务器中的文件去配置mongo的连接
      • ¥20 Python如何统计文本中两字及以上的词语个数
      • ¥15 MapReduce自定义对象怎么写
      • ¥15 看下哪里错了,程序应该没错