BATCH_SIZE = CORE * 6 NUM_EPOCH = 6 if __name__ == '__main__': device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") print(device) writer = SummaryWriter(filename_suffix="cnn_cough_%s" % EXPERIMENT_NAME) run = 0 for test_id, train_id in get_runs(): segmented_label_train, label_val = get_labels_by_ids( EXPERIMENT_NAME, train_id, test_id, run) round_loss = [] black_box = ModelC().to(DEVICE).double() loader = DataLoader(dataset=CoughDataSet(segmented_label_train), batch_size=BATCH_SIZE, shuffle=True, num_workers=CORE, pin_memory=True) loss_function = nn.CrossEntropyLoss() optimizer = torch.optim.SGD(black_box.parameters(), lr=0.001, momentum=0.9, nesterov=True, dampening=0) black_box.train()
import matplotlib.pyplot as plt import numpy as np import pandas as pd import torch from sklearn.metrics import precision_recall_curve, roc_curve, roc_auc_score from tqdm import tqdm from component.cnn_model import ModelC from component.decision_maker_w_onboarding import prepare_eval_data, evaluate_result 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 = []
BATCH_SIZE = 20 INPUT_PIXEL_WIDTH = 8 SEED = 2333333 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)
from component.cnn_model import ModelC black_box = ModelC().double() def get_n_params(model): pp=0 for p in list(model.parameters()): nn=1 for s in list(p.size()): nn = nn*s pp += nn return pp print(get_n_params(black_box))