class Jarvis(Model):
def __init__(self):
Model.__init__(self)
self.model = Sequential()
# Convulational layers\w MaxPooling
self.model.add(Conv2D(64, (5, 5), activation="relu"))
self.model.add(MaxPooling2D((2, 2)))
self.model.add(Conv2D(64, (5, 5), activation="relu"))
self.model.add(MaxPooling2D((2, 2)))
# Flattening layers
self.model.add(Flatten())
# Dense layers
self.model.add(Dense(1000))
self.model.add(Dense(10, activation="softmax"))
# Compiling model
self.model.compile(optimizer="adam",
loss="categorical_crossentropy",
metrics=["accuracy"])
self.model.fit(x=train_x, y=train_y,
epochs=8, batch_size=100)
我正在像这样加载数据
(train_x, train_y), (test_x, test_y) = tfds.load("glue", split="train", data_dir=os.path.dirname(__file__))
我建议您使用 scikit-learn 加载数据,因为这样要好得多!
首先将数据加载为 csv 或 excel 文件:
import pandas as pd
data = pd.read_csv('Example$Path$')
然后从 scikitlearn 导入 train_test_split:
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=101)
#X and y over here are the columns of the data. X is the training columns and y is the column you are trying to predict