Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically dispatch function but do not print result #231

Open
albertotb opened this issue Mar 3, 2020 · 3 comments
Open

Dynamically dispatch function but do not print result #231

albertotb opened this issue Mar 3, 2020 · 3 comments

Comments

@albertotb
Copy link

albertotb commented Mar 3, 2020

Can Fire be used to dynamically dispatch a function as in the dict example but without printing the result? I would like to do something with the return value, for instance:

if __name__ == "__main__":
    # inception and exception are functions that return keras models, 
    # each having its own parameters 
    ret = Fire.Fire({'inception': inception,
                     'xception': xception})

    # do something with ret

If I try to run the previous code, for instance:

python ./train.py inception 100 100 10

I get the following error:

ERROR: The function received no value for the required argument: inputs
2020-03-03 16:30:13.774542: W tensorflow/python/util/util.cc:319] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
Usage: train.py inception 100 100 10 - <group|command|value> | --inputs=INPUTS <flags> [ARGS]...
  available groups:      inbound_nodes | input | input_names | input_shape |
                         inputs | layers | losses | metrics | metrics_names |
                         non_trainable_variables | non_trainable_weights |
                         outbound_nodes | output | output_names |
                         output_shape | outputs | state_updates | submodules |
                         trainable_variables | trainable_weights | updates |
                         variables | weights
  available commands:    add_loss | add_metric | add_update | add_variable |
                         add_weight | apply | build | call | compile |
                         compute_mask | compute_output_shape |
                         compute_output_signature | count_params | evaluate |
                         evaluate_generator | fit | fit_generator |
                         from_config | get_config | get_input_at |
                         get_input_mask_at | get_input_shape_at | get_layer |
                         get_losses_for | get_output_at | get_output_mask_at |
                         get_output_shape_at | get_updates_for | get_weights |
                         load_weights | name_scope | predict |
                         predict_generator | predict_on_batch | reset_metrics |
                         reset_states | save | save_weights | set_weights |
                         summary | test_on_batch | to_json | to_yaml |
                         train_on_batch | with_name_scope
  available values:      activity_regularizer | built | dtype | dynamic |
                         input_mask | input_spec | name | optimizer |
                         output_mask | run_eagerly | stateful |
                         supports_masking | trainable
  flags are accepted

For detailed information on this command, run:
  train.py inception 100 100 10 - -- --help`
@dbieber
Copy link
Member

dbieber commented Mar 4, 2020

This is not an option today but is a good idea. Thanks for opening the issue.

@dbieber
Copy link
Member

dbieber commented Mar 9, 2020

Take a look at the discussion in #188, which includes proposals for how to disable printing the output.

@spyoungtech
Copy link

spyoungtech commented Mar 25, 2020

One way you might be able to do something like this is by using contextlib.redirect_stdout to suppress the output. For example, you could redirect to /dev/null (or platform equivalent)

import os
import contextlib
with open(os.devnull, 'w') as devnull:
    with contextlib.redirect_stdout(devnull):
        ret = fire.Fire(something)
# do something with ret

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants