How to train data in NiftyNet

358 views Asked by At

I'm trying to train a network using NiftyNet with my own data (CT images and their corresponding labels). I designed the Net class shortly following some other training with similar sample data, all NiftyNet documentation I could find and parameters of my own data adjusted. But I keep getting this error:

"TypeError: init() got an unexpected keyword argument 'w_initializer'".

I've tried every change I could think of in my config.ini, Net class, etc. But I can't make it work nor find the reason. Can anyone help with this error? Or maybe share some guidelines to train my own network from the beginning so I can at least try to start an alternative from zero and see if I find a way out?

Training command:

! net_segment train -c /home/niftynet/extensions/dense_vnet_TC/config.ini --name dense_vnet_TC.net_TC.MyNet

Some values in config.ini:

[NETWORK]
name = dense_vnet
batch_size = 6
volume_padding_size = 0
window_sampling = resize

[TRAINING]
sample_per_volume = 1
lr = 0.001
loss_type = dense_vnet_TC.dice_hinge.dice
starting_iter = 0
save_every_n = 1000
max_iter = 3001

[INFERENCE]
border = (0, 0, 0)
inference_iter = 3000
output_interp_order = 0
spatial_window_size = (512, 512, 40)
save_seg_dir = ./segmentation_output/

############################ Custom configuration
[SEGMENTATION]
image = ct
label = label
label_normalisation = False
output_prob = False
num_classes = 2

Basics of Net class:

from niftynet.network.base_net import BaseNet

class MyNet(BaseNet):

    def __init__(self, num_classes, name='MyNet'):

        super(MyNet, self).__init__(num_classes=num_classes, acti_func=acti_func, name=name)

        # network specific property
        self.hidden_features = 10

    def layer_op(self, images, is_training):
        # create layer instances
        conv_1 = ConvolutionalLayer(self.hidden_features, kernel_size=3, name='conv_input')

        conv_2 = ConvolutionalLayer(self.num_classes, kernel_size=1, acti_func=None, name='conv_output')

        # apply layer instances
        flow = conv_1(images, is_training)
        flow = conv_2(flow, is_training)

        return flow

End of output, after doing some of the processing as expected:

Traceback (most recent call last): File
"/home/niftynet/bin/net_segment", line 10, in
sys.exit(main()) File "/home/niftynet/lib/python3.6/site- packages/niftynet/init.py",
line 142, in main
app_driver.run(app_driver.app) File "/home/niftynet/lib/python3.6/site-packages/niftynet/engine/application_driver.py",
line 189, in run
is_training_action=self.is_training_action) File "/home/niftynet/lib/python3.6/site- packages/niftynet/engine/application_driver.py",
line 258, in create_graph
application.initialise_network() File "/home/niftynet/lib/python3.6/site-packages/niftynet/application/segmentation_application.py",
line 280, in initialise_network
acti_func=self.net_param.activation_function) TypeError: init() got an unexpected keyword argument 'w_initializer'

1

There are 1 answers

0
Alexandra Cristobal Huerta On

I think you need to change this line (based on a similar problem I had):

super(MyNet, self).__init__(num_classes=num_classes, acti_func=acti_func, name=name)

for (just add w_regularizer) :

super(MyNet, self).__init__(num_classes=num_classes, w_regularizer=w_regularizer, acti_func=acti_func, name=name)

if not try also to add it here :

def __init__(self, num_classes, w_regularizer=w_regularizer, name='MyNet'): 

I hope it helps.