matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.68k stars 11.7k forks source link

Demo.ipynb not working : *** No instances to display *** #942

Open tobymu opened 6 years ago

tobymu commented 6 years ago

@waleedka Hello, I use tensorflow1.9 + python3.5

When I run the demo, it shows "No instances to display"

import os
import sys
import random
import math
import numpy as np
import skimage.io
import matplotlib
import matplotlib.pyplot as plt

# Root directory of the project
ROOT_DIR = os.path.abspath("..")
print("ROOT_DIR:", ROOT_DIR)

# Import Mask RCNN
sys.path.append(ROOT_DIR)  # To find local version of the library
from mrcnn import utils
import mrcnn.model as modellib
from mrcnn import visualize
# Import COCO config
sys.path.append(os.path.join(ROOT_DIR, "samples/coco/"))  # To find local version
import coco

# %matplotlib inline 

# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs")

# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")
print("COCO_MODEL_PATH", COCO_MODEL_PATH)
# Download COCO trained weights from Releases if needed
if not os.path.exists(COCO_MODEL_PATH):
    utils.download_trained_weights(COCO_MODEL_PATH)

# Directory of images to run detection on
IMAGE_DIR = os.path.join(ROOT_DIR, "images")
print("IMAGE_DIR", IMAGE_DIR)

class InferenceConfig(coco.CocoConfig):
    # Set batch size to 1 since we'll be running inference on
    # one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1

config = InferenceConfig()
config.display()

# Create model object in inference mode.
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)

# Load weights trained on MS-COCO
model.load_weights(COCO_MODEL_PATH, by_name=True)

# COCO Class names
# Index of the class in the list is its ID. For example, to get ID of
# the teddy bear class, use: class_names.index('teddy bear')
class_names = ['BG', 'person', 'bicycle', 'car', 'motorcycle', 'airplane',
               'bus', 'train', 'truck', 'boat', 'traffic light',
               'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird',
               'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear',
               'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie',
               'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball',
               'kite', 'baseball bat', 'baseball glove', 'skateboard',
               'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup',
               'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
               'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza',
               'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed',
               'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote',
               'keyboard', 'cell phone', 'microwave', 'oven', 'toaster',
               'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors',
               'teddy bear', 'hair drier', 'toothbrush']

# Load a random image from the images folder
file_names = next(os.walk(IMAGE_DIR))[2]
print(file_names)
image = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))

# Run detection
results = model.detect([image], verbose=1)

# Visualize results
r = results[0]
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], 
                            class_names, r['scores'])

I don't know why. Thanks for help!

tobymu commented 6 years ago

(tensorflow_py3.5_tf1.9) aita@aita:~/AITA2/01Visual/19FaceID/chenyiyi/Mask_RCNN-master/mask_rcnn_example_demo$ python demo.py ROOT_DIR: /home/aita/AITA2/01Visual/19FaceID/chenyiyi/Mask_RCNN-master Using TensorFlow backend. COCO_MODEL_PATH /home/aita/AITA2/01Visual/19FaceID/chenyiyi/Mask_RCNN-master/mask_rcnn_coco.h5 IMAGE_DIR /home/aita/AITA2/01Visual/19FaceID/chenyiyi/Mask_RCNN-master/images 2018-09-17 20:48:30.754146: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2018-09-17 20:48:30.930634: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties: name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.7335 pciBusID: 0000:03:00.0 totalMemory: 7.92GiB freeMemory: 7.58GiB 2018-09-17 20:48:30.930680: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0 2018-09-17 20:48:31.132087: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-09-17 20:48:31.132120: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958] 0 2018-09-17 20:48:31.132126: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0: N 2018-09-17 20:48:31.132332: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7317 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080, pci bus id: 0000:03:00.0, compute capability: 6.1) ['8829708882_48f263491e_z.jpg', '3132016470_c27baa00e8_z.jpg', '2516944023_d00345997d_z.jpg', '8433365521_9252889f9a_z.jpg', '8053677163_d4c8f416be_z.jpg', '6821351586_59aa0dc110_z.jpg', '1045023827_4ec3e8ba5c_z.jpg', '25691390_f9944f61b5_z.jpg', '3878153025_8fde829928_z.jpg', '3651581213_f81963d1dd_z.jpg', '6584515005_fce9cec486_z.jpg', '8699757338_c3941051b6_z.jpg', '9118579087_f9ffa19e63_z.jpg', '8734543718_37f6b8bd45_z.jpg', '3800883468_12af3c0b50_z.jpg', '3862500489_6fd195d183_z.jpg', '262985539_1709e54576_z.jpg', '7933423348_c30bd9bd4e_z.jpg', '7581246086_cf7bbb7255_z.jpg', '3627527276_6fe8cd9bfe_z.jpg', '4782628554_668bc31826_z.jpg', '8512296263_5fc5458e20_z.jpg', '9247489789_132c0d534a_z.jpg', '5951960966_d4e1cda5d0_z.jpg', '2502287818_41e4b0c4fb_z.jpg', '12283150_12d37e6389_z.jpg', '4410436637_7b0ca36ee7_z.jpg', '2383514521_1fc8d7b0de_z.jpg', '8239308689_efa6c11b08_z.jpg'] Processing 1 images image shape: (491, 640, 3) min: 0.00000 max: 255.00000 uint8 molded_images shape: (1, 1024, 1024, 3) min: -123.70000 max: 151.10000 float64 image_metas shape: (1, 93) min: 0.00000 max: 1024.00000 float64 anchors shape: (1, 261888, 4) min: -0.35390 max: 1.29134 float32 No instances to display

tabelh commented 5 years ago

Any news on this subject, running in to the same problem. In my case it is caused by a divide by zero in model.py, 2456: boxes = np.divide(boxes - shift, scale) using tensorflow 1.13 python 2.7 running demo.ipynb in jupyter.

musematics commented 5 years ago

Any news on this subject, running in to the same problem. In my case it is caused by a divide by zero in model.py, 2456: boxes = np.divide(boxes - shift, scale) using tensorflow 1.13 python 2.7 running demo.ipynb in jupyter.

@tabelh @tobymu I encountered exactly the same problem here. Any solution? Thanks al lot!

tabelh commented 5 years ago

Any news on this subject, running in to the same problem. In my case it is caused by a divide by zero in model.py, 2456: boxes = np.divide(boxes - shift, scale) using tensorflow 1.13 python 2.7 running demo.ipynb in jupyter.

@tabelh @tobymu I encountered exactly the same problem here. Any solution? Thanks al lot!

I think it has something to do with the interpreter of python2.7 that does not allow simple training. I ended up simply running the code in a python3 virtualenvironment to do my training. The weight file can then be used for inference with python2 without issues, at least i haven't found them.

musematics commented 5 years ago

Any news on this subject, running in to the same problem. In my case it is caused by a divide by zero in model.py, 2456: boxes = np.divide(boxes - shift, scale) using tensorflow 1.13 python 2.7 running demo.ipynb in jupyter.

@tabelh @tobymu I encountered exactly the same problem here. Any solution? Thanks al lot!

I think it has something to do with the interpreter of python2.7 that does not allow simple training. I ended up simply running the code in a python3 virtualenvironment to do my training. The weight file can then be used for inference with python2 without issues, at least i haven't found them.

@tabelh Thank you very much! I've just found 'Working with py2 #515. A modification with model.py and visualize.py might also solve this problem.