Пример #1
0
    def test_parse_from_sequence_example_missing_framei_exception(self):
        missing_frame_proto = text_format.Parse(
            """
        feature_lists {
          feature_list {
            key: "utility"
            value {
              feature { float_list { value: 0.0 } }
              feature { }
            }
          }
        }
        """, example_pb2.SequenceExample())
        features = data_lib.parse_from_sequence_example(
            ops.convert_to_tensor([missing_frame_proto.SerializeToString()]),
            list_size=2,
            context_feature_spec=None,
            example_feature_spec={"utility": EXAMPLE_FEATURE_SPEC["utility"]})

        with session.Session() as sess:
            sess.run(variables.local_variables_initializer())
            queue_runner.start_queue_runners()
            with self.assertRaisesRegexp(
                    errors.InvalidArgumentError,
                    r"Unexpected number of elements in feature utility"):
                sess.run(features)
  def _make_sequence_example(self):
    example = example_pb2.SequenceExample()
    example.context.feature['int_ctx'].int64_list.value.extend([5])
    example.context.feature['float_ctx'].float_list.value.extend([123.6])
    for val in range(0, 10, 2):
      feat = feature_pb2.Feature()
      feat.int64_list.value.extend([val] * val)
      example.feature_lists.feature_list['int_list'].feature.extend([feat])
    for val in range(1, 11, 2):
      feat = feature_pb2.Feature()
      feat.bytes_list.value.extend([tf.compat.as_bytes(str(val))] * val)
      example.feature_lists.feature_list['str_list'].feature.extend([feat])

    return example
Пример #3
0
def _make_sequence_example():
    example = example_pb2.SequenceExample()
    return text_format.Parse(_SEQ_EX_PROTO, example)
Пример #4
0
  def testSingleTriggerAndStats(self):
    event_trigger = text_format.Parse(
        """
      event_time { value_us: 1420102800000000 }
    """, google_extensions_pb2.EventTrigger())
    event_trigger_labels = (event_trigger, list())
    event_trigger_labels_list = (event_trigger_labels,)

    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
        birth_date { value_us: 8640000000000 }
      } } }
      entry { resource { medication_request {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        contained {
          medication {
            id { value: "med" }
            code { coding {
              system { value:
                "http://hl7.org/fhir/sid/ndc"
              }
              code { value: "123" }
            } }
          }
        }
        authored_on {
          value_us: 1420095600000000 # "2015-01-01T07:00:00+00:00"
        }
        medication { reference {
          medication_id { value: "med" }
        } }
      } } }
    """, resources_pb2.Bundle())
    expected_seqex = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1420095600 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "Patient.birthDate"
          value { int64_list { value: 8640000 } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 1 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1420102800 } }
        } }
        feature_lists: {
          feature_list {
            key: "MedicationRequest.contained.medication.code.ndc"
            value { feature { bytes_list { value: "123" } } }
          }
          feature_list {
            key: "MedicationRequest.meta.lastUpdated"
            value { feature { int64_list { value: 1420095600 } } }
          }
          feature_list {
            key: "MedicationRequest.authoredOn"
            value { feature { int64_list { value: 1420095600 } } }
          }
          feature_list {
            key: "eventId"
            value { feature { int64_list { value: 1420095600 } } }
          }
          feature_list {
            key: "MedicationRequest.contained.medication.code"
            value { feature { bytes_list { value: "ndc:123" } } }
          }
          feature_list {
            key: "encounterId"
            value { feature { int64_list { value: 1420095600 } } }
          }
        }
    """, example_pb2.SequenceExample())
    got_stats = self._runTest(
        "Patient/14", bundle, event_trigger_labels_list,
        (("Patient/14:0-1@1420102800", expected_seqex, 1),))
    # We only spot check a few counters here. The main goal is to make sure
    # we get the counters back from c++ land.
    self.assertEqual(1, got_stats.get("num-examples"))
Пример #5
0
  def testMultipleTriggersAndExamples(self):
    event_trigger1 = text_format.Parse(
        """
      event_time { value_us: 1417424400000000 }
      source { encounter_id { value: "1" } }
    """, google_extensions_pb2.EventTrigger())
    event_trigger2 = text_format.Parse(
        """
      event_time { value_us: 1420102800000000 }
      source { encounter_id { value: "2" } }
    """, google_extensions_pb2.EventTrigger())
    event_trigger_labels1 = (
        event_trigger1,
        list(),
    )
    event_trigger_labels2 = (
        event_trigger2,
        list(),
    )
    event_trigger_labels_list = (
        event_trigger_labels1,
        event_trigger_labels2,
    )

    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
      } } }
      entry {
        resource { encounter {
          id { value: "1" }
          subject { patient_id { value: "14" } }
          class_value {
            system { value: "http://hl7.org/fhir/v3/ActCode" }
            code { value: "IMP" }
          }
          reason {
            coding {
              system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
              code { value: "V410.9" }
              display { value: "Standard issue" }
            }
          }
          period {
            start {
              value_us: 1417420800000000 # "2014-12-01T08:00:00+00:00"
            }
            end {
              value_us: 1417424400000000 # "2014-12-01T09:00:00+00:00"
            }
          }
        } }
      }
      entry {
        resource { encounter {
          id { value: "2" }
          subject { patient_id { value: "14" } }
          class_value {
            system { value: "http://hl7.org/fhir/v3/ActCode" }
            code { value: "IMP" }
          }
          reason {
            coding {
              system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
              code { value: "191.4" }
              display { value: "Malignant neoplasm of occipital lobe" }
            }
          }
          period {
            start {
              value_us: 1420099200000000 # "2015-01-01T08:00:00+00:00"
            }
            end {
              value_us: 1420102800000000 # "2015-01-01T09:00:00+00:00"
            }
          }
        } }
      }
    """, resources_pb2.Bundle())
    # pylint: disable=line-too-long
    expected_seqex1 = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1417420800 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 2 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1417424400 } } }
        }
        feature_lists: {
          feature_list {
            key: "Encounter.class"
            value { feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { value: "actcode:IMP" } } }
          }
          feature_list {
            key: "Encounter.meta.lastUpdated"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } }
          }
          feature_list {
            key: "Encounter.period.start"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } }
          }
          feature_list {
            key: "Encounter.period.end"
            value { feature { int64_list { } } feature { int64_list { value: 1417424400 } } }
          }
          feature_list {
            key: "Encounter.reason"
            value { feature { bytes_list { } } feature { bytes_list { value: "icd9:V410.9" } } }
          }
          feature_list {
            key: "Encounter.reason.icd9"
            value { feature { bytes_list { } } feature { bytes_list { value: "V410.9" } } }
          }
          feature_list {
            key: "Encounter.reason.icd9.display.tokenized"
            value { feature { bytes_list { } } feature { bytes_list { value: "standard" value: "issue" } } }
          }
          feature_list {
            key: "encounterId"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } }
          }
          feature_list {
            key: "eventId"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } }
          }
        }
    """, example_pb2.SequenceExample())
    expected_seqex2 = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1420099200 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 4 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1420102800 } } }
        }
        feature_lists: {
          feature_list {
            key: "Encounter.class"
            value {
              feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { value: "actcode:IMP" } }
            }
          }
          feature_list {
            key: "Encounter.meta.lastUpdated"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } } }
          }
          feature_list {
            key: "Encounter.period.start"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } }
            }
          }
          feature_list {
            key: "Encounter.period.end"
            value {
              feature { int64_list { } } feature { int64_list { value: 1417424400 } } feature { int64_list { } } feature { int64_list { value: 1420102800 } }
            }
          }
          feature_list {
            key: "Encounter.reason"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "icd9:V410.9" } } feature { bytes_list { } } feature { bytes_list { value: "icd9:191.4" } }
            }
          }
          feature_list {
            key: "Encounter.reason.icd9"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "V410.9" } } feature { bytes_list { } } feature { bytes_list { value: "191.4" } }
            }
          }
          feature_list {
            key: "Encounter.reason.icd9.display.tokenized"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "standard" value: "issue" } } feature { bytes_list { } } feature { bytes_list { value: "malignant" value: "neoplasm" value: "of" value: "occipital" value: "lobe" } }
            }
          }
          feature_list {
            key: "encounterId"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } }
            }
          }
          feature_list {
            key: "eventId"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } }
            }
          }
        }
    """, example_pb2.SequenceExample())
    # pylint: enable=line-too-long
    _ = self._runTest("Patient/14", bundle, event_trigger_labels_list, (
        ("Patient/14:0-2@1417424400:Encounter/1", expected_seqex1, 2),
        ("Patient/14:0-4@1420102800:Encounter/2", expected_seqex2, 4),
    ))
Пример #6
0
  def testSingleTriggerAndLabel(self):
    event_trigger = text_format.Parse(
        """
      event_time { value_us: 1420102800000000 }
      source { encounter_id { value: "1" } }
    """, google_extensions_pb2.EventTrigger())
    event_label = text_format.Parse(
        """
      patient { patient_id { value: "14" } }
      type { code { value: "test1" }}
      event_time { value_us: 1420102800000000 }
      label {
        class_name {
          system { value: "urn:test:label"
          }
          code { value: "red" }
        }
      }
    """, google_extensions_pb2.EventLabel())
    event_trigger_labels = (
        event_trigger,
        (event_label,),
    )
    event_trigger_labels_list = (event_trigger_labels,)

    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
      } } }
      entry { resource { condition {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        code { coding {
          system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
          code { value: "bar" }
        } }
        asserted_date {
          value_us: 1417392000000000 # "2014-12-01T00:00:00+00:00"
        }
      } } }
      entry { resource { condition {
        id { value: "2" }
        subject { patient_id { value: "14" } }
        code { coding {
          system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
          code { value: "baz" }
        } }
        asserted_date {
          value_us: 1420099200000000 # "2015-01-01T08:00:00+00:00"
        }
      } } }
      entry { resource { composition {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        encounter { encounter_id { value: "1" } }
        section { text { div { value: "test text" } } }
        date {
          value_us: 1420102800000000
          timezone: "UTC"
          precision: SECOND
        }
      } } }
      entry { resource { encounter {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        class_value {
          system { value: "http://hl7.org/fhir/v3/ActCode" }
          code { value: "IMP" }
        }
        reason {
          coding {
            system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
            code { value: "191.4" }
              display { value: "Malignant neoplasm of occipital lobe" }
          }
        }
        period {
          start {
            value_us: 1420099200000000 # "2015-01-01T08:00:00+00:00"
          }
          end {
            value_us: 1420102800000000 # "2015-01-01T09:00:00+00:00"
          }
        }
      } } }
    """, resources_pb2.Bundle())
    # pylint: disable=line-too-long
    expected_seqex = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1420099200 } }
        }
        feature {
          key: "label.test1.class"
          value { bytes_list { value: "red" } }
        }
        feature {
          key: "label.test1.timestamp_secs"
          value { int64_list { value: 1420102800 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 5 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1420102800 } }
        }
      }
      feature_lists: {
        feature_list {
          key: "Composition.meta.lastUpdated"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420102800 } } feature { int64_list { } } }
        }
        feature_list {
          key: "Composition.date"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420102800 } } feature { int64_list { } } }
        }
        feature_list {
          key: "Composition.section.text.div.tokenized"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "test" value: "text" } } feature { bytes_list { } } }
        }
        feature_list {
          key: "Condition.meta.lastUpdated"
          value { feature { int64_list { value: 1417392000 } } feature { int64_list { value: 1420099200 } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } }
        }
        feature_list {
          key: "Condition.code"
          value { feature { bytes_list { value: "icd9:bar" } } feature { bytes_list { value: "icd9:baz" } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } }
        }
        feature_list {
          key: "Condition.code.icd9"
          value { feature { bytes_list { value: "bar" } } feature { bytes_list { value: "baz" } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } }
        }
        feature_list {
          key: "Condition.assertedDate"
          value { feature { int64_list { value: 1417392000 } } feature { int64_list { value: 1420099200 } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } }
        }
        feature_list {
          key: "Encounter.class"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { } } feature { bytes_list { value: "actcode:IMP" } } }
        }
        feature_list {
          key: "Encounter.meta.lastUpdated"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420099200 } } feature { int64_list { } } feature { int64_list { value: 1420102800 } } }
        }
        feature_list {
          key: "Encounter.period.start"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420099200 } } feature { int64_list { } } feature { int64_list { value: 1420099200 } } }
        }
        feature_list {
          key: "Encounter.period.end"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420102800 } } }
        }
        feature_list {
          key: "Encounter.reason"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "icd9:191.4" } } }
        }
        feature_list {
          key: "Encounter.reason.icd9"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "191.4" } } }
        }
        feature_list {
          key: "Encounter.reason.icd9.display.tokenized"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "malignant" value: "neoplasm" value: "of" value: "occipital" value: "lobe" } } }
        }
        feature_list {
          key: "encounterId"
          value { feature { int64_list { value: 1417392000 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } } }
        }
        feature_list {
          key: "eventId"
          value { feature { int64_list { value: 1417392000 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } } feature { int64_list { value: 1420102800 } } }
        }
      }
    """, example_pb2.SequenceExample())
    # pylint: enable=line-too-long
    _ = self._runTest(
        "Patient/14", bundle, event_trigger_labels_list,
        (("Patient/14:0-5@1420102800:Encounter/1", expected_seqex, 5),))
Пример #7
0
    def testDecodeJpegImageAndBoundingBox(self):
        """Test if the decoder can correctly decode the image and bounding box.

    A set of random images (represented as an image tensor) is first decoded as
    the groundtrue image. Meanwhile, the image tensor will be encoded and pass
    through the sequence example, and then decoded as images. The groundtruth
    image and the decoded image are expected to be equal. Similar tests are
    also applied to labels such as bounding box.
    """
        image_tensor = np.random.randint(256,
                                         size=(256, 256, 3)).astype(np.uint8)
        encoded_jpeg = self._EncodeImage(image_tensor)
        decoded_jpeg = self._DecodeImage(encoded_jpeg)

        sequence_example = example_pb2.SequenceExample(
            feature_lists=feature_pb2.FeatureLists(
                feature_list={
                    'image/encoded':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(bytes_list=feature_pb2.BytesList(
                            value=[encoded_jpeg])),
                    ]),
                    'bbox/xmin':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(float_list=feature_pb2.FloatList(
                            value=[0.0])),
                    ]),
                    'bbox/xmax':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(float_list=feature_pb2.FloatList(
                            value=[1.0]))
                    ]),
                    'bbox/ymin':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(float_list=feature_pb2.FloatList(
                            value=[0.0])),
                    ]),
                    'bbox/ymax':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(float_list=feature_pb2.FloatList(
                            value=[1.0]))
                    ]),
                })).SerializeToString()

        example_decoder = tf_sequence_example_decoder.TFSequenceExampleDecoder(
        )
        tensor_dict = example_decoder.decode(
            tf.convert_to_tensor(sequence_example))

        # Test tensor dict image dimension.
        self.assertAllEqual(
            (tensor_dict[fields.InputDataFields.image].get_shape().as_list()),
            [None, None, None, 3])
        with self.test_session() as sess:
            tensor_dict[fields.InputDataFields.image] = tf.squeeze(
                tensor_dict[fields.InputDataFields.image])
            tensor_dict[fields.InputDataFields.groundtruth_boxes] = tf.squeeze(
                tensor_dict[fields.InputDataFields.groundtruth_boxes])
            tensor_dict = sess.run(tensor_dict)

        # Test decoded image.
        self.assertAllEqual(decoded_jpeg,
                            tensor_dict[fields.InputDataFields.image])
        # Test decoded bounding box.
        self.assertAllEqual(
            [0.0, 0.0, 1.0, 1.0],
            tensor_dict[fields.InputDataFields.groundtruth_boxes])
    def _create_tf_record(self):
        path = os.path.join(self.get_temp_dir(), 'tfrecord')
        writer = tf.python_io.TFRecordWriter(path)

        image_tensor = np.random.randint(255,
                                         size=(16, 16, 3)).astype(np.uint8)
        with self.test_session():
            encoded_jpeg = tf.image.encode_jpeg(
                tf.constant(image_tensor)).eval()

        sequence_example = example_pb2.SequenceExample(
            context=feature_pb2.Features(
                feature={
                    'image/format':
                    feature_pb2.Feature(bytes_list=feature_pb2.BytesList(
                        value=['jpeg'.encode('utf-8')])),
                    'image/height':
                    feature_pb2.Feature(int64_list=feature_pb2.Int64List(
                        value=[16])),
                    'image/width':
                    feature_pb2.Feature(int64_list=feature_pb2.Int64List(
                        value=[16])),
                }),
            feature_lists=feature_pb2.FeatureLists(
                feature_list={
                    'image/encoded':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(bytes_list=feature_pb2.BytesList(
                            value=[encoded_jpeg])),
                    ]),
                    'image/object/bbox/xmin':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(float_list=feature_pb2.FloatList(
                            value=[0.0])),
                    ]),
                    'image/object/bbox/xmax':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(float_list=feature_pb2.FloatList(
                            value=[1.0]))
                    ]),
                    'image/object/bbox/ymin':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(float_list=feature_pb2.FloatList(
                            value=[0.0])),
                    ]),
                    'image/object/bbox/ymax':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(float_list=feature_pb2.FloatList(
                            value=[1.0]))
                    ]),
                    'image/object/class/label':
                    feature_pb2.FeatureList(feature=[
                        feature_pb2.Feature(int64_list=feature_pb2.Int64List(
                            value=[2]))
                    ]),
                }))

        writer.write(sequence_example.SerializeToString())
        writer.close()

        return path
Пример #9
0
  def testBundleAndLabelsToSeqexDoFn(self):
    event_trigger1 = text_format.Parse(
        """
      event_time { value_us: 1417424400000000 }
      source { encounter_id { value: "1" } }
    """, google_extensions_pb2.EventTrigger())
    event_trigger2 = text_format.Parse(
        """
      event_time { value_us: 1420102800000000 }
      source { encounter_id { value: "2" } }
    """, google_extensions_pb2.EventTrigger())
    event_trigger_labels1 = (
        event_trigger1,
        list(),
    )
    event_trigger_labels2 = (
        event_trigger2,
        list(),
    )
    event_trigger_labels_list = [
        event_trigger_labels1,
        event_trigger_labels2,
    ]

    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
      } } }
      entry {
        resource { encounter {
          id { value: "1" }
          subject { patient_id { value: "14" } }
          class_value {
            system { value: "http://hl7.org/fhir/v3/ActCode" }
            code { value: "IMP" }
          }
          reason {
            coding {
              system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
              code { value: "V410.9" }
              display { value: "Standard issue" }
            }
          }
          period {
            start {
              value_us: 1417420800000000 # "2014-12-01T08:00:00+00:00"
            }
            end {
              value_us: 1417424400000000 # "2014-12-01T09:00:00+00:00"
            }
          }
        } }
      }
      entry {
        resource { encounter {
          id { value: "2" }
          subject { patient_id { value: "14" } }
          class_value {
            system { value: "http://hl7.org/fhir/v3/ActCode" }
            code { value: "IMP" }
          }
          reason {
            coding {
              system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
              code { value: "191.4" }
              display { value: "Malignant neoplasm of occipital lobe" }
            }
          }
          period {
            start {
              value_us: 1420099200000000 # "2015-01-01T08:00:00+00:00"
            }
            end {
              value_us: 1420102800000000 # "2015-01-01T09:00:00+00:00"
            }
          }
        } }
      }
    """, resources_pb2.Bundle())
    # pylint: disable=line-too-long
    expected_seqex1 = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1417420800 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 2 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1417424400 } } }
        }
        feature_lists: {
          feature_list {
            key: "Encounter.class"
            value { feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } }
          }
          feature_list {
            key: "Encounter.meta.lastUpdated"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } }
          }
          feature_list {
            key: "Encounter.period.start"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } }
          }
          feature_list {
            key: "Encounter.period.end"
            value { feature { int64_list { } } feature { int64_list { value: 1417424400 } } }
          }
          feature_list {
            key: "Encounter.reason.http-hl7-org-fhir-sid-icd-9-cm-diagnosis"
            value { feature { bytes_list { } } feature { bytes_list { value: "V410.9" } } }
          }
          feature_list {
            key: "Encounter.reason.http-hl7-org-fhir-sid-icd-9-cm-diagnosis.display.tokenized"
            value { feature { bytes_list { } } feature { bytes_list { value: "standard" value: "issue" } } }
          }
          feature_list {
            key: "encounterId"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } }
          }
          feature_list {
            key: "eventId"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } }
          }
        }
    """, example_pb2.SequenceExample())
    expected_seqex2 = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1420099200 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 4 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1420102800 } } }
        }
        feature_lists: {
          feature_list {
            key: "Encounter.class"
            value {
              feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } }
            }
          }
          feature_list {
            key: "Encounter.meta.lastUpdated"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } } }
          }
          feature_list {
            key: "Encounter.period.start"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } }
            }
          }
          feature_list {
            key: "Encounter.period.end"
            value {
              feature { int64_list { } } feature { int64_list { value: 1417424400 } } feature { int64_list { } } feature { int64_list { value: 1420102800 } }
            }
          }
          feature_list {
            key: "Encounter.reason.http-hl7-org-fhir-sid-icd-9-cm-diagnosis"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "V410.9" } } feature { bytes_list { } } feature { bytes_list { value: "191.4" } }
            }
          }
          feature_list {
            key: "Encounter.reason.http-hl7-org-fhir-sid-icd-9-cm-diagnosis.display.tokenized"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "standard" value: "issue" } } feature { bytes_list { } } feature { bytes_list { value: "malignant" value: "neoplasm" value: "of" value: "occipital" value: "lobe" } }
            }
          }
          feature_list {
            key: "encounterId"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } }
            }
          }
          feature_list {
            key: "eventId"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } }
            }
          }
        }
    """, example_pb2.SequenceExample())
    with test_pipeline.TestPipeline() as p:
      result = (
          p
          | beam.Create([(b"Patient/14", (bundle, event_trigger_labels_list))])
          | "BundleAndLabelsToSeqex" >> beam.ParDo(
              bundle_to_seqex.BundleAndLabelsToSeqexDoFn(
                  version_config=self._version_config,
                  enable_attribution=False,
                  generate_sequence_label=False)))

      def check_result(got):
        try:
          self.assertLen(got, 2, "got: %s" % got)
          got_seqex1 = got[0]
          got_seqex2 = got[1]
          self.assertProtoEqual(expected_seqex1, got_seqex1)
          self.assertProtoEqual(expected_seqex2, got_seqex2)
        except AssertionError as err:
          raise util.BeamAssertException(err)

      util.assert_that(result, check_result)
Пример #10
0
      feature_list {
        key: "unigrams"
        value {
          feature { bytes_list { value: "tensorflow" } }
          feature { bytes_list { value: ["learning", "to", "rank"] } }
        }
      }
      feature_list {
        key: "utility"
        value {
          feature { float_list { value: 0.0 } }
          feature { float_list { value: 1.0 } }
        }
      }
    }
    """, example_pb2.SequenceExample())

SEQ_EXAMPLE_PROTO_2 = text_format.Parse(
    """
    context {
      feature {
        key: "query_length"
        value { int64_list { value: 2 } }
      }
    }
    feature_lists {
      feature_list {
        key: "unigrams"
        value {
          feature { bytes_list { value: "gbdt" } }
          feature { }