chanelcolgate / hydroelectric-project

0 stars 0 forks source link

Advanced TensorFlow Extended #18

Open chanelcolgate opened 3 years ago

chanelcolgate commented 3 years ago

Description

evaluator_trial_model = Evaluator( examples=example_gen.outputs['examples'], model=trainer_trial_model.outputs['model'], eval_config=eval_config_trial_model, instance_name='trial_model' )

- TFLite
```python
from tfx.components.trainer.executor import TrainerFnArgs
from tfx.components.trainer.rewriting import converters
from tfx.components.trainer.rewriting import rewriter
from tfx.components.trainer.rewriting import rewriter_factory

def run_fn(fn_args: TrainerFnArgs):
  ...
  temp_saving_model_dir = os.path.join(fn_args.serving_model_dir, "temp")
  # Export the model as a saved model
  model.save(temp_saving_model_dir,
             save_format='tf',
             signatures=signatures)

  # Instantiate the TFLite rewriter.
  tfrw = rewriter_factory.create_rewriter(
    rewriter_factory.TFLITE_REWRITER,
    name='tflite_rewriter',
    enable_experimental_new_converter=True
  )
  # Convert the model to TFLite format
  converters.rewriter_saved_model(temp_saving_model_dir,
                                  fn_args.serving_model_dir,
                                  tfrw,
                                  rewriter.ModelType.TFLITE_MODEL)

  # Delete the saved model after conversion
  tf.io.gfile.rmtree(temp_saving_model_dir)

evaluation = Evaluator( examples=example_gen.outputs['examples'], model=trainer_mobile_model.outputs['model'], eval_config=eval_config, instance_name="tflite_model" )


- Converting Models to TensorFlow.js: Since TFX version 0.22, an additional feature of the rewriter_factory is available: the conversion of preexisting TensorFlow models to TensorFlow.js models. This conversion allows the deployment of models to web browers and Node.js runtime environments. You can use this new functionality by replacing the `rewriter_factory` name with `rewriter_factory.TFJS_REWRITER` and set the `rewriter.ModelType` to `rewriter.ModelType.TFJS_MODEL` 

#### Estimate
#### Tests