saniaE commited on
Commit
e8f694e
·
1 Parent(s): 11c0d05

trying out a fix

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -23,7 +23,7 @@ sys.modules['keras'] = keras
23
  sys.modules['keras.engine'] = KE
24
  sys.modules['keras.layers'] = keras.layers
25
  sys.modules['keras.models'] = keras.models
26
-
27
  from fastapi import FastAPI, File, UploadFile
28
  from fastapi.middleware.cors import CORSMiddleware
29
  from PIL import Image
@@ -48,10 +48,32 @@ snapshot_download(
48
  cache_dir=cache_dir
49
  )
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Import Mask RCNN modules
52
  from mrcnn.config import Config
53
  import mrcnn.model as modellib
54
 
 
 
55
  app = FastAPI()
56
 
57
  # CORS Configuration
 
23
  sys.modules['keras.engine'] = KE
24
  sys.modules['keras.layers'] = keras.layers
25
  sys.modules['keras.models'] = keras.models
26
+
27
  from fastapi import FastAPI, File, UploadFile
28
  from fastapi.middleware.cors import CORSMiddleware
29
  from PIL import Image
 
48
  cache_dir=cache_dir
49
  )
50
 
51
+ model_path = "mrcnn/model.py"
52
+ with open(model_path, 'r') as f:
53
+ content = f.read()
54
+
55
+ # Fix the Reshape issue in fpn_classifier_graph
56
+ content = content.replace(
57
+ 'mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)',
58
+ 'mrcnn_bbox = KL.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)'
59
+ )
60
+
61
+ # Fix the Reshape issue in build_fpn_mask_graph
62
+ content = content.replace(
63
+ 'mrcnn_mask = KL.Reshape((s[1], s[2], s[3], num_classes), name="mrcnn_mask")(x)',
64
+ 'mrcnn_mask = KL.Reshape((-1, s[2], s[3], num_classes), name="mrcnn_mask")(x)'
65
+ )
66
+
67
+ with open(model_path, 'w') as f:
68
+ f.write(content)
69
+ print("Applied TF 1.15 patches to mrcnn/model.py")
70
+
71
  # Import Mask RCNN modules
72
  from mrcnn.config import Config
73
  import mrcnn.model as modellib
74
 
75
+ print("Collected all imports")
76
+
77
  app = FastAPI()
78
 
79
  # CORS Configuration