Python和Yaml文件插入对象

2024-05-19 10:23:48 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以将python命令中的数据添加到yaml文件中? 以下是yaml文件:

!obj:pylearn2.train.Train {    
    dataset: !obj:pylearn2.datasets.hepatitis.Hepatitis  &dataset {
    },
    model: !obj:pylearn2.models.mlp.MLP {
        batch_size: 50,
        layers : [
            # We use two hidden layers with maxout activations

            !obj:pylearn2.models.maxout.Maxout {
                layer_name: 'h0',
                num_units: 300,
                num_pieces: 2,
                irange: 0.5,
            },

           #I want to add another of !obj:pylearn2.models.maxout.Maxout{...} from my python file... 

            !obj:pylearn2.models.mlp.Softmax {
                layer_name: 'y',
                # Initialize the weights to all 0s
                irange: 0.5,
                n_classes: 2
            }
        ],
        nvis: 2612,
    },
    algorithm: !obj:pylearn2.training_algorithms.sgd.SGD {
        learning_rate : 1e-3,
        batch_size : 50,
        monitoring_batches : 20,
        monitoring_dataset : *dataset, 
        termination_criterion : !obj:pylearn2.termination_criterion.MonitorBased {
            prop_decrase: .01,
            N : 35
        },
    } ,
    #save the pickle file to the current directory
    save_path : ./garbageprova.pkl,
    #frequency of updating the file
    save_freq : 100
}

如何向我的model.layers[]列表添加另一个元素?在


Tags: 文件thetoobjyamlmodelmodelssave

热门问题