SaniaE commited on
Commit
dcf7940
·
verified ·
1 Parent(s): e661641

fixed attribute error

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -25,7 +25,7 @@ snapshot_download(repo_id=REPO_ID, allow_patterns=["mrcnn/*"], local_dir=".", to
25
  patches.patch_model_file()
26
 
27
  import mrcnn.model as modellib
28
- from mrcnn.model import mold_image
29
  from model_utils import PredictionConfig, visualize_detections
30
 
31
  app = FastAPI()
@@ -108,7 +108,7 @@ async def explain_occlusion(file: UploadFile = File(...)):
108
 
109
  baseline_score = baseline_res['scores'][0]
110
 
111
- # FIX: Wrapped [image_rgb] list in np.array() to resolve AttributeError
112
  molded_base = mold_image(np.array([image_rgb]), config)
113
  molded_base = molded_base[0]
114
 
@@ -126,7 +126,6 @@ async def explain_occlusion(file: UploadFile = File(...)):
126
  y_end = min(y + patch_size, h)
127
  x_end = min(x + patch_size, w)
128
 
129
- # Modify the pre-molded matrix directly to skip color formatting logic entirely
130
  img_occ = molded_base.copy()
131
  img_occ[y:y_end, x:x_end, :] = gray_molded_value
132
 
@@ -141,13 +140,21 @@ async def explain_occlusion(file: UploadFile = File(...)):
141
  with graph.as_default():
142
  keras_model = model_eval.keras_model
143
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  for img in molded_patches:
145
  molded_images = np.expand_dims(img, axis=0)
146
 
147
- # Re-use Matterport's internal metadata tracking matrix elements
148
- image_metas = np.array([model_eval.get_anchors_image_meta(img.shape, image_rgb.shape, (0,0,h,w), 1.0, np.zeros(config.NUM_CLASSES))])
149
- anchors = model_eval.anchors
150
-
151
  # Truncated execution pass running purely up to the numerical layers (No mask processing overhead)
152
  detections, _, _, _, _, _, _ = keras_model.predict([molded_images, image_metas, anchors], verbose=0)
153
 
 
25
  patches.patch_model_file()
26
 
27
  import mrcnn.model as modellib
28
+ from mrcnn.model import mold_image, compose_image_meta # FIX: Importing compose_image_meta directly
29
  from model_utils import PredictionConfig, visualize_detections
30
 
31
  app = FastAPI()
 
108
 
109
  baseline_score = baseline_res['scores'][0]
110
 
111
+ # Pre-calculate Image Molding parameters once
112
  molded_base = mold_image(np.array([image_rgb]), config)
113
  molded_base = molded_base[0]
114
 
 
126
  y_end = min(y + patch_size, h)
127
  x_end = min(x + patch_size, w)
128
 
 
129
  img_occ = molded_base.copy()
130
  img_occ[y:y_end, x:x_end, :] = gray_molded_value
131
 
 
140
  with graph.as_default():
141
  keras_model = model_eval.keras_model
142
 
143
+ # Build standard image meta tracking sequence utilizing original module functions
144
+ meta = compose_image_meta(
145
+ image_id=0,
146
+ original_image_shape=image_rgb.shape,
147
+ image_shape=(h, w, 3),
148
+ window=(0, 0, h, w),
149
+ scale=1.0,
150
+ active_class_ids=np.ones(config.NUM_CLASSES, dtype=np.int32)
151
+ )
152
+ image_metas = np.array([meta])
153
+ anchors = model_eval.anchors
154
+
155
  for img in molded_patches:
156
  molded_images = np.expand_dims(img, axis=0)
157
 
 
 
 
 
158
  # Truncated execution pass running purely up to the numerical layers (No mask processing overhead)
159
  detections, _, _, _, _, _, _ = keras_model.predict([molded_images, image_metas, anchors], verbose=0)
160