def test_mobilenet():
    data = load_train()
    r = convert_to_normalized_array(data['band_1']).reshape(-1, 75, 75)
    g = convert_to_normalized_array(data['band_2']).reshape(-1, 75, 75)
    b = r / (g + 0.01)
    X = np.dstack([r, g, b]).reshape(-1, 75, 75, 3)
    y = data['is_iceberg']

    X_resized = []
    for i in range(len(X)):
        new_img = resize(X[i], (128, 128))
        X_resized.append(new_img)

    X_resized = np.concatenate(X_resized).reshape(-1, 128, 128, 3)

    X_tr, y_tr = X_resized[:1408], y[:1408]
    X_val, y_val = X_resized[1408:], y[1408:]

    model = build_model()

    model.compile(
        loss='binary_crossentropy',
        optimizer=optimizers.Adadelta(),
        metrics=['binary_accuracy'])

    model.fit(
        X_tr, y_tr,
        batch_size=128,
        epochs=50,
        validation_data=(X_val, y_val),
        callbacks=[TensorBoard(log_dir='/tmp/mobilenet/run-{}'.format(datetime.utcnow().strftime("%Y%m%d%H%M%S")))])
def test_vgg19():
    data = load_train()
    r = convert_to_normalized_array(data['band_1']).reshape(-1, 75, 75)
    g = convert_to_normalized_array(data['band_2']).reshape(-1, 75, 75)
    b = r / (g + 0.01)
    X = np.dstack([r, g, b]).reshape(-1, 75, 75, 3)
    y = data['is_iceberg']

    X_tr, y_tr = X[:1408], y[:1408]
    X_val, y_val = X[1408:], y[1408:]

    model = build_model()

    model.compile(loss='binary_crossentropy',
                  optimizer=optimizers.Adadelta(),
                  metrics=['binary_accuracy'])

    model.fit(X_tr,
              y_tr,
              batch_size=128,
              epochs=50,
              validation_data=(X_val, y_val),
              callbacks=[
                  TensorBoard(log_dir='/tmp/vgg19/run-{}'.format(
                      datetime.utcnow().strftime("%Y%m%d%H%M%S")))
              ])
Esempio n. 3
0
def test_knn():
    data = load_train()
    X = convert_to_normalized_array(data['band_1'])[:, 25:50, 25:50].reshape(
        -1, 25 * 25)
    y = data['is_iceberg']
    model = KNeighborsClassifier(n_neighbors=20)
    scores = cross_val_score(model, X, y, scoring='neg_log_loss')
    assert np.mean(-scores) == approx(0.48, abs=0.02)