Beispiel #1
0
    def test_get_slices_from_session_invalid_type(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1', 'prompt', dataset, ['l1', 'l2', 'l3'])
        label_session = sessions.get_session_by_id(db.session, 1)

        with self.assertRaises(ValueError):
            sampling.get_slices_from_session(label_session)
Beispiel #2
0
    def test_get_session_by_id(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        label_session = sessions.get_session_by_id(db.session, 1)

        self.assertEqual(label_session.session_name, 'session1')
Beispiel #3
0
    def test_get_element_by_id(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])

        element = labels.get_element_by_id(db.session, 1)
        self.assertEqual(element.image_1_name, 'img1.nii.gz')
Beispiel #4
0
    def test_get_all_labels_elements_metadata(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        label_session = sessions.get_session_by_id(db.session, 1)
        all_labels = labels.get_all_labels(label_session)

        check_elements = list(all_labels.keys())
        self.assertEqual(check_elements, label_session.elements)
Beispiel #5
0
    def test_get_all_labels_elements_length(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        label_session = sessions.get_session_by_id(db.session, 1)
        all_labels = labels.get_all_labels(label_session)

        element_count = len(all_labels)
        self.assertEqual(element_count, 3)
Beispiel #6
0
    def test_export_session_json_elements_length(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'test_prompt', dataset,
                                                  ['l1', 'l2', 'l3'])

        label_session = sessions.get_session_by_id(db.session, 1)
        session_json = sessions.export_session_json(label_session)

        element_count = len(session_json['elements'])
        self.assertEqual(element_count, 3)
Beispiel #7
0
    def test_create_categorical_image_session_metadata(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'test_prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        label_session = sessions.get_session_by_id(db.session, 1)

        self.assertEqual(label_session.session_name, 'session1')
        self.assertEqual(label_session.session_type,
                         LabelSessionType.CATEGORICAL_IMAGE.name)
        self.assertEqual(label_session.prompt, 'test_prompt')
        self.assertEqual(label_session.dataset, 'dataset1')
        self.assertEqual(label_session.label_values_str, 'l1,l2,l3')
Beispiel #8
0
    def test_get_sessions_length(self):
        dataset1 = backend.get_dataset('dataset1')
        dataset2 = backend.get_dataset('dataset2')

        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset1,
                                                  ['l1', 'l2', 'l3'])
        sessions.create_categorical_image_session(db.session, 'session2',
                                                  'prompt', dataset1,
                                                  ['l1', 'l2', 'l3'])
        sessions.create_categorical_image_session(db.session, 'session3',
                                                  'prompt', dataset1,
                                                  ['l1', 'l2', 'l3'])
        sessions.create_categorical_image_session(db.session, 'session4',
                                                  'prompt', dataset2,
                                                  ['l1', 'l2', 'l3'])

        dataset1_sessions = sessions.get_sessions(db.session, dataset1)
        dataset1_sessions_count = len(dataset1_sessions)

        dataset2_sessions = sessions.get_sessions(db.session, dataset2)
        dataset2_sessions_count = len(dataset2_sessions)

        self.assertEqual(dataset1_sessions_count, 3)
        self.assertEqual(dataset2_sessions_count, 1)
Beispiel #9
0
    def test_set_label(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        element = labels.get_element_by_id(db.session, 1)

        labels.set_label(db.session, element, 'l1', 1000)

        label_count = len(element.labels)
        self.assertEqual(label_count, 1)

        element_label = element.labels[0]
        self.assertEqual(element_label.label_value, 'l1')
        self.assertEqual(element_label.milliseconds, 1000)
Beispiel #10
0
    def test_get_all_labels_labels_length(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        label_session = sessions.get_session_by_id(db.session, 1)

        labels.set_label(db.session, label_session.elements[0], 'l1', 1000)
        labels.set_label(db.session, label_session.elements[0], 'l2', 250)
        labels.set_label(db.session, label_session.elements[1], 'l3', 0)

        all_labels = labels.get_all_labels(label_session)
        check_labels = list(all_labels.values())

        self.assertEqual(len(check_labels[0]), 2)
        self.assertEqual(len(check_labels[1]), 1)
        self.assertEqual(len(check_labels[2]), 0)
Beispiel #11
0
    def test_get_all_labels_labels_metadata(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        label_session = sessions.get_session_by_id(db.session, 1)

        labels.set_label(db.session, label_session.elements[0], 'l1', 1000)
        labels.set_label(db.session, label_session.elements[0], 'l2', 250)
        labels.set_label(db.session, label_session.elements[1], 'l3', 0)

        all_labels = labels.get_all_labels(label_session)
        check_labels = list(all_labels.values())

        self.assertEqual(check_labels[0][0].label_value, 'l1')
        self.assertEqual(check_labels[0][1].label_value, 'l2')
        self.assertEqual(check_labels[1][0].label_value, 'l3')

        self.assertEqual(check_labels[0][0].milliseconds, 1000)
        self.assertEqual(check_labels[0][1].milliseconds, 250)
        self.assertEqual(check_labels[1][0].milliseconds, 0)
Beispiel #12
0
    def test_create_categorical_image_session_elements_metadata(self):
        dataset = backend.get_dataset('dataset1')
        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'test_prompt', dataset,
                                                  ['l1', 'l2', 'l3'])

        label_session = sessions.get_session_by_id(db.session, 1)
        session_elements = label_session.elements

        self.assertEqual(session_elements[0].element_index, 0)
        self.assertEqual(session_elements[1].element_index, 1)
        self.assertEqual(session_elements[2].element_index, 2)

        self.assertEqual(session_elements[0].image_1_name, 'img1.nii.gz')
        self.assertEqual(session_elements[1].image_1_name, 'img2.nii')
        self.assertEqual(session_elements[2].image_1_name, 'img3')

        self.assertIsNone(session_elements[0].slice_1_index)
        self.assertIsNone(session_elements[0].slice_1_type)
        self.assertIsNone(session_elements[0].image_2_name)
        self.assertIsNone(session_elements[0].slice_2_index)
        self.assertIsNone(session_elements[0].slice_2_type)
Beispiel #13
0
def create_categorical_session(dataset_name: str):
    dataset = backend.get_dataset(dataset_name)
    if dataset is None:
        abort(400)

    current_sessions = sessions.get_sessions(db.session, dataset)
    label_session_count = len(current_sessions)

    form = CreateCategoricalSessionForm(meta={'csrf': False})

    if form.validate_on_submit():
        if form.session_name.data in [se.session_name for se in current_sessions]:
            form.session_name.errors.append('Session name already in use.')
        else:
            label_values = [v.strip() for v in form.label_values.data.split(',')]
            sessions.create_categorical_image_session(db.session, form.session_name.data, form.prompt.data,
                                                      dataset, label_values)
            return redirect(url_for('dataset_overview', dataset_name=dataset.name))

    return render_template('create_categorical_session.html',
                           dataset=dataset,
                           label_session_count=label_session_count,
                           form=form)
Beispiel #14
0
    def test_get_sessions_by_type_length(self):
        dataset = backend.get_dataset('dataset1')

        sessions.create_categorical_image_session(db.session, 'session1',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        sessions.create_categorical_image_session(db.session, 'session2',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])

        sessions.create_categorical_slice_session(db.session, 'session3',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'], [])
        sessions.create_categorical_slice_session(db.session, 'session4',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'], [])

        sessions.create_comparison_slice_session(db.session, 'session5',
                                                 'prompt', dataset,
                                                 ['l1', 'l2'], [])

        sessions.create_categorical_image_session(db.session, 'session6',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])
        sessions.create_categorical_image_session(db.session, 'session7',
                                                  'prompt', dataset,
                                                  ['l1', 'l2', 'l3'])

        categorical_image_sessions = sessions.get_sessions(
            db.session, dataset, LabelSessionType.CATEGORICAL_IMAGE)
        categorical_image_session_count = len(categorical_image_sessions)

        categorical_slice_sessions = sessions.get_sessions(
            db.session, dataset, LabelSessionType.CATEGORICAL_SLICE)
        categorical_slice_session_count = len(categorical_slice_sessions)

        comparison_slice_sessions = sessions.get_sessions(
            db.session, dataset, LabelSessionType.COMPARISON_SLICE)
        comparison_slice_session_count = len(comparison_slice_sessions)

        self.assertEqual(categorical_image_session_count, 4)
        self.assertEqual(categorical_slice_session_count, 2)
        self.assertEqual(comparison_slice_session_count, 1)