예제 #1
0
def main(_):
    dataset = Dataset_Youtube8M(dataset_dir=FLAGS.data_dir,
                                normalization=False,
                                using_existing_features=False,
                                flag=FLAGS)
    K.clear_session()
    learner = LearnerLSTMReg(dataset=dataset,
                             learner_name='LSTMReg',
                             flag=FLAGS)

    # evaluator = Evaluator_AVEC2016()

    learner.learn()
    truth, prediction = learner.predict()
예제 #2
0
               predict_yaml_test,
               delimiter=",",
               fmt="%.3f")

    np.savetxt("predict_yaml_train_classes.csv",
               predict_yaml_train_classes,
               delimiter=",",
               fmt="%d")
    np.savetxt("predict_yaml_test_classes.csv",
               predict_yaml_test_classes,
               delimiter=",",
               fmt="%d")

    return history


# This is also added for candle compliance so that the program can
# still be executed independently from the command line.
def main():

    gParameters = initialize_parameters()
    run(gParameters)


if __name__ == '__main__':
    main()
    try:
        ke.clear_session()
    except AttributeError:  # theano does not have this function
        pass
train, labels = make_moons(n_samples=1000, noise=0.4, random_state=1)
train_x, test, label_x, label = train_test_split(train,
                                                 labels,
                                                 test_size=0.3,
                                                 random_state=101)
train_x.shape
test.shape

plt.scatter(train_x[:, 0], train_x[:, 1], c=label_x.flatten(), edgecolors='b')
plt.show()

x_min

plt.contourf(train_x[:, 0], train[:, 1], c=label_x)
plt.show()
k.clear_session()
model = Sequential()
model.add(l.Dense(10, activation=l.activations.relu, input_dim=2))
model.add(l.Dropout(.2))
model.add(l.Dense(8, activation=l.activations.tanh))
model.add(l.Dropout(0.2))
model.add(l.Dense(10))
model.add(l.Dropout(.2))
model.add(l.Activation('relu'))
model.add(l.Dense(1, activation=l.activations.sigmoid))
model.compile(optimizer='rmsprop',
              loss='binary_crossentropy',
              metrics=['accuracy'])
model.summary()
model.fit(x=train_x, y=label_x, batch_size=64, epochs=1000)
model.evaluate(train_x, label_x)
예제 #4
0
    
    X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 1))
    X_test = np.reshape(X_test, (X_test.shape[0], X_test.shape[1], 1))
    
    model = Sequential()
    model.add(LSTM(50, input_shape=(X_train.shape[1], X_train.shape[2])))
    model.add(Dense(1))
    model.compile(loss='mae', optimizer='adam')
# fit network
    history = model.fit(X_train, y_train, epochs=200, batch_size=50, validation_data=(X_test, y_test), verbose=0, shuffle=False)

    testPredict = model.predict(X_test)
    
    pred_vec = np.append(pred_vec,testPredict)
    
    K.clear_session()
# plot history
    
true_vec = y[1:1384,]

def rmse(pred_vec, true_vec):
    return np.sqrt(((pred_vec - true_vec) ** 2).mean())

rmse_val = rmse(np.array(pred_vec), np.array(true_vec))
print("rms error is: " + str(rmse_val))




# visually inspect results (requires matplotlib)
#rpca.plot_fit()
import numpy as np
import keras
from keras.models import load_model
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D
from keras.optimizers import Adam
from keras.layers import MaxPooling2D
RCP_dict = {0: "Rock", 1: "Paper", 2: "Scissors"}

cap = cv2.VideoCapture(0)

model = load_model('RockPaperScissors.h5')
while True:

    keras.clear_session()
    ret, frame = cap.read()
    if not ret:
        break
    #frame=frame.resize(1,300,200,3)

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cropped_img = np.expand_dims(cv2.resize(gray, (200, 300)), -1)

    rr = gray.resize(300, 200, 3)
    prediction = model.predict(rr, steps=1)
    #maxindex = np.argmax(prediction)
    print(prediction)
    #cv2.putText(frame, prediction, (40+20, 120-60), 1, (255, 255, 255), 2, cv2.LINE_AA)
    objects = (['Rock', 'Paper', 'Scissors'])
    index = np.arange(len(objects))