lib/dnn/core/models.rb in ruby-dnn-0.15.0 vs lib/dnn/core/models.rb in ruby-dnn-0.15.1
- old
+ new
@@ -156,11 +156,11 @@
alias fit train
# Start training by iterator.
# Setup the model before use this method.
- # @param [Iterator] train_iterator Iterator used for training.
+ # @param [DNN::Iterator] train_iterator Iterator used for training.
# @param [Integer] epochs Number of training.
# @param [Integer] batch_size Batch size used for one training.
# @param [Integer] initial_epoch Initial epoch.
# @param [Array | NilClass] test If you to test the model for every 1 epoch,
# specify [x_test, y_test]. Don't test to the model, specify nil.
@@ -258,14 +258,17 @@
# @param [Numo::SFloat] y Output test data.
# @param [Integer] batch_size Batch size used for one test.
# @return [Array] Returns the test data accuracy and mean loss in the form [accuracy, mean_loss].
def evaluate(x, y, batch_size: 100)
check_xy_type(x, y)
- evaluate_by_iterator(Iterator.new(x, y, random: false))
+ evaluate_by_iterator(Iterator.new(x, y, random: false), batch_size: batch_size)
end
- # Evaluate model by iterator
+ # Evaluate model by iterator.
+ # @param [DNN::Iterator] test_iterator Iterator used for testing.
+ # @param [Integer] batch_size Batch size used for one test.
+ # @return [Array] Returns the test data accuracy and mean loss in the form [accuracy, mean_loss].
def evaluate_by_iterator(test_iterator, batch_size: 100)
num_test_datas = test_iterator.num_datas
batch_size = batch_size >= num_test_datas[0] ? num_test_datas : batch_size
total_correct = 0
sum_loss = 0
@@ -296,9 +299,10 @@
end
# Implement the process to accuracy this model.
# @param [Numo::SFloat] x Input test data.
# @param [Numo::SFloat] y Output test data.
+ # @return [Integer] Returns the test data accuracy.
private def accuracy(x, y)
if x.shape[1..-1] == [1]
correct = 0
x.shape[0].times do |i|
if @loss_func.is_a?(Losses::SigmoidCrossEntropy)