Exemplo n.º 1
0
 def test_01(self):
     if os.path.exists('./experiments_data') is False:
         os.mkdir('./experiments_data')
     if os.path.exists('./datasets/image') is False:
         z = zipfile.ZipFile("./datasets/image.zip", "r")
         seq_x = []
         label_y = []
         for filename in z.namelist():
             z.extract(filename, './datasets')
     cur_dataset = expdata_generator(self.expdata_id)
     cur_dataset.get_exp_data(sel_task='diagnose',
                              data_root='./datasets/image')
Exemplo n.º 2
0
 def test_02_rf(self):
     cur_dataset = expdata_generator(self.expdata_id)
     cur_dataset.load_exp_data()
     expmodel_id = 'test.randomforest'
     clf = RandomForest(expmodel_id=expmodel_id)
     clf.fit(cur_dataset.train, cur_dataset.valid)
     clf.load_model()
     clf.inference(cur_dataset.test)
     pred_results = clf.get_results()
     assert np.shape(pred_results['hat_y']) == np.shape(pred_results['y'])
     assert True not in np.isnan(pred_results['hat_y']).tolist()
     assert True not in np.isnan(pred_results['hat_y'] * 0).tolist()
Exemplo n.º 3
0
 def test_02_basiccnn_gpu(self):
     cur_dataset = expdata_generator(self.expdata_id)
     cur_dataset.load_exp_data()
     expmodel_id = 'test.basicnn.gpu'
     clf = BasicCNN(expmodel_id=expmodel_id,
                    n_batchsize=20,
                    use_gpu=True,
                    n_epoch=6)
     clf.fit(cur_dataset.train, cur_dataset.valid)
     clf.load_model()
     clf.inference(cur_dataset.test)
     pred_results = clf.get_results()
     assert np.shape(pred_results['hat_y']) == np.shape(pred_results['y'])
     assert True not in np.isnan(pred_results['hat_y']).tolist()
     assert True not in np.isnan(pred_results['hat_y'] * 0).tolist()
Exemplo n.º 4
0
 def test_02_dblstm_ws_cpu(self):
     cur_dataset = expdata_generator(self.expdata_id)
     cur_dataset.load_exp_data()
     expmodel_id = 'test.dblstm_ws.cpu'
     clf = DBLSTM_WS(expmodel_id=expmodel_id,
                     n_batchsize=20,
                     use_gpu=False,
                     n_epoch=3)
     clf.fit(cur_dataset.train, cur_dataset.valid)
     clf.load_model()
     clf.inference(cur_dataset.test)
     pred_results = clf.get_results()
     assert np.shape(pred_results['hat_y']) == np.shape(pred_results['y'])
     assert True not in np.isnan(pred_results['hat_y']).tolist()
     assert True not in np.isnan(pred_results['hat_y'] * 0).tolist()
Exemplo n.º 5
0
 def test_02_typicalcnn_gpu(self):
     cur_dataset = expdata_generator(self.expdata_id)
     cur_dataset.load_exp_data()
     expmodel_id = 'test.typicalcnn'
     clf = TypicalCNN(expmodel_id=expmodel_id,
                      cnn_name='resnet18',
                      n_batchsize=20,
                      use_gpu=False,
                      n_epoch=6)
     clf.fit(cur_dataset.train, cur_dataset.valid)
     clf.load_model()
     clf.inference(cur_dataset.test)
     pred_results = clf.get_results()
     assert np.shape(pred_results['hat_y']) == np.shape(pred_results['y'])
     assert True not in np.isnan(pred_results['hat_y']).tolist()
     assert True not in np.isnan(pred_results['hat_y'] * 0).tolist()
#from pyhealth.models.ecg.dblstm_ws import DBLSTM_WS as model
#from pyhealth.models.ecg.denseconv import DenseConv as model
#from pyhealth.models.ecg.deepres1d import DeepRES1D as model
#from pyhealth.models.ecg.sdaelstm import SDAELSTM as model
#from pyhealth.models.ecg.mina import MINA as model
#from pyhealth.models.ecg.rcrnet import RCRNet as model
#from pyhealth.models.ecg.rf import RandomForest as model
#from pyhealth.models.ecg.xgboost import XGBoost as model
from pyhealth.evaluation.evaluator import func

data_dir = os.path.join(root_dir, 'datasets', 'ecg')

expdata_id = '2020.1104.data.diagnose.ecg'

# set up the datasets
cur_dataset = expdata_generator(expdata_id, root_dir=root_dir)
cur_dataset.get_exp_data(sel_task='diagnose', data_root=data_dir)
cur_dataset.load_exp_data()
cur_dataset.show_data()

# initialize the model for training
expmodel_id = '2020.1104.ecg.diagnose.'
clf = model(expmodel_id=expmodel_id, n_epoch=10, use_gpu=True)
clf.fit(cur_dataset.train, cur_dataset.valid)

# load the best model for inference
clf.load_model()
clf.inference(cur_dataset.test)
results = clf.get_results()
print(results)