view keras_model_builder.xml @ 1:5f39cff2a372 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
author bgruening
date Fri, 13 Sep 2019 12:29:52 -0400
parents 818896cd2213
children 449a757be9c9
line wrap: on
line source

<tool id="keras_model_builder" name="Create deep learning model" version="@KERAS_VERSION@">
    <description>with an optimizer, loss function and fit parameters</description>
    <macros>
        <import>main_macros.xml</import>
        <import>keras_macros.xml</import>
    </macros>
    <expand macro="python_requirements"/>
    <expand macro="macro_stdio"/>
    <version_command>echo "@KERAS_VERSION@"</version_command>
    <command>
        <![CDATA[
        python '$__tool_directory__/keras_deep_learning.py'
                --inputs '$inputs'
                --tool_id 'keras_model_builder'
                --outfile '$outfile'
                --model_json '$mode_selection.infile_json'
                #if $mode_selection.mode_type == 'prefitted'
                --infile_weights '$mode_selection.infile_weights'
                    #end if
                #if $mode_selection.mode_type == 'train_model' and $mode_selection.get_params
                --outfile_params '$outfile_params'
                #end if
        ]]>
    </command>
    <configfiles>
        <inputs name="inputs"/>
    </configfiles>
    <inputs>
        <conditional name="mode_selection">
            <param name="mode_type" type="select" label="Choose a building mode">
                <option value="train_model" selected="true">Build a training model</option>
                <option value="prefitted">Load a pretrained model for prediction</option>
            </param>
            <when value="train_model">
                <param name="infile_json" type="data" format="json" label="Select the dataset containing model configurations (JSON)"/>
                <param name="learning_type" type="select" label="Do classification or regression?">
                    <option value="KerasGClassifier">KerasGClassifier</option>
                    <option value="KerasGRegressor">KerasGRegressor</option>
                </param>
                <expand macro="keras_compile_params_section"/>
                <expand macro="keras_fit_params_section"/>
                <param name="random_seed" type="integer" value="" optional="true" label="Random Seed" help="Integer or blank for None. Warning: when random seed is set to an integer, training will be running in single thread mode, which may cause slowness."/>
                <param name="get_params" type="boolean" truevalue="booltrue" falsevalue="boolfalse" checked="false" label="Output parameters for searchCV?" help="Optional. Tunable parameters could be obtained through `estimator_attributes` tool."/>
            </when>
            <when value="prefitted">
                <param name="infile_json" type="data" format="json" label="Select the dataset containing model configurations (JSON)"/>
                <param name="infile_weights" type="data" format="h5" label="Select the dataset containing keras layers weights"/>
            </when>
        </conditional>
    </inputs>
    <outputs>
        <data format="zip" name="outfile" label="Keras Model Builder    on ${on_string}"/>
        <data format="tabular" name="outfile_params" label="get_params for Keras Model Builder on ${on_string}">
            <filter>mode_selection['mode_type'] == 'train_model' and mode_selection['get_params']</filter>
        </data>
    </outputs>
    <tests>
        <test>
            <conditional name="mode_selection">
                <param name="infile_json" value="keras01.json" ftype="json"/>
                <param name="learning_type" value="KerasGRegressor"/>
                <section name="fit_params">
                    <param name="epochs" value="100"/>
                </section>
            </conditional>
            <output name="outfile" file="keras_model01" compare="sim_size" delta="5"/>
        </test>
        <test>
            <conditional name="mode_selection">
                <param name="infile_json" value="keras02.json" ftype="json"/>
                <section name="compile_params">
                    <conditional name="optimizer_selection">
                        <param name="optimizer_type" value="Adam"/>
                    </conditional>
                </section>
                <section name="fit_params">
                    <param name="epochs" value="100"/>
                </section>
            </conditional>
            <output name="outfile" file="keras_model02" compare="sim_size" delta="5"/>
        </test>
        <test>
            <conditional name="mode_selection">
                <param name="mode_type" value="prefitted"/>
                <param name="infile_json" value="keras03.json" ftype="json"/>
                <param name="infile_weights" value="keras_save_weights01.h5" ftype="h5"/>
            </conditional>
            <output name="outfile" file="keras_prefitted01.zip" compare="sim_size" delta="5"/>
        </test>
        <test>
            <conditional name="mode_selection">
                <param name="infile_json" value="keras04.json" ftype="json"/>
                <param name="learning_type" value="KerasGRegressor"/>
                <section name="compile_params">
                    <conditional name="optimizer_selection">
                        <param name="optimizer_type" value="Adam"/>
                    </conditional>
                    <param name="metrics" value="mse"/>
                    <param name="loss" value="mean_squared_error"/>
                </section>
                <section name="fit_params">
                    <param name="epochs" value="100"/>
                </section>
                <param name="random_seed" value="42"/>
                <param name="get_params" value="true"/>
            </conditional>
            <output name="outfile" file="keras_model04" compare="sim_size" delta="1"/>
            <output name="outfile_params" file="keras_params04.tabular"/>
        </test>
    </tests>
    <help>
    <![CDATA[
**Help**

**What it does**

Creates an estimator object (classifier or regressor) by using the architecture JSON from 'Create architecture' tool and adding an optimizer, loss function and other fit parameters. The fit parameters include the number of training epochs and batch size. Multiple attributes of an optimizer can also be set. A pre-trained deep learning model can also be used with this tool.

**Return**

An estimator object which can be used to train on a dataset.

**How to compile the architecture using this tool?**

1. Choose the architecture building mode. For example - choose "Build a training model".
2. Attach an architecture JSON file (obtained after executing "Create architecture" tool) which contains information about multiple layers.
3. Select a loss function. For example - for classification tasks, choose 'cross entropy' losses and for regression tasks, choose 'mean squared' or 'mean absolute' losses.
4. Choose an optimizer which minimizes the loss computed by the loss function. Multiple attributes of the chosen optimizer can be modified. 'RMSProp' and 'Adam' are some of the popular optimizers.
5. Insert the number of iterations (epochs) and the size of training batches (batch_size).
6. Execute the tool to get a compiled estimator object.

    ]]>
    </help>
    <citations>
        <expand macro="keras_citation"/>
        <expand macro="tensorflow_citation"/>
    </citations>
</tool>