File tree Expand file tree Collapse file tree 3 files changed +18
-10
lines changed
digit-recognition/frontend/src/features/digit-recognizer Expand file tree Collapse file tree 3 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,8 @@ export const DigitCanvas = ({
4343 ctx . imageSmoothingEnabled = true ;
4444 }
4545 }
46- } , [ canvasRef ] ) ;
46+ // eslint-disable-next-line react-hooks/exhaustive-deps
47+ } , [ ] ) ;
4748
4849 const startDrawing = ( e : React . MouseEvent ) => {
4950 const canvas = canvasRef . current ;
Original file line number Diff line number Diff line change 11import { Button , Card } from "@/components" ;
22import { DigitCanvas } from "./DigitCanvas" ;
3- import { useRef , useState } from "react" ;
3+ import { useEffect , useRef , useState } from "react" ;
44import { findMaxIndex , getFlattenedPixelArray } from "./utils" ;
55import { useDigitRecognitionPredict } from "./api/useDigitRecognitionPredict" ;
66import { useReadRpcState } from "./api/readRpcState" ;
@@ -52,16 +52,21 @@ export const DigitRecognizer = () => {
5252 : findMaxIndex ( rpcState . map ( getFloatingPoint ) ) ;
5353
5454 const predictedDigit = isSubmited ? currentState : null ;
55- console . log (
56- "current state:" ,
57- currentState ,
58- rpcState ?. map ( getFloatingPoint ) ,
59- rpcState
60- ) ;
55+
56+ useEffect ( ( ) => {
57+ console . log (
58+ "current state:" ,
59+ currentState ,
60+ rpcState ?. map ( getFloatingPoint ) ,
61+ rpcState
62+ ) ;
63+ // eslint-disable-next-line react-hooks/exhaustive-deps
64+ } , [ ] ) ;
6165
6266 const onSubmit = ( ) => {
6367 setIsSubmiting ( true ) ;
6468 const flattenedPixelArray = getFlattenedPixelArray ( canvasRef ) ;
69+ console . log ( "flattenedPixelArray:" , flattenedPixelArray . join ( ", " ) ) ;
6570 digitRecognitionPredict ( flattenedPixelArray ) ;
6671 } ;
6772
Original file line number Diff line number Diff line change @@ -28,17 +28,19 @@ export const getFlattenedPixelArray = (
2828 continue ;
2929 }
3030
31- const getRandomDeviation = ( ) => Math . round ( Math . random ( ) * 10 - 5 ) ;
3231 const isUseDeviation = Math . random ( ) > 0.5 ;
3332 const middleBrightness = 250 ;
33+ const deviationRange = 5 ;
34+ const deviationSpread = deviationRange * 2 ;
35+ const getRandomDeviation = ( ) =>
36+ Math . round ( Math . random ( ) * deviationSpread - deviationRange ) ;
3437 const noisedBrightness = isUseDeviation
3538 ? middleBrightness + getRandomDeviation ( )
3639 : middleBrightness ;
3740
3841 grayscaleArray . push ( Math . min ( noisedBrightness , 255 ) ) ;
3942 }
4043
41- console . log ( "grayscaleArray:" , grayscaleArray . join ( ", " ) ) ;
4244 return grayscaleArray ; // Array of 784 elements
4345} ;
4446
You can’t perform that action at this time.
0 commit comments