# Dialog script for trainpix2pix automatically generated

{
    name	trainpix2pix
    script	trainpix2pix
    label	"Train Pix2Pix"

    help {
	""
    }

    inputlabel	1	"Input 1"
    inputlabel	2	"Input 2"
    inputlabel	3	"Input 3"
    inputlabel	4	"Input 4"

    group {
        name    "training"
        label   "Training"

        groupsimple {
            name    "tasks"
            label   "Tasks"

            parm {
                name    "pdg_workitemgeneration"
                label   "Generate When"
                type    ordinal
                default { "2" }
                menu usetokenvalue {
                    [ "opmenu -l -a create_venv pdg_workitemgeneration" ]
                }
                parmtag { "autoscope" "0000000000000000" }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "pdg_cachemode"
                label   "Cache Mode"
                type    ordinal
                default { "0" }
                menu usetokenvalue {
                    [ "opmenu -l -a create_venv pdg_cachemode" ]
                }
                parmtag { "autoscope" "0000000000000000" }
                parmtag { "script_callback_language" "python" }
            }
        }

        groupcollapsible {
            name    "venv"
            label   "Virtual Environment"

            parm {
                name    "venvpath"
                label   "Environment Path"
                type    directory
                default { "$HIP/venv.`@pdg_schedulername`" }
                help    "The path to the virtual environment on disk. This can refer to an existing virtual environment, or the path to an environment that will be created specifically for this node. 67 68     The following third party packages are installed into the virtual environment: \"matplotlib onnx tensorboard tensorboardX torch torchvision tqdm tensorboardX\""
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "venvsource"
                label   "Environment Init"
                type    ordinal
                default { "0" }
                help    "Determines whether this node should use an existing environment defined created earlier in the graph, or if it should create a new venv as part of the training process."
                menu {
                    "0" "Create New Environment"
                    "1" "Use Existing Environment"
                }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "pythonbin"
                label   "Python Bin"
                type    ordinal
                default { "1" }
                help    "When Environment Init is set to Create New Environment, this parameter determines which Python executable to use when creating the virtual environment and installing packages. This is also the version of Python that will be associated with the venv."
                disablewhen "{ venvsource != 0 }"
                menu {
                    "0" "Hython"
                    "1" "PDG Python"
                    "2" "Custom"
                }
                parmtag { "autoscope" "0000000000000000" }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "python"
                label   "Custom Python Bin"
                type    string
                default { "/usr/bin/python3" }
                help    "When Python Bin is set to Custom, this parameter determines the path to the Python interpreter to use when creating the virtual environment."
                disablewhen "{ pythonbin != 2 } { venvsource != 0 }"
                parmtag { "autoscope" "0000000000000000" }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "pdgml"
                label   "ML Module Path"
                type    directory
                default { "$HIP/pdgml" }
                help    "The path to the module that contains the ML training and testing scripts."
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "venvdescription"
                label   "Packages"
                type    label
                default { "Training a model requires the following packages in the virtual environment:\nmatplotlib onnx tensorboard tensorboardX torch torchvision tqdm " }
                parmtag { "sidefx::look" "block" }
            }
        }

        groupcollapsible {
            name    "trainingsetup"
            label   "Training Setup"

            parm {
                name    "trainingprefix"
                label   "Model Prefix"
                type    string
                default { "$OS" }
                help    " prefix string added to files and directories producing during training. This parameter should be used to create unique names when multiple training tasks output to the same training root directory. for example, when wedinging training parameters you can include `@wedgeindex` in this parameter in order to ensure unique training outputs."
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingresults"
                label   "Test Output"
                type    directory
                default { "$HIP/training/testresults" }
                help    "The output directory for test results produced when evaluating the trained model against the test dataset."
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingcheckpoints"
                label   "Model Output"
                type    directory
                default { "$HIP/training/models" }
                help    "The output directory for PyTorch models producing during the training process."
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingsaverate"
                label   "Model Save Rate"
                type    integer
                default { "1" }
                help    "The rate at which PyTorch model files are written to disk during the training process. A value of `1` indicates that a model should be written out for each training iteration, a value of `2` indicates that the model should be written every other iteration, and so on. Model files are added as outputs to the work tiems in this node. The last training iteration is always written to disk, regardless of the save rate."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingoutput"
                label   "Node Output"
                type    ordinal
                default { "0" }
                help    "Determines whether or not the node should output all training iteration work items or just the final work item from the last iteration."
                menu {
                    "0" "All Training Iterations"
                    "1" "Last Training Iteration"
                }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "sepparm"
                label   "Separator"
                type    separator
                default { "" }
            }
            parm {
                name    "trainingsaveplots"
                label   "Save SSIM Plots"
                type    toggle
                nolabel
                joinnext
                default { "1" }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingplots"
                label   "SSIM Plot Output"
                type    directory
                default { "$HIP/training/plots" }
                help    "The directory where Structural Similarity Index (SSIM) plots are written when the training process completes. The plots have the iteration number of the X axis and the SSIM metric on the Y axis, and can be useful for determine how quickly a model improved."
                disablewhen "{ trainingsaveplots == 0 }"
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "traininguseonnx"
                label   "Use ONNX"
                type    toggle
                nolabel
                joinnext
                default { "0" }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingonnx"
                label   "ONNX Output"
                type    directory
                default { "$HIP/training/onnx" }
                help    "When this parameter is enabled, the PyTorch model is converted to an ONNX model for use with the ONNX Inference SOP and written to the directory specified by this parameter. ONNX files are added as outputs to work items in this node. An ONNX file is written out each time the PyTorch model is saved, as determind by the Model Save Rate parameter."
                disablewhen "{ traininguseonnx == 0 }"
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingusetensorboard"
                label   "Use TensorBoard"
                type    toggle
                nolabel
                joinnext
                default { "0" }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingtensorboard"
                label   "TensorBoard Output"
                type    directory
                default { "$HIP/training/tensorboard" }
                help    "When this parameter is enabled, TensorBoard log files are written the directory specified by this parameter. The log files can be used with the `tensorboard` utility application."
                disablewhen "{ trainingusetensorboard == 0 }"
                parmtag { "script_callback_language" "python" }
            }
        }

        groupcollapsible {
            name    "trainingimages2"
            label   "Training Images"

            parm {
                name    "trainingimages"
                label   "Image Input Dir"
                type    directory
                default { "$HIP/training/input" }
                help    "Specifies the directory that contains the input images. The directory specified in this parameter should have two subdirectories -- one called `train` that contains the training dataset, and one called `test` that contains the test dataset."
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "traininguseimagecount"
                label   "Use Image Count"
                type    toggle
                nolabel
                joinnext
                default { "0" }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingimagecount"
                label   "Limit Dataset Size"
                type    integer
                default { "100" }
                help    "When this parameter is enabled, the model will only use the specified number of images while training. Otherwise, when this parameter is off, the entire input image dataset is use for the training process."
                disablewhen "{ traininguseimagecount == 0 }"
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingimagesize"
                label   "Image Size"
                type    integer
                default { "512" }
                help    "The size of the input images. Input images must be square, i.e. this size refers to both the length and the width of the images."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingimagechannels"
                label   "Image Channels"
                type    integer
                default { "1" }
                help    "The number of color channels in the input images. For example, for grayscale images this parameter should be set to `1` and for RGB images it should be set to `3`."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingbatchsize"
                label   "Batch Size"
                type    integer
                default { "1" }
                help    "The batch size to use when training."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingdirection"
                label   "Flip Training Direction"
                type    toggle
                default { "0" }
                help    "By default, the model learns by associated the right image in each training pair with the corresponding left image in the pair. Enabling this toggle flips the training direction."
                parmtag { "script_callback_language" "python" }
            }
        }

        groupcollapsible {
            name    "trainingparameters"
            label   "Training Parameters"

            parm {
                name    "traininglr"
                label   "Learning Rate"
                type    float
                default { "0.005" }
                help    "The rate at which the model updates while training."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingiterations"
                label   "Total Iterations"
                type    integer
                default { "50" }
                help    "The total number of training iterations. Increasing the number of iterations will generally improve the quality of the model, with diminishing returns. Training time increases linearlly with the number of iterations."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingdecay"
                label   "Decay Iterations"
                type    integer
                default { "10" }
                help    "Determines the number of iterations at the end of the training process where the model's learning rate decays from the value specified in the Learning Rate parameter to a value of 0."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "sepparm3"
                label   "Separator"
                type    separator
                default { "" }
            }
            parm {
                name    "trainingglayers"
                label   "Generator Layers"
                type    integer
                default { "8" }
                help    "The number of downsample-upsample pairs in the U-Net generator model."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingdlayers"
                label   "Discriminator Layers"
                type    integer
                default { "4" }
                help    "The number of layers in the patchGAN discriminator model."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
            parm {
                name    "trainingfilter"
                label   "Filter Size"
                type    integer
                default { "4" }
                help    "The size of the filter used in the model."
                range   { 0 10 }
                parmtag { "script_callback_language" "python" }
            }
        }

    }

    group {
        name    "training_1"
        label   "Schedulers"

        parm {
            name    "topscheduler"
            label   "TOP Scheduler Override"
            type    oppath
            joinnext
            default { "" }
            parmtag { "opfilter" "!!TOP/SCHEDULER!!" }
            parmtag { "oprelative" "." }
        }
        parm {
            name    "addjobparms"
            label   "Add Job Parms"
            type    button
            nolabel
            default { "0" }
            menu {
                [ "from top import schedulerutil" ]
                [ "return schedulerutil.schedulerTypesMenu()" ]
                language python
            }
            parmtag { "script_callback" "from top import schedulerutil; schedulerutil.onAddJobParms(kwargs)" }
            parmtag { "script_callback_language" "python" }
        }
        parm {
            name    "pdg_useschedulewhen"
            label   "Use Schedule When"
            type    toggle
            nolabel
            joinnext
            default { "0" }
            parmtag { "script_callback_language" "python" }
        }
        parm {
            name    "pdg_schedulewhen"
            label   "Schedule When"
            type    integer
            default { "1" }
            disablewhen "{ pdg_useschedulewhen == 0 }"
            range   { 0 10 }
            parmtag { "script_callback_language" "python" }
            parmtag { "sidefx::slider" "none" }
        }
        parm {
            name    "sepparm4"
            label   "Separator"
            type    separator
            default { "" }
        }
        parm {
            name    "pdg_workitemlabel"
            label   "Work Item Label"
            type    ordinal
            joinnext
            default { "0" }
            menu {
                "0" "Use Default"
                "1" "Inherit from Upstream Item"
                "2" "Custom Expression"
            }
            parmtag { "script_callback_language" "python" }
        }
        parm {
            name    "pdg_workitemlabelexpr"
            label   "Label Expression"
            type    string
            nolabel
            default { "" }
            disablewhen "{ pdg_workitemlabel != 2 }"
            parmtag { "script_callback_language" "python" }
        }
        parm {
            name    "pdg_workitempriority"
            label   "Work Item Priority"
            type    ordinal
            joinnext
            default { "0" }
            menu {
                "0" "Inherit from Upstream Item"
                "1" "Custom Expression"
            }
            parmtag { "script_callback_language" "python" }
        }
        parm {
            name    "pdg_workitempriorityexpr"
            label   "Priority Expression"
            type    integer
            nolabel
            default { "0" }
            disablewhen "{ pdg_workitempriority != 1 }"
            range   { 0 10 }
            parmtag { "script_callback_language" "python" }
            parmtag { "sidefx::slider" "none" }
        }
    }

}
