cl-waffe
cl-waffe copied to clipboard
!argmax/!argmin requires tensor to be copied.
In the function trainer:
(defun valid (trainer dataset batch-size)
"Valid trainer"
(let ((count 0)
(correct 0))
(loop for index fixnum upfrom 0 below (get-dataset-length dataset) by batch-size
do (let* ((ds (get-dataset dataset index))
(x (car ds))
(y (second ds))
(out (const (value (call (slot-value trainer 'model) x))))
(out-labels (!argmax out))
(y-labels (!argmax (const (copy-mat (data y)))))) ; <--- Here
(with-facets ((out-labels ((data out-labels) 'backing-array :direction :input))
(y-labels ((data y-labels) 'backing-array :direction :input)))
(loop for i below (length out-labels)
do (progn
(incf count 1)
(if (= (aref out-labels i) (aref y-labels i))
(incf correct 1)
(incf correct 0)))))))
(format t "Accuracy:~a~C" (coerce (/ correct count) 'float) #\newline)))
This creates y's copy every time otherwise y-labels' value is not updated.
I guess this is due to accessing the wrong facets or something like that. hmm