Reputation: 56
In my colab notebook I would like add some custom parameters and for this I need #@param ecc
near to them.
I'm using Jupyter magic commands environment variable %env
and the system takes the whole line (comment included) and not only the variable. This results in an error. I guess it's not possible to comment next to %env
magic variables, or is there a way?
I'm doing this:
%env checkpoint_iter = 50
%env content_weight = 8 #@param {type:"slider", min:0, max:100, step:0.1} #@markdown Weight of content image
!python -W ignore main.py ${checkpoint_iter} ${content_weight}
And then I receive:
Traceback (most recent call last):
File "main.py", line 25, in <module>
checkpoint_iter = int(sys.argv[9])
ValueError: invalid literal for int() with base 10: '#@param'
My my goal would be to get something like this:
How can I reach this?
Upvotes: 0
Views: 273
Reputation: 13656
You can not comment inside Collab forms.
But you can combine a comment, slider and env. variable like this:
#@markdown Checkpoint iteration
checkpoint_iter = 30 #@param {type:"integer"}
%env checkpoint_iter = $checkpoint_iter
#@markdown Weight of content image
content_weight = 21.4 #@param {type:"slider", min:0, max:100, step:0.1}
%env content_weight = $content_weight
By the way, you don't have to use environmental variables to pass command line parameters. Using variable reference $<var_name>
should work the same:
weight = 86.5 #@param {type:"slider", min:0, max:100, step:0.1}
iter = 50
!python -W ignore main.py $iter $weight
Upvotes: 1