2013-07-25 70 views
1

可以將數據從python命令添加到yaml文件嗎? 這裏的YAML文件:Python和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[]名單?

回答

0

您可以使用PyYAML來在Python中處理YAML。看看PyYAML documentation 和主頁上的例子。這些應該讓你知道如何解決你的需求