@@ -17,6 +17,7 @@ import { View, StyleSheet, Image } from 'react-native';
1717import React , { useContext , useEffect , useState } from 'react' ;
1818import { GeneratingContext } from '../../context' ;
1919import ScreenWrapper from '../../ScreenWrapper' ;
20+ import ErrorBanner from '../../components/ErrorBanner' ;
2021
2122const numberToColor : number [ ] [ ] = [
2223 [ 255 , 87 , 51 ] , // 0 Red
@@ -44,19 +45,29 @@ const numberToColor: number[][] = [
4445
4546export default function SemanticSegmentationScreen ( ) {
4647 const { setGlobalGenerating } = useContext ( GeneratingContext ) ;
47- const { isReady, isGenerating, downloadProgress, forward } =
48- useSemanticSegmentation ( {
49- model : DEEPLAB_V3_MOBILENET_V3_LARGE_QUANTIZED ,
50- } ) ;
48+ const {
49+ isReady,
50+ isGenerating,
51+ downloadProgress,
52+ forward,
53+ error : modelError ,
54+ } = useSemanticSegmentation ( {
55+ model : DEEPLAB_V3_MOBILENET_V3_LARGE_QUANTIZED ,
56+ } ) ;
5157 const [ imageUri , setImageUri ] = useState ( '' ) ;
5258 const [ imageSize , setImageSize ] = useState ( { width : 0 , height : 0 } ) ;
5359 const [ segImage , setSegImage ] = useState < SkImage | null > ( null ) ;
5460 const [ canvasSize , setCanvasSize ] = useState ( { width : 0 , height : 0 } ) ;
61+ const [ error , setError ] = useState < string | null > ( null ) ;
5562
5663 useEffect ( ( ) => {
5764 setGlobalGenerating ( isGenerating ) ;
5865 } , [ isGenerating , setGlobalGenerating ] ) ;
5966
67+ useEffect ( ( ) => {
68+ if ( modelError ) setError ( String ( modelError ) ) ;
69+ } , [ modelError ] ) ;
70+
6071 const handleCameraPress = async ( isCamera : boolean ) => {
6172 const image = await getImage ( isCamera ) ;
6273 if ( ! image ?. uri ) return ;
@@ -100,21 +111,22 @@ export default function SemanticSegmentationScreen() {
100111 ) ;
101112 setSegImage ( img ) ;
102113 } catch ( e ) {
103- console . error ( e ) ;
114+ setError ( e instanceof Error ? e . message : String ( e ) ) ;
104115 }
105116 } ;
106117
107- if ( ! isReady ) {
118+ if ( ! isReady && ! modelError ) {
108119 return (
109120 < Spinner
110- visible = { ! isReady }
121+ visible = { true }
111122 textContent = { `Loading the model ${ ( downloadProgress * 100 ) . toFixed ( 0 ) } %` }
112123 />
113124 ) ;
114125 }
115126
116127 return (
117128 < ScreenWrapper >
129+ < ErrorBanner message = { error } onDismiss = { ( ) => setError ( null ) } />
118130 < View style = { styles . imageCanvasContainer } >
119131 < View style = { styles . imageContainer } >
120132 < Image
0 commit comments