2015-11-12 56 views
2

當我從git中克隆它時,AlexNet的基準是Tensorflow存儲庫的一部分。基準測試實現了圖層,但是在我看來,AlexNet的實際權重並未在任何時候加載。是否有AlexNet權重可用於Tensorflow?

我想玩Tensorflow,但我的應用程序(caffe)正在使用預先訓練的AlexNet。

你是否認爲他們也會發布權重?

回答

0

沒有,基準文件只是執行,你必須訓練和評估

0

是的,有AlexNet可供Tensorflow預訓練的權重,你可以下載它here

將它們加載到你的項目,你可以使用下面的代碼(改編自here

# Load the weights into memory 
weights_dict = np.load('./weight-path/bvlc_alexnet.npy', encoding='bytes').item() 

# Loop over all layer names stored in the weights dict 
for op_name in weights_dict: 

    # Check if layer should be trained from scratch 
    if op_name not in self.SKIP_LAYER: 

     with tf.variable_scope(op_name, reuse=True): 

      # Assign weights/biases to their corresponding tf variable 
      for data in weights_dict[op_name]: 

       # Biases 
       if len(data.shape) == 1: 
        var = tf.get_variable('biases', trainable=False) 
        session.run(var.assign(data)) 

       # Weights 
       else: 
        var = tf.get_variable('weights', trainable=False) 
        session.run(var.assign(data)) 
相關問題