Ejemplo n.º 1
0
def pool_eeg_signal_channel(input_eeg_list,
                            channel_idx,
                            concat_dim1=1,
                            is_rep=False):
    '''
    The function will use a bunch of image tensor and concat them with the multiplication of pooling size from the
    channel dimension as concat_dim1=1. The arrangement should be every eeg height (channel) contains 5 kernel indexes
    Args:
        input_eeg_list: input image tensor list that obtained from split_image.py
        channel_idx: the channel index based on different channel information
        concat_dim1: concat dimension 1, the channel dimension

    Returns: the concated kernel tensor and the tensor input shape for verification

    '''
    if not isinstance(input_eeg_list, list):
        print("input eeg split signal is not a list of tensor.")

    if len(input_eeg_list) > 0:
        input_shape = input_eeg_list[0].get_shape().as_list()
    else:
        print("input eeg split not exist.")
        return

    # get the size of the vec1
    # conv_idx = biosemi_chan_mapper.pool_mapper(channel_idx)

    if is_rep:  # this will only be used for pooling of resize channels
        vec_idx = np.arange(0, EEG_SIGNAL_SIZE),
        vec_idx = np.reshape(vec_idx, (EEG_SIGNAL_SIZE, 1))
        conv_idx = np.repeat(vec_idx, BIOSEMI_POOL, axis=1)
    else:
        conv_idx = roi_mapper_idx.roi_mapper_idx_select(channel_idx, 'pool')
        conv_idx = biosemi_chan_mapper.replace_mapper_idx(conv_idx)
    conv_idx_shape = conv_idx.shape  # (128, 2)

    # input_shape = [10, 1, 256, 1]
    input_shape[concat_dim1] *= conv_idx_shape[0]
    input_shape[concat_dim1] *= conv_idx_shape[1]
    # input_shape = [10, 2*128, 256, 1]

    curr_kernel_tensor = []
    for kernel_idx in conv_idx:  # go for every kernel => 256 kernels
        # for each kernel => 5 index
        # concat on the first dimension => concat_dim1 = 1
        curr_kernel_tensor.append(
            tf.concat(concat_dim1,
                      [input_eeg_list[idx] for idx in kernel_idx]))

    kernel_tensor = tf.concat(concat_dim1, curr_kernel_tensor)

    return kernel_tensor, input_shape
Ejemplo n.º 2
0
def pool_eeg_signal_channel(
        input_eeg_list,
        channel_idx,
        concat_dim1=1,
        is_rep=False):
    '''
    The function will use a bunch of image tensor and concat them with the multiplication of pooling size from the
    channel dimension as concat_dim1=1. The arrangement should be every eeg height (channel) contains 5 kernel indexes
    Args:
        input_eeg_list: input image tensor list that obtained from split_image.py
        channel_idx: the channel index based on different channel information
        concat_dim1: concat dimension 1, the channel dimension

    Returns: the concated kernel tensor and the tensor input shape for verification

    '''
    if not isinstance(input_eeg_list, list):
        print("input eeg split signal is not a list of tensor.")

    if len(input_eeg_list) > 0:
        input_shape = input_eeg_list[0].get_shape().as_list()
    else:
        print("input eeg split not exist.")
        return

    # get the size of the vec1
    # conv_idx = biosemi_chan_mapper.pool_mapper(channel_idx)

    if is_rep:  # this will only be used for pooling of resize channels
        vec_idx = np.arange(0, EEG_SIGNAL_SIZE),
        vec_idx = np.reshape(vec_idx, (EEG_SIGNAL_SIZE, 1))
        conv_idx = np.repeat(vec_idx, BIOSEMI_POOL, axis=1)
    else:
        conv_idx = roi_mapper_idx.roi_mapper_idx_select(channel_idx, 'pool')
        conv_idx = biosemi_chan_mapper.replace_mapper_idx(conv_idx)
    conv_idx_shape = conv_idx.shape     # (128, 2)

    # input_shape = [10, 1, 256, 1]
    input_shape[concat_dim1] *= conv_idx_shape[0]
    input_shape[concat_dim1] *= conv_idx_shape[1]
    # input_shape = [10, 2*128, 256, 1]

    curr_kernel_tensor = []
    for kernel_idx in conv_idx:  # go for every kernel => 256 kernels
        # for each kernel => 5 index
        # concat on the first dimension => concat_dim1 = 1
        curr_kernel_tensor.append(tf.concat(concat_dim1, [input_eeg_list[idx] for idx in kernel_idx]))

    kernel_tensor = tf.concat(concat_dim1, curr_kernel_tensor)

    return kernel_tensor, input_shape
Ejemplo n.º 3
0
def conv_eeg_signal_channel(
        input_eeg_list,
        channel_idx,
        concat_dim1=1):
    '''
    The function will use a bunch of image tensor and concat them with the multiplication of kernel size and from the
    channel dimension as concat_dim1=1. The arrangement should be every eeg height (channel) contains 5 kernel indexes
    Args:
        input_eeg_list: input image tensor list that obtained from split_image.py
        channel_idx: the channel index based on different channel information
        concat_dim1: concat dimension 1, the channel dimension

    Returns: the concated kernel tensor and the tensor input shape for verification

    '''
    if not isinstance(input_eeg_list, list):
        print("input eeg split signal is not a list of tensor.")

    if len(input_eeg_list) > 0:
        input_shape = input_eeg_list[0].get_shape().as_list()
    else:
        print("input eeg split not exist.")
        return

    # get the size of the vec1
    # conv_idx = biosemi_chan_mapper.conv_mapper(channel_idx)
    conv_idx = roi_mapper_idx.roi_mapper_idx_select(channel_idx, 'conv')
    conv_idx = biosemi_chan_mapper.replace_mapper_idx(conv_idx)
    conv_idx_shape = conv_idx.shape     # (256, 5)

    # input_shape = [10, 1, 256, 1]
    input_shape[concat_dim1] *= conv_idx_shape[0]
    input_shape[concat_dim1] *= conv_idx_shape[1]
    # input_shape = [10, 5*256, 256, 1]

    curr_kernel_tensor = []
    for kernel_idx in conv_idx:  # go for every kernel => 256 kernels
        # for each kernel => 5 index
        # concat on the first dimension => concat_dim1 = 1
        curr_kernel_tensor.append(tf.concat(concat_dim1, [input_eeg_list[idx] for idx in kernel_idx]))

    kernel_tensor = tf.concat(concat_dim1, curr_kernel_tensor)

    return kernel_tensor, input_shape
Ejemplo n.º 4
0
def conv_eeg_signal_channel(input_eeg_list, channel_idx, concat_dim1=1):
    '''
    The function will use a bunch of image tensor and concat them with the multiplication of kernel size and from the
    channel dimension as concat_dim1=1. The arrangement should be every eeg height (channel) contains 5 kernel indexes
    Args:
        input_eeg_list: input image tensor list that obtained from split_image.py
        channel_idx: the channel index based on different channel information
        concat_dim1: concat dimension 1, the channel dimension

    Returns: the concated kernel tensor and the tensor input shape for verification

    '''
    if not isinstance(input_eeg_list, list):
        print("input eeg split signal is not a list of tensor.")

    if len(input_eeg_list) > 0:
        input_shape = input_eeg_list[0].get_shape().as_list()
    else:
        print("input eeg split not exist.")
        return

    # get the size of the vec1
    # conv_idx = biosemi_chan_mapper.conv_mapper(channel_idx)
    conv_idx = roi_mapper_idx.roi_mapper_idx_select(channel_idx, 'conv')
    conv_idx = biosemi_chan_mapper.replace_mapper_idx(conv_idx)
    conv_idx_shape = conv_idx.shape  # (256, 5)

    # input_shape = [10, 1, 256, 1]
    input_shape[concat_dim1] *= conv_idx_shape[0]
    input_shape[concat_dim1] *= conv_idx_shape[1]
    # input_shape = [10, 5*256, 256, 1]

    curr_kernel_tensor = []
    for kernel_idx in conv_idx:  # go for every kernel => 256 kernels
        # for each kernel => 5 index
        # concat on the first dimension => concat_dim1 = 1
        curr_kernel_tensor.append(
            tf.concat(concat_dim1,
                      [input_eeg_list[idx] for idx in kernel_idx]))

    kernel_tensor = tf.concat(concat_dim1, curr_kernel_tensor)

    return kernel_tensor, input_shape
Ejemplo n.º 5
0
 def test_replace_mapper(self):
     for chan_num in roi_property.CONV_CHAN_INFO:
         conv_256_idx = biosemi_chan_mapper.conv_mapper(chan_num)
         conv_256_idx = biosemi_chan_mapper.replace_mapper_idx(conv_256_idx)
         self.assertEqual(conv_256_idx.shape, (chan_num, roi_property.BIOSEMI_CONV))
Ejemplo n.º 6
0
 def test_replace_mapper(self):
     for chan_num in roi_property.CONV_CHAN_INFO:
         conv_256_idx = biosemi_chan_mapper.conv_mapper(chan_num)
         conv_256_idx = biosemi_chan_mapper.replace_mapper_idx(conv_256_idx)
         self.assertEqual(conv_256_idx.shape,
                          (chan_num, roi_property.BIOSEMI_CONV))