损失和准确性在第一个时期后被冻结

时间:2019-11-15 19:44:58

标签: python tensorflow keras

我的损失和准确性分别冻结在0和1。为什么会这样呢?第一个时期具有正常的外观损失和准确性,但是在那之后,我不知道发生了什么。

import tensorflow as tf
import numpy as np
import glob
data = "*data\\*training\\*\\*"
filelist = glob.glob(str(data))
classes = ('classa','classb')
def generator(file):
    f = tf.io.read_file(file)
    f = tf.image.decode_jpeg(f)
    f = tf.image.resize(tf.image.rgb_to_grayscale(f), size = [28,28])
    f = tf.squeeze(f, [2])
    l = file.split('\\')
    l = l[2]
    l_label = classes.index(l)
    r1 = tf.constant(l_label)
    return f, r1
array1 = []
array2 = []
def todataset():
    for file in filelist:
        push_to_array1, push_to_array2 = generator(file)
        array1.append(push_to_array1)
        array2.append(push_to_array2)
    dataseta = tf.data.Dataset.from_tensors(array1)
    datasetb = tf.data.Dataset.from_tensors(array2)
    return(tf.data.Dataset.zip((dataseta,datasetb)))
dataset = todataset().shuffle(len(filelist)).repeat()

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(),
              metrics=['accuracy'])
model.fit(dataset, epochs=10, steps_per_epoch = 10)

0 个答案:

没有答案