pyhealth.models.image package

Submodules

pyhealth.models.image.typicalcnn module

class pyhealth.models.image.typicalcnn.TypicalCNN(expmodel_id='test.new', cnn_name='resnet18', pretrained=False, n_epoch=100, n_batchsize=5, load_size=255, crop_size=224, learn_ratio=0.0001, weight_decay=0.0001, n_epoch_saved=1, bias=True, dropout=0.5, batch_first=True, loss_name='L1LossSoftmax', aggregate='sum', optimizer_name='adam', use_gpu=False, gpu_ids='0')[source]

Bases: BaseControler

Several typical & popular CNN networks for medical image prediction

Parameters

cnn_namestr, optional (default = ‘resnet18’)

name of typical/popular CNN networks

pretrainedbool, optional (default = False)

used for pre-trained model load, True -> load pretrained model; False -> not load

n_epochint, optional (default = 100)

number of epochs with the initial learning rate

n_batchsizeint, optional (default = 5)

batch size for model training

load_sizeint, optional (default = 255)

scale images to this size

crop_sizeint, optional (default = 224)

crop load_sized image into to this size

learn_ratiofloat, optional (default = 1e-4)

initial learning rate for adam

weight_decayfloat, optional (default = 1e-4)

weight decay (L2 penalty)

n_epoch_savedint, optional (default = 1)

frequency of saving checkpoints at the end of epochs

biasbool, optional (default = True)

If False, then the layer does not use bias weights b_ih and b_hh.

dropoutfloat, optional (default = 0.5)

If non-zero, introduces a Dropout layer on the outputs of each LSTM layer except the last layer, with dropout probability equal to dropout.

batch_firstbool, optional (default = False)

If True, then the input and output tensors are provided as (batch, seq, feature).

loss_namestr, optional (default=’SigmoidCELoss’)

Name or objective function.

use_gpubool, optional (default=False)

If yes, use GPU resources; else use CPU resources

gpu_idsstr, optional (default=’’)

If yes, assign concrete used gpu ids such as ‘0,2,6’; else use ‘0’

fit(train_data, valid_data, assign_task_type=None)[source]

Parameters


train_data{

‘x’:list[episode_file_path], ‘y’:list[label], ‘l’:list[seq_len], ‘feat_n’: n of feature space, ‘label_n’: n of label space }

The input train samples dict.

valid_data{

‘x’:list[episode_file_path], ‘y’:list[label], ‘l’:list[seq_len], ‘feat_n’: n of feature space, ‘label_n’: n of label space }

The input valid samples dict.

assign_task_type: str (default = None)

predifine task type to model mapping <feature, label> current support [‘binary’,’multiclass’,’multilabel’,’regression’]

Returns


self : object

Fitted estimator.

load_model(loaded_epoch='', config_file_path='', model_file_path='')[source]

Parameters


loaded_epoch : str, loaded model name

we save the model by <epoch_count>.epoch, latest.epoch, best.epoch

Returns


self : object

loaded estimator.

Module contents