Beispiel #1
0
DEVICE = 'cuda:0'
#DEVICE = 'cpu'
#RUN = 'Dec19-balanced-30dB'
RUN = 'Dec19-30dB-ratio9'
MODEL = 49

DATA_PATH = '/home/jlchen/sandbox/feature/dnn_paper'
TEST_LABEL = './label/test_set.csv'

THRESHOLD = 1

black_box = ModelC().to(DEVICE).double()
print(black_box)


black_box.load_state_dict(torch.load('./model/cnn_attempt_%s_epoch_%d.pkl' % (RUN, MODEL)))
black_box.eval()

test_df = pd.read_csv('./label/segmented_val_set.csv')
test_positive = test_df[test_df['label'] >= 0.9]
test_negative = test_df[test_df['label'] < 0.9]
count_positive = len(test_positive)
count_negative = len(test_negative)
print(count_negative, count_positive)

positive_index = np.arange(0, count_positive, 1)
negative_index = np.arange(0, count_negative, 1)
np.random.shuffle(positive_index)
np.random.shuffle(negative_index)
TEST_CASES = 10000
Beispiel #2
0
from component.configuration import DEVICE

EXPERIMENT_NAME = 'Dec25_onboarding_'

black_box = ModelC().to(DEVICE).double()
print(black_box)

#test_table = pd.read_csv('label/Dec25_small_nosliding__val_run0.csv', index_col=0)
test_table = pd.read_csv('label/Dec25_onboarding__val_run0.csv', index_col=0)

# print(test_table.head(10))
#test_table = test_table.sample(frac=0.5, random_state=SEED)
#print(test_table.describe())

#black_box.load_state_dict(torch.load('./model/cnn_final_Dec25_small_nosliding__run_0.pkl'))
black_box.load_state_dict(
    torch.load('model/cnn_final_Dec25_onboarding__run_0.pkl'))
black_box.eval()

y_true = []
y_scores = []
y_audio = []

for audio_id, row in tqdm(test_table.iterrows(), total=test_table.shape[0]):
    record_label = row['label']

    spectrogram, decibel = prepare_eval_data(audio_id)
    pred_val = black_box(spectrogram.to(DEVICE).view(
        -1, 1, 64, 16)).to('cpu').detach().numpy()
    result = evaluate_result(pred_val, decibel, 30.0)
    y_true.append(record_label)
    y_scores.append(result)