Exemplo n.º 1
0
def test_one_image_three_nets_adaptive_3dshape(temp_imgs, data_shapes, label_shapes, data_channel, class_num,
                                             sess, nets, outputs, inputs):
    '''
        Test one image with three anisotropic networks with fixed or adaptable tensor height and width.
        These networks are used in axial, saggital and coronal view respectively.
        shape_mode: reset the tensor shape based on input image shape
        '''
    [ax_data_shape, sg_data_shape, cr_data_shape] = data_shapes
    [ax_label_shape, sg_label_shape, cr_label_shape] = label_shapes
    [D, H, W] = temp_imgs[0].shape
    prob = volume_probability_prediction_dynamic_3dshape(temp_imgs, ax_data_shape, ax_label_shape, data_channel,
                                                           class_num, sess, nets[0])

    tr_volumes1 = transpose_volumes(temp_imgs, 'sagittal')
    [sgD, sgH, sgW] = tr_volumes1[0].shape
    prob1 = volume_probability_prediction_dynamic_3dshape(tr_volumes1, sg_data_shape, sg_label_shape, data_channel,
                                                            class_num, sess, nets[1])
    prob1 = np.transpose(prob1, [1,2,0,3])
    
    tr_volumes2 = transpose_volumes(temp_imgs, 'coronal')
    [trD, trH, trW] = tr_volumes2[0].shape
    prob2 = volume_probability_prediction_dynamic_3dshape(tr_volumes2, cr_data_shape, cr_label_shape, data_channel,
                                                            class_num, sess, nets[2])
    prob2 = np.transpose(prob2, [1,0,2,3])
    
    prob = (prob + prob1 + prob2)/3.0
    return prob
Exemplo n.º 2
0
def test_one_image_three_nets(temp_imgs, data_shape, label_shape, data_channel, class_num,
                   batch_size, direction, sess, proby1, x1, proby2, x2, proby3, x3):
    '''
    Test one image with three anisotropic networks with fixed tensor height and width.
    These networks are used in axial, saggital and coronal view respectively.
    '''
    prob = volume_probability_prediction(temp_imgs, data_shape, label_shape, data_channel, 
                                  class_num, batch_size, sess, proby1, x1)
    if(direction == 'all'):
        tr_volumes1 = transpose_volumes(temp_imgs, 'sagittal')
        prob1 = volume_probability_prediction(tr_volumes1, data_shape, label_shape, data_channel, 
                                  class_num, batch_size, sess, proby2, x2)
        prob1 = np.transpose(prob1, [1,2,0,3])
        tr_volumes2 = transpose_volumes(temp_imgs, 'coronal')
        prob2 = volume_probability_prediction(tr_volumes2, data_shape, label_shape, data_channel, 
                                  class_num, batch_size, sess, proby3, x3)
        prob2 = np.transpose(prob2, [1,0,2,3])
        prob = (prob + prob1 + prob2)/3.0
    return prob
Exemplo n.º 3
0
def test_one_image_dynamic_shape(temp_imgs, data_shape, label_shape, data_channel, class_num,
                                 batch_size, direction, sess, net):
    '''
    Test one image wiht anisotropic networks with adaptable tensor height and width.
    The same network can be used in axial, saggital and coronal view.
    '''
    prob = volume_probability_prediction_dynamic_shape(temp_imgs, data_shape, label_shape,  data_channel, 
                                  class_num, batch_size, sess, net)
    if(direction == 'all'):
        tr_volumes1 = transpose_volumes(temp_imgs, 'sagittal')
        prob1 = volume_probability_prediction_dynamic_shape(tr_volumes1, data_shape, label_shape,  data_channel, 
                                  class_num, batch_size, sess, net)
        prob1 = np.transpose(prob1, [1,2,0,3])
        tr_volumes2 = transpose_volumes(temp_imgs, 'coronal')
        prob2 = volume_probability_prediction_dynamic_shape(tr_volumes2, data_shape, label_shape,  data_channel, 
                                  class_num, batch_size, sess, net)
        prob2 = np.transpose(prob2, [1,0,2,3])
        prob = (prob + prob1 + prob2)/3.0
    return prob
Exemplo n.º 4
0
def test_one_image_three_nets_dynamic_shape(temp_imgs, data_shape, label_shape,  data_channel, class_num,
                   batch_size, direction, sess, net1, net2, net3):
    '''
    Test one image with three anisotropic networks with adaptable tensor height and width.
    These networks are used in axial, saggital and coronal view respectively.
    '''
    prob = volume_probability_prediction_dynamic_shape(temp_imgs, data_shape, label_shape, data_channel, 
                                  class_num, batch_size, sess, net1)
    print('test volume shape', prob.shape)
    if(direction == 'all'):
        tr_volumes1 = transpose_volumes(temp_imgs, 'sagittal')
        prob1 = volume_probability_prediction_dynamic_shape(tr_volumes1, data_shape, label_shape,  data_channel, 
                                  class_num, batch_size, sess, net2)
        prob1 = np.transpose(prob1, [1,2,0,3])
        tr_volumes2 = transpose_volumes(temp_imgs, 'coronal')
        prob2 = volume_probability_prediction_dynamic_shape(tr_volumes2, data_shape, label_shape,  data_channel, 
                                  class_num, batch_size, sess, net3)
        prob2 = np.transpose(prob2, [1,0,2,3])
        prob = (prob + prob1 + prob2)/3.0
    return prob
Exemplo n.º 5
0
def test_one_image_three_nets_adaptive_shape(temp_imgs, data_shapes, label_shapes, data_channel, class_num,
                   batch_size, sess, nets, outputs, inputs, shape_mode):
    '''
    Test one image with three anisotropic networks with fixed or adaptable tensor height and width.
    These networks are used in axial, saggital and coronal view respectively.
    shape_mode: 0: use fixed tensor shape in all direction
                1: compare tensor shape and image shape and then select fixed or adaptive tensor shape
                2: use adaptive tensor shape in all direction
    '''
    [ax_data_shape, sg_data_shape, cr_data_shape] = data_shapes
    [ax_label_shape, sg_label_shape, cr_label_shape] = label_shapes
    [D, H, W] = temp_imgs[0].shape
    if(shape_mode == 0 or (shape_mode == 1 and (H <= ax_data_shape[1] and W <= ax_data_shape[2]))):
        prob = volume_probability_prediction(temp_imgs, ax_data_shape, ax_label_shape, data_channel, 
                                  class_num, batch_size, sess, outputs[0], inputs[0])
    else:
        prob = volume_probability_prediction_dynamic_shape(temp_imgs, ax_data_shape, ax_label_shape, data_channel, 
                                  class_num, batch_size, sess, nets[0])

    tr_volumes1 = transpose_volumes(temp_imgs, 'sagittal')
    [sgD, sgH, sgW] = tr_volumes1[0].shape
    if(shape_mode == 0 or (shape_mode == 1 and (sgH <= sg_data_shape[1] and sgW <= sg_data_shape[2]))):
        prob1 = volume_probability_prediction(tr_volumes1, sg_data_shape, sg_label_shape, data_channel, 
                              class_num, batch_size, sess, outputs[1], inputs[1])
    else:
        prob1 = volume_probability_prediction_dynamic_shape(tr_volumes1, sg_data_shape, sg_label_shape, data_channel, 
                              class_num, batch_size, sess, nets[1])
    prob1 = np.transpose(prob1, [1,2,0,3])
    
    tr_volumes2 = transpose_volumes(temp_imgs, 'coronal')
    [trD, trH, trW] = tr_volumes2[0].shape
    if(shape_mode == 0 or (shape_mode == 1 and (trH <= cr_data_shape[1] and trW <= cr_data_shape[2]))):
        prob2 = volume_probability_prediction(tr_volumes2, cr_data_shape, cr_label_shape, data_channel, 
                              class_num, batch_size, sess, outputs[2], inputs[2])
    else:
        prob2 = volume_probability_prediction_dynamic_shape(tr_volumes2, cr_data_shape, cr_label_shape, data_channel, 
                              class_num, batch_size, sess, nets[2])        
    prob2 = np.transpose(prob2, [1,0,2,3])
    
    prob = (prob + prob1 + prob2)/3.0
    return prob