import tensorflow
import tensorflow as tf
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
import sys
import time
from tensorflow import keras
print(keras.name)
fashion_minst = keras.datasets.fashion_mnist
(x_trian_all,y_train_all),(x_test,y_test) =fashion_minst.load_data()
x_valid,x_train = x_trian_all[:5000],x_trian_all[5000:]
y_valid,y_train = y_train_all[:5000],y_train_all[5000:]
print(x_valid.shape,y_valid.shape)
def show_Single_image(image_arr):
plt.imshow(image_arr,cmap=“binary”)
plt.show()
def show_imags(n_rows,n_clos,x_data,y_data,class_names):
assert len(x_data)==len(y_data)
assert n_closn_rows<len(x_data)
plt.figure(figsize=(n_clos1.4,n_rows1.6))
for row in range(n_rows):
for col in range(n_rows):
index = n_closrow+col
plt.subplot(n_rows,n_clos,index+1)
plt.imshow(x_data[index],cmap=“binary”,interpolation=‘nearest’)
plt.axis(‘off’)
plt.title(class_names[y_data[index]])
plt.show()
class_name=[‘T-shirt’,‘Trouser’,‘pullover’,‘dress’,‘coat’,
‘sandal’,‘shirt’,‘sneaker’,‘bag’,‘ankle boot’]
#show_imags(5,5,x_train,y_train,class_name)
#show_Single_image(x_train[0])
model =keras.models.Sequential
model.add(keras.layers.Flatten(input_shape=[28,28]))
model.add(keras.layers.Dense(300,activation=“relu”))
model.add(keras.layers.Dense(100,activation=“relu”))
model.add(keras.layers.Dense(10,activation=“sofatmax”))
model.compile(loss=“sparse_categorical_crossentropy”,optimizer=“sgd”,metrics=[“accuracy”])
model.fit(x_train,y_train,epochs=10,validation_data=(x_valid,y_valid))
出现以下错误:
Traceback (most recent call last):
File “D:/TensorFlowDemo/FirstDemo.py”, line 43, in
model.add(keras.layers.Flatten(input_shape=[28,28]))
File “D:\python\lib\site-packages\tensorflow_core\python\training\tracking\base.py”, line 457, in _method_wrapper
result = method(self, *args, **kwargs)
TypeError: add() missing 1 required positional argument: ‘layer’