@@ -70,9 +70,19 @@ export default function InstanceSegmentationScreen() {
7070
7171 // Set default input size when model is ready
7272 useEffect ( ( ) => {
73- if ( isReady && availableInputSizes && availableInputSizes . length > 0 ) {
74- setSelectedInputSize ( availableInputSizes [ 0 ] ) ;
73+ if ( ! isReady ) return ;
74+
75+ if ( availableInputSizes && availableInputSizes . length > 0 ) {
76+ setSelectedInputSize ( ( prev ) => {
77+ if ( typeof prev === 'number' && availableInputSizes . includes ( prev ) ) {
78+ return prev ;
79+ }
80+ return availableInputSizes [ 0 ] ;
81+ } ) ;
82+ return ;
7583 }
84+
85+ setSelectedInputSize ( null ) ;
7686 } , [ isReady , availableInputSizes ] ) ;
7787
7888 const handleCameraPress = async ( isCamera : boolean ) => {
@@ -90,14 +100,21 @@ export default function InstanceSegmentationScreen() {
90100 const runForward = async ( ) => {
91101 if ( ! imageUri || imageSize . width === 0 || imageSize . height === 0 ) return ;
92102
103+ const inputSize =
104+ availableInputSizes &&
105+ typeof selectedInputSize === 'number' &&
106+ availableInputSizes . includes ( selectedInputSize )
107+ ? selectedInputSize
108+ : undefined ;
109+
93110 try {
94111 const start = Date . now ( ) ;
95112 const output = await forward ( imageUri , {
96113 confidenceThreshold : 0.5 ,
97114 iouThreshold : 0.55 ,
98115 maxInstances : 20 ,
99116 returnMaskAtOriginalResolution : true ,
100- inputSize : selectedInputSize ?? undefined ,
117+ inputSize,
101118 } ) ;
102119
103120 setInferenceTime ( Date . now ( ) - start ) ;
0 commit comments