Ejemplo n.º 1
0
        CLF1_TEST.append(
            np.dstack((each_emb[0].reshape((10, 8000)), each_emb[1].reshape(
                (10, 8000)), each_emb[2].reshape(
                    (10, 8000)), each_emb[3].reshape((10, 8000)))))

    #except any error then remove that file manually and then run the process again
    except OSError:
        print 'Test Pickling Error: ', each_wav

#################################################################################
# Preprocess the data as per the input of the model
#################################################################################
CLF1_TEST = np.array(CLF1_TEST).reshape((-1, 10, 8000, 4))
CLF1_TEST = CLF1_TEST / np.linalg.norm(CLF1_TEST)

#################################################################################
# Run the predictions on the data
#################################################################################
PREDICTIONS = MODEL.predict(CLF1_TEST).ravel()
DF_TEST['predictions_prob'] = PREDICTIONS
DF_TEST['predictions'] = PREDICTIONS.ravel().round()

#################################################################################
# save it in a CSV file
#################################################################################
if RESULT.path_to_write_prediction_csv:
    DF_TEST.drop(["features"],
                 axis=1).to_csv(RESULT.path_to_write_prediction_csv)
else:
    print "Predictions are not saved. Give appropiate argument to save the predictions"
                                strides=100,
                                activation='relu',
                                padding='same'),
                         input_shape=(10, 8000, 4))(INPUTS)
CONV_2 = TimeDistributed(
    Conv1D(100, kernel_size=4, activation='relu', padding='same'))(CONV_1)
MAX_POOL = TimeDistributed(MaxPooling1D(80))(CONV_2)
DENSE_1 = TimeDistributed(Dense(60, activation='relu'))(MAX_POOL)
DENSE_2 = TimeDistributed(Dense(50, activation='relu'))(DENSE_1)
DENSE_3 = TimeDistributed(Dense(1, activation='sigmoid'))(DENSE_2)
MAX_POOL_2 = MaxPooling2D((10, 1))(DENSE_3)
PREDICTIONS = Flatten()(MAX_POOL_2)
MODEL = Model(inputs=[INPUTS], outputs=[PREDICTIONS])
print MODEL.summary()

# Load the saved weights and predict on the audiomoth  recordings
MODEL.load_weights('../Goertzel_model_8k_weights_time.h5')

#call the audiomoth function to predict on the frequency components of audio moth WAV files
TEST_VALUES, DATAFRAME = aud_goertzel.dataframe_with_frequency_components(
    RESULT.audio_files_path, RESULT.path_for_goertzel_components)
PREDICTIONS = MODEL.predict(TEST_VALUES).ravel()
DATAFRAME['predictions_prob'] = PREDICTIONS
DATAFRAME['predictions'] = PREDICTIONS.ravel().round()

#save it in a CSV file
DATAFRAME[[
    'wav_file', 'Label_1', 'Label_2', 'Label_3', 'predictions_prob',
    'predictions'
]].to_csv('predictions_by_goertzel_model.csv')