lib/dnn/core/model.rb in ruby-dnn-0.5.8 vs lib/dnn/core/model.rb in ruby-dnn-0.5.9
- old
+ new
@@ -100,10 +100,13 @@
batch_size: 1,
test: nil,
verbose: true,
batch_proc: nil,
&epoch_proc)
+ unless compiled?
+ raise DNN_Error.new("The model is not compiled.")
+ end
@batch_size = batch_size
num_train_data = x.shape[0]
(1..epochs).each do |epoch|
puts "【 epoch #{epoch}/#{epochs} 】" if verbose
(num_train_data.to_f / @batch_size).ceil.times do |index|
@@ -166,11 +169,15 @@
y_batch[j, false] = y[k, false]
end
x_batch, y_batch = batch_proc.call(x_batch, y_batch) if batch_proc
out = forward(x_batch, false)
@batch_size.times do |j|
- correct += 1 if out[j, true].max_index == y_batch[j, true].max_index
+ if @layers[-1].shape == [1]
+ correct += 1 if out[j, 0].round == y_batch[j, 0].round
+ else
+ correct += 1 if out[j, true].max_index == y_batch[j, true].max_index
+ end
end
end
correct.to_f / x.shape[0]
end
@@ -181,9 +188,12 @@
def predict1(x)
predict(SFloat.cast([x]))[0, false]
end
def forward(x, training)
+ unless compiled?
+ raise DNN_Error.new("The model is not compiled.")
+ end
@training = training
@layers.each do |layer|
x = layer.forward(x)
end
x