def train(
    # Use InputPath to get a locally accessible path for the input artifact
    # of type `Dataset`.
    dataset_one_path: InputPath('Dataset'),
    # Use InputArtifact to get a metadata-rich handle to the input artifact
    # of type `Dataset`.
    dataset_two: InputArtifact(Dataset),
    # An input parameter of type string.
    message: str,
    # Use OutputArtifact to get a metadata-rich handle to the output artifact
    # of type `Dataset`.
    model: OutputArtifact(Model),
    # An input parameter of type int with a default value.
    num_steps: int = 100):
    '''Dummy Training step'''
    with open(dataset_one_path, 'r') as input_file:
        dataset_one_contents = input_file.read()

    with open(dataset_two.path, 'r') as input_file:
        dataset_two_contents = input_file.read()

    line = "dataset_one_contents: {} || dataset_two_contents: {} || message: {}\n".format(
        dataset_one_contents, dataset_two_contents, message)

    with open(model.path, 'w') as output_file:
        for i in range(num_steps):
            output_file.write("Step {}\n{}\n=====\n".format(i, line))

    # Use model.get() to get a Model artifact, which has a .metadata dictionary
    # to store arbitrary metadata for the output artifact.
    model.get().metadata['accuracy'] = 0.9
Beispiel #2
0
 def test_func(input_artifact_one: InputArtifact(Dataset)):
   self.assertEqual(input_artifact_one.uri,
                    'gs://some-bucket/input_artifact_one')
   self.assertEqual(
       input_artifact_one.path,
       os.path.join(self._test_dir, 'some-bucket/input_artifact_one'))
   self.assertEqual(input_artifact_one.get().name, 'input_artifact_one')
Beispiel #3
0
def train(dataset: InputArtifact(Dataset)) -> NamedTuple(
    'Outputs', [
        ('scalar', str),
        ('model', Model),
    ]):
  """Dummy Training step."""
  with open(dataset.path, 'r') as f:
    data = f.read()
  print('Dataset:', data)

  scalar = '123'
  model = 'My model trained using data: {}'.format(data)

  from collections import namedtuple
  output = namedtuple('Outputs', ['scalar', 'model'])
  return output(scalar, model)
Beispiel #4
0
def output_named_tuple(artifact: InputArtifact(Dataset)) -> NamedTuple(
        'Outputs', [
            ('scalar', str),
            ('metrics', Metrics),
            ('model', Model),
        ]):
    scalar = "123"

    import json
    metrics = json.dumps({
        'metrics': [{
            'name': 'accuracy',
            'numberValue': 0.9,
            'format': "PERCENTAGE",
        }]
    })

    with open(artifact.path, 'r') as f:
        artifact_contents = f.read()
    model = "Model contents: " + artifact_contents

    from collections import namedtuple
    output = namedtuple('Outputs', ['scalar', 'metrics', 'model'])
    return output(scalar, metrics, model)
Beispiel #5
0
 def _make_input_artifact(cls, runtime_artifact: Dict):
     artifact = create_runtime_artifact(runtime_artifact)
     return InputArtifact(artifact_type=type(artifact), artifact=artifact)