コード例 #1
0
def are_predictions_all_close(keras_model, rtol=1e-05, atol=1e-08):
    sysml_model = Keras2DML(spark, keras_model, input_shape=input_shape, weights=tmp_dir)
    keras_preds = keras_model.predict(keras_tensor).flatten()
    sysml_preds = sysml_model.predict_proba(sysml_matrix).flatten()
    #print(str(keras_preds))
    #print(str(sysml_preds))
    return np.allclose(keras_preds, sysml_preds, rtol=rtol, atol=atol)
コード例 #2
0
def get_sysml_model(keras_model):
    sysml_model = Keras2DML(spark, keras_model, weights=tmp_dir, max_iter=1, batch_size=batch_size)
    # For apples-to-apples comparison of output probabilities:
    # By performing one-hot encoding outside, we ensure that the ordering of the TF columns
    # matches that of SystemML
    sysml_model.set(train_algo='batch', perform_one_hot_encoding=False)
    # print('Script:' + str(sysml_model.get_training_script()))
    return sysml_model
コード例 #3
0
 def test_simplernn_predictions1(self):
     data_dim = 16
     timesteps = 8
     num_classes = 10
     batch_size = 64
     model = Sequential()
     model.add(SimpleRNN(32, return_sequences=False, input_shape=(timesteps, data_dim)))
     model.add(Dense(10, activation='softmax'))
     x_train = np.random.random((batch_size, timesteps, data_dim))
     y_train = np.random.random((batch_size, num_classes))
     from systemml.mllearn import Keras2DML
     sysml_model = Keras2DML(spark, model, input_shape=(timesteps,data_dim,1), weights='weights_dir').set(debug=True)
     keras_preds = model.predict(x_train).flatten()
     sysml_preds = sysml_model.predict_proba(x_train.reshape((batch_size, -1))).flatten()
     self.failUnless(np.allclose(sysml_preds, keras_preds))
コード例 #4
0
 def test_lstm_predictions1(self):
     data_dim = 32
     timesteps = 8
     num_classes = 10
     batch_size = 64
     w1 = np.random.random((data_dim, 4*data_dim))
     w2 = np.random.random((data_dim, 4*data_dim))
     b = np.zeros(128)
     model = Sequential()
     model.add(LSTM(32, return_sequences=False, recurrent_activation='sigmoid', input_shape=(timesteps, data_dim),  weights=[w1, w2, b]))
     model.add(Dense(10, activation='softmax'))
     x_train = np.random.random((batch_size, timesteps, data_dim))
     y_train = np.random.random((batch_size, num_classes))
     from systemml.mllearn import Keras2DML
     sysml_model = Keras2DML(spark, model, input_shape=(timesteps,data_dim,1), weights='weights_dir').set(debug=True)
     keras_preds = model.predict(x_train)
     sysml_preds = sysml_model.predict_proba(x_train.reshape((batch_size, -1)))
     np.allclose(sysml_preds, keras_preds)
コード例 #5
0
#creamos la LSTM network
model = Sequential()
model.add(LSTM(4, input_shape=(1, look_back)))
model.add(Dense(1))
model.summary()
model.compile(loss='mean_squared_error', optimizer='adam')

epochs = 100
batch_size = 1
samples = 700
max_iter = int(epochs * math.ceil(samples / batch_size))

keras.backend.set_image_data_format("channels_first")

sysml_model = Keras2DML(spark, model, input_shape=(1, 1))

print(
    "########################TRAINING#############################################"
)
startTraining = time.monotonic()
#Aca se entrena la red
sysml_model.fit(trainX, trainY)
#model.fit(trainX, trainY, epochs=100, batch_size=1, verbose=0)
finishTraining = time.monotonic()
print("Tiempo de entrenamiento:", (finishTraining - startTraining))

# hacemos las predicciones
startPredict = time.monotonic()
trainPredict = model.predict(trainX)
testPredict = model.predict(testX)
コード例 #6
0
        local_batch_size = 16
    else:
        raise ValueError('looped_minibatch not yet implemented for ' +
                         str(args.network))
    if batch_size % local_batch_size != 0:
        raise ValueError('local_batch_size = ' + str(local_batch_size) +
                         ' should be multiple of batch size=' +
                         str(batch_size))
#------------------------------------------------------------------------------------------

if args.framework.startswith('systemml'):
    print("Initializing Keras2DML.")
    from systemml.mllearn import Keras2DML
    should_load_weights = False
    sysml_model = Keras2DML(spark,
                            model,
                            load_keras_weights=should_load_weights,
                            weights="tmp_weights1")
    if looped_minibatch:
        sysml_model.set(train_algo="looped_minibatch",
                        parallel_batches=int(batch_size / local_batch_size),
                        test_algo="batch")  # systemml doesnot have a generator
        sysml_model.set(weight_parallel_batches=False)
    else:
        sysml_model.set(train_algo="batch", test_algo="batch")
    sysml_model.set(perform_fused_backward_update=True)
    sysml_model.setStatistics(True).setStatisticsMaxHeavyHitters(100)
    # Since this script is used for measuring performance and not for printing script, inline the nn library
    sysml_model.set(inline_nn_library=True)
    # For apples-to-apples comparison, donot force set the allocated array to 0
    sysml_model.setConfigProperty("sysml.gpu.force.memSetZero", "false")
    # Use single GPU