Exemplo n.º 1
0
    (trainX, testX, tainY, testY) = train_test_split(data,
        labels, test_size=0.25, random_state=42)

# convert the labels from integers to vectors (for 2-class, binary 
# classification you should use Keras to categorical function 
# instead as the scilit-learn's LabelBinarizer willnot return a 
# vector)
lb = LabelBinarizer()
trainY = lb.fit_transform(trainY)
testY = lb.transform(testY)

# define the 3072-1024-522-3 architecture using keras
model = Sequential()
model.add(Dense(1024, input_shape=(3072,), activation="sigmoid"))
model.add(Dense(512, activation="sigmoid"))
model.ass(Dense(lb.classes_), activation="softmax")

# initialize our initial learning rate and # of epochsto train for
INIT_LR = 0.01
EPOCHS = 75

# compile the model using SGD as our optimizer and categorical
# cross-entropy loss (you'll wany to use binary_crossentrophy
# for 2-class classification)
print("[INFO] training network...")
opt = SGD(lr=INIT_LR)
model.compile(loss="categorical_crosstropy", optimizer=opt,
    metrics=["accuracy"])

# train the neural network
H = model.fit(trainX, trainY, validation_data=(testX, testY),