TensorFlow:恢复RNN网后损失会上升

时间:2017-04-26 23:36:04

标签: tensorflow recurrent-neural-network language-model

环境信息

  • 操作系统:Windows 7 64位
  • 从预先建立的点子(无CUDA)安装的Tensorflow:1.0.1
  • Python 3.5.2 64位

问题

我在恢复网络方面遇到了问题(RNN字符基础语言模型)。以下是具有相同问题的简化版本。

当我第一次运行它时,我得到了这个。

import UIKit
import Firebase
import FirebaseDatabase

class FirstViewTableViewController: UITableViewController, UISearchBarDelegate {

let whiskeySearchBar = UISearchBar()
var ref: FIRDatabaseReference?
var refHandle: UInt!
var whiskeyList = [WhiskeyItem]()

let cell = "cell"

override func viewDidLoad() {

    super.viewDidLoad()

    createWhiskeySearchBar()

    //Display Firebase whiskey data:
    ref = FIRDatabase.database().reference()
    fetchWhiskey()

}

func createWhiskeySearchBar() {

    whiskeySearchBar.showsCancelButton = false
    whiskeySearchBar.placeholder = "Search whiskeys"
    whiskeySearchBar.delegate = self

    self.navigationItem.titleView = whiskeySearchBar
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return whiskeyList.count
}


 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

 // Configure the cell...

 cell.textLabel?.text = whiskeyList[indexPath.row].wName

 return cell
 }




func fetchWhiskey() {
    refHandle = ref?.child("whiskey").observe(.childAdded, with: { (snapshot) in
        if let dictionary = snapshot.value as? [String : AnyObject] {

            print(dictionary)
            let whiskeyItemInstance = WhiskeyItem()

            whiskeyItemInstance.setValuesForKeys(dictionary)
            self.whiskeyList.append(whiskeyItemInstance)

            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    })

}

但是在第二次运行中,恢复参数后,我明白了。

    ...
    step 160: loss = 1.956 (perplexity = 7.069016620211226)
    step 180: loss = 1.837 (perplexity = 6.274748642468816)
    step 200: loss = 1.825 (perplexity = 6.202084762557817)

所有tf变量似乎都被正确恢复,包括状态,它将被馈送到RNN。 数据位置也会恢复(来自'步骤')。

我也为MNIST识别模型制作了一个类似的程序,这个程序运行正常:恢复前后的损失是连续的。

是否还有其他参数或状态需要保存和恢复?

    step 220: loss = 2.346 (perplexity = 10.446611983898903)
    step 240: loss = 2.346 (perplexity = 10.446709120339545)
    ...

1 个答案:

答案 0 :(得分:2)

问题解决了。它与RNN和TensorFlow无关。

我改变了

chars = list(set(data))

chars = sorted(set(data))

现在可行。

这是因为python uses a random hash function来构建集合,并且每次python重新启动时,都会出现问题。有不同的顺序。