在图像分类领域内,其中的大杀器莫过于Resnet50了,这个残差神经网络当时被发明出来之后,顿时毁天灭敌,其余任何模型都无法想与之比拟。我们下面用Tensorflow来调用这个模型,让我们的神经网络对Fashion-mnist数据集进行图像分类.由于在这个数据集当中图像的尺寸是28*28*1的,如果想要使用resnet那就需要把28*28*1的灰度图变为224*224*3的RGB图,我们使用OpenCV库可以很容易将图像进行resize。
首先我们进行导包:
import os,sys
import numpy as np
import scipy
from scipy import ndimage
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
from PIL import Image
import random
加载数据集:
(train_image,train_label),(test_image,test_label)=tf.keras.datasets.fashion_mnist.load_data()