简体   繁体   English

我的 model 得到了 94% 我认为它不对而且没有意义

[英]My model got 94% I dont think its right andit doesnt make sense

Hi so I recently made an AI program that can classify flowers and it says when I ran Model.fit_generator it says I got 94% accuracy and when I searched up the record for highest accuracy is was also 94% and it just doesn't sound right like I just started neural.networks 2 months ago and it says I got the same accuracy of a company and I just started.Also I used a TPU from colab嗨,所以我最近制作了一个可以对鲜花进行分类的 AI 程序,它说当我运行 Model.fit_generator 时它说我得到了 94% 的准确率,当我搜索记录的最高精度时它也是 94% 只是听起来不对就像我 2 个月前刚开始使用 neural.networks,它说我得到了一家公司相同的准确度,我才刚刚开始。我还使用了来自 colab 的 TPU

import os 
import numpy as np
import pickle 
from tensorflow import keras 
import cv2
import matplotlib.pyplot as plt
import random
from keras.preprocessing.image import ImageDataGenerator
os.getcwd()
data = []
img_size = 175
categories = ["daisy", "dandelion", "rose", "sunflower", "tulip","Lily","aster","blue bonet","Camellia","gardinia","Lavander","Azalea"]
def create_data():
    for category in categories:
        path = os.path.join('image_data/image_data/Train', category)
        class_num = categories.index(category)
        for img in os.listdir(path):
            img_arr = cv2.imread(os.path.join(path, img))
            try:
                new_arr = cv2.resize(img_arr, (img_size, img_size))
            except cv2.error as e:
                print('Not valid')
            cv2.waitKey()
            
            data.append([new_arr, class_num])

create_data()
random.shuffle(data)
X=[]
y=[]

for features, labels in data:
    X.append(features)
    y.append(labels)

X = np.array(X).reshape(-1, img_size, img_size, 3)
y = np.array(y)
print('Shape of X: ', X.shape)
print('Shape of y: ', y.shape)
pickle_out = open('X.pickle', 'wb')

pickle.dump(X, pickle_out)

pickle_out_2 = open('y.pickle', 'wb')

pickle.dump(y, pickle_out_2)
X = X / 255.0
from sklearn.preprocessing import LabelEncoder
from keras.utils import to_categorical
le = LabelEncoder()
y= le.fit_transform(y)
y = to_categorical(y,12)
y.shape
from sklearn.model_selection import train_test_split

X_train, X_valid, y_train, y_valid = train_test_split(X, y, train_size = 0.8, random_state= 7)
datagen = ImageDataGenerator(
        featurewise_center=False,  
        samplewise_center=False,  
        featurewise_std_normalization=False, 
        samplewise_std_normalization=False, 
        zca_whitening=False,  
        rotation_range=10,  
        zoom_range = 0.1,
        width_shift_range=0.2,  
        height_shift_range=0.2, 
        horizontal_flip=True, 
        vertical_flip=False) 
datagen.fit(X_train)
model = keras.models.Sequential([keras.layers.Conv2D(32, 5, activation='relu', padding='SAME', input_shape=X.shape[1:]),
                                keras.layers.MaxPooling2D(2),
                                
                                keras.layers.Conv2D(64, 3, activation='relu', padding='SAME'),
                                keras.layers.MaxPooling2D(pool_size=2),
                        
                                
                                keras.layers.Conv2D(96, 3, activation="relu", padding="same"),
                                keras.layers.MaxPooling2D(pool_size=2),
                               
                                keras.layers.Conv2D(128, 3, activation="relu", padding="same"),
                                
                                keras.layers.MaxPooling2D(pool_size=2),
                                
                                keras.layers.Flatten(),
                                
                                keras.layers.Dense(500, activation='relu'),
                                keras.layers.Dropout(0.7),
                                keras.layers.Dense(12, activation='softmax')
                                ])
model.compile(optimizer = keras.optimizers.Adam(learning_rate=0.001), loss = 'categorical_crossentropy', metrics=['accuracy'])
#history = model.fit_generator(datagen.flow(X_train, y_train, batch_size=128), epochs=70, validation_data=(X_valid, y_valid))
model.fit(X_train, y_train, batch_size=128, epochs=70,validation_data=(X_valid, y_valid))
model.save("model1.h5")

could you please see if I actually got 94% acc.你能看看我是否真的获得了 94% 的 acc。 Sorry for my English it is not my first language抱歉我的英语不是我的母语

First of all, you need to go through the basic ML course and build up some base to know what exactly you're trying to achieve here.首先,您需要 go 完成基本的 ML 课程并建立一些基础,以了解您在这里想要实现的目标。 Getting your model to overfit and to get 99.9% accuracy is pretty straightforward and EASY, but also wrong.让你的model 过度拟合并获得 99.9% 的准确率是非常简单和容易的,但也是错误的。 I'm pretty sire your code can overfit and give you the accuracy that you've mentioned.我很高兴您的代码可以过度拟合并为您提供您提到的准确性。 There's nothing wrong with your code.您的代码没有任何问题。

I would recommand you to plot validation loss and accuracy, might help you to understand what happened and will definitely tells you if your model overfit.我会建议您使用 plot 验证损失和准确性,这可能会帮助您了解发生了什么,并且肯定会告诉您 model 是否过拟合。

You can also use model.predict on new images preprocessed to actually check if your.network performs well.您还可以对经过预处理的新图像使用model.predict来实际检查您的网络是否运行良好。

I would recommand you splitting your data into three different sets: training, validation and test.我会建议您将数据分成三个不同的集合:训练、验证和测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的图像没有缩放到正确的像素 - My image doesnt scale to its right pixel 我不认为我的表是在 SQLite 中创建的 - I dont think my tables are being created in SQLite 尽管我从参考资料中获得了相同的代码,但我无法让我的网站显示其内容 - I cant make my website show its content although i got the same codes from my reference 我认为Flask希望我在我的tests.py文件中实例化该应用程序,但我不知道如何 - I think Flask wants me to instantiate the app in my tests.py file but i dont know how to 设置一个带有序列的数组元素,它说我的列表是不均匀的,但我不认为它是 - setting an array element with a sequence, it says my list is inhomogeneous but i dont think it is Matplotlib的概率密度直方图没有意义 - probability density histogram with Matplotlib doesnt make sense 如何理解程序输出的多项式系数? - How do I make sense of the polynomial coefficients my program outputs? 我一直收到Nonetype,但我不认为应该吗? - I keep getting Nonetype but I dont think I should be? 我的代码有效,但我认为我使用的方法不正确 - My code works but I don't think I'm using the right method 我如何更改 plot 以使其从左角开始并在右角结束(我希望这是有道理的) - How do I change the plot so that it starts at the left corner and ends and the right corner (I hope this make sense)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM