def write_input_layer(model_name='sas', layer_name='data', channels='-1',
    width='-1', height='-1', scale='1.0', offsets=None, std=None,
    model_type='CNN'):
    """
    Generate Python code defining a SAS deep learning input layer

    Parameters
    ----------
    model_name : string
       Name for deep learning model
    layer_name : string
       Layer name
    channels : string
       number of input channels
    width : string
       image width
    height : string
       image height
    scale : string
       scaling factor to apply to raw image pixel data
    offsets : list
       image channel offsets, these values will be subtracted from the pixels of 
       each image channel
    std : list
       image channel standardization, the pixels of each image channel will be divided
       by these values
    model_type : string
       Specifies the deep learning model type (either CNN or RNN)

    Returns
    -------
    string
        String representing Python code defining a SAS deep learning input layer

    """
    if offsets is None:
        str_offset = 'None'
    else:
        str_offset = repr(offsets)
    if std is None:
        str_std = 'None'
    else:
        str_std = repr(std)
    if model_type == 'CNN':
        out = [
            'def sas_model_gen(s, input_crop_type=None, input_channel_offset='
             + str_offset + ', norm_std = ' + str_std +
            ', input_image_size=None):',
            '   # quick check for deeplearn actionset',
            '   actionset_list = s.actionsetinfo().setinfo.actionset.tolist()',
            '   actionset_list = [item.lower() for item in actionset_list]',
            '   if "deeplearn" not in actionset_list:s.loadactionset("deeplearn")'
            , '   ', '   # quick error-checking and default setting',
            '   if (input_crop_type is None):',
            '       input_crop_type="NONE"', '   else:',
            '       if (input_crop_type.upper() != "NONE") and (input_crop_type.upper() != "UNIQUE"):'
            ,
            '           raise ValueError("Parameter input_crop_type can only be NONE or UNIQUE")'
            , '', '   if (input_image_size is not None):',
            '       channels = input_image_size[0]',
            '       if (len(input_image_size) == 2):',
            '           height = width = input_image_size[1]',
            '       elif (len(inputImageSize) == 3):',
            '           height,width = input_image_size[1:]',
            '       else:',
            '           raise ValueError("Parameter input_image_size must be a tuple with two or three entries")'
            , '', '   # instantiate model', 
            '   s.buildModel(model=dict(name=' + repr(model_name) +
            ',replace=True),type="CNN")', '', '   # input layer', 
            '   nchannels=' + channels,
            '   if input_channel_offset is None and nchannels==3:',
            '       print("INFO: Setting channel mean values to ImageNet means")'
            , '       input_channel_offset = [103.939, 116.779, 123.68]', 
            '       s.addLayer(model=' + repr(model_name) + ', name=' +
            repr(layer_name) + ',', 
            '                  layer=dict( type="input", nchannels=' +
            channels + ', width=' + width + ', height=' + height + ',', 
            '                  scale = ' + scale +
            ', randomcrop=input_crop_type, offsets=input_channel_offset, offsetStd=norm_std))'
            , '   elif input_channel_offset is not None:', 
            '       s.addLayer(model=' + repr(model_name) + ', name=' +
            repr(layer_name) + ',', 
            '                  layer=dict( type="input", nchannels=' +
            channels + ', width=' + width + ', height=' + height + ',', 
            '                  scale = ' + scale +
            ', randomcrop=input_crop_type, offsets=input_channel_offset, offsetStd=norm_std))'
            , '   else:', '       s.addLayer(model=' + repr(model_name) +
            ', name=' + repr(layer_name) + ',', 
            '                  layer=dict( type="input", nchannels=' +
            channels + ', width=' + width + ', height=' + height + ',', 
            '                  scale = ' + scale +
            ', randomcrop=input_crop_type, offsetStd=norm_std))']
    else:
        out = ['def sas_model_gen(s):',
            '   # quick check for deeplearn actionset',
            '   actionset_list = s.actionsetinfo().setinfo.actionset.tolist()',
            '   actionset_list = [item.lower() for item in actionset_list]',
            '   if "deeplearn" not in actionset_list:s.loadactionset("deeplearn")'
            , '   ', '', '   # instantiate model', 
            '   s.buildModel(model=dict(name=' + repr(model_name) +
            ',replace=True),type="RNN")', '', '   # input layer', 
            '   s.addLayer(model=' + repr(model_name) + ', name=' + repr(
            layer_name) + ',', 
            '              layer=dict( type="input", nchannels=' + channels +
            ', width=' + width + ',', '                           height=' +
            height + '))']
    return '\n'.join(out)
