-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3cad0f
commit b5082b3
Showing
2 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require_relative 'mlp' | ||
require_relative 'dataset' | ||
require 'optparse' | ||
|
||
snapshot_filename = nil | ||
opt = OptionParser.new | ||
opt.on('-r', '--resume VALUE', "Resume the training from snapshot") { |v| snapshot_filename = v } | ||
opt.parse!(ARGV) | ||
|
||
# 学習させた時と同じモデルを定義 | ||
predictor = MLP.new | ||
|
||
# スナップショットをモデルに読み込む | ||
Chainer::Serializers::MarshalDeserializer.load_file(snapshot_filename, predictor, path: '/updater/model:main/@predictor/') | ||
|
||
# テスト用のデータセットを取得 | ||
test_dataset = Dataset.get_iris | ||
|
||
pass_count = 0 | ||
(0...test_dataset.size).each do |i| | ||
variables, answer = test_dataset[i] | ||
|
||
# 変数をモデルに与えて推論結果を取得 | ||
prediction = predictor.(variables).data.argmax | ||
pass_count += 1 if prediction == answer | ||
|
||
print format("test%03d: prediction = %d, answer = %d\n",i, prediction, answer) | ||
end | ||
|
||
print "accuracy: #{pass_count * 100.0 / test_dataset.size}\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters