훈련된 MaskRCNN을 이용해 예측 파이썬 치트코드

2) mask rcnn the real-infer

Mask RCNN 훈련된 모델로 예측

  • 현재 훈련된 모델이 저장되어 있다면, 이 모델로 실제 Segmentation을 예측하는 과정
In [1]:
import os 
import sys
import random
import math
import numpy as np
import cv2
import matplotlib.pyplot as plt
from tqdm import tqdm
import pandas as pd 
import glob
from sklearn.model_selection import KFold
from PIL import Image
import os.path
import glob

import skimage

from skimage import data, color
from skimage.transform import rescale, resize, downscale_local_mean

from mrcnn.config import Config
from mrcnn import utils
import mrcnn.model as modellib
from mrcnn import visualize
from mrcnn.model import log

import os
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

import tensorflow as tf

import traceback
Using TensorFlow backend.
In [ ]:
class ShapesConfig(Config):
    
    NAME = "shapes"

    GPU_COUNT = 1
    IMAGES_PER_GPU = 8

    NUM_CLASSES = 351  

    IMAGE_MIN_DIM = 256
    IMAGE_MAX_DIM = 256

    RPN_ANCHOR_SCALES = (8, 16, 32, 64, 128)  # anchor side in pixels

    TRAIN_ROIS_PER_IMAGE = 32

    STEPS_PER_EPOCH = 100

    VALIDATION_STEPS = 5
    
config = ShapesConfig()
config.display()
In [3]:
class InferenceConfig(ShapesConfig):
    GPU_COUNT = 1
    IMAGES_PER_GPU = 8

inference_config = InferenceConfig()

MODEL_DIR = os.path.join("./model/")

추론 모드로 모델 로드

  • 모델은 보통 훈련시 자동으로 epoch당 저장하게 되어있다.
In [ ]:
model_inference = modellib.MaskRCNN(mode="inference", 
                          config=inference_config,
                          model_dir=MODEL_DIR)
In [ ]:
model_inference.load_weights("./model/shapes20190914T2042/mask_rcnn_shapes_0002.h5", by_name=True)
In [6]:
tests = os.listdir('../test')
results = []

예측

  • 8개씩 나눠서 예측
  • list안에 8개씩 짝이 있어 나중에 flatten이 필요
In [ ]:
def get_image_array(num):
    return np.array(Image.open('../test/' + tests[num]))

for i in tqdm(range(0, 100000, 8)):
    
    t = [ get_image_array(i+j) for j in range(0,8) ]
    
    results.append(model_inference.detect(t, verbose = 1))
In [8]:
import pickle

저장

  • 결과 데이터를 저장해 competition용 submission파일로 저장
In [9]:
# write python dict to a file
output = open('result_002_head_weight.pkl', 'wb')
pickle.dump(results, output)
output.close()

14 thoughts on “훈련된 MaskRCNN을 이용해 예측 파이썬 치트코드

  1. Zithromax Sold Over Counter [url=https://cheapcialisir.com/]viagra cialis online[/url] Is 2 Yr Old Doxycycline Safe To Take ? Cialis Pflanzliches Viagra Horn

  2. Woah! I’m really enjoying the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between user
    friendliness and visual appearance. I must say that you’ve done a superb job
    with this. Also, the blog loads very fast for me on Safari.
    Superb Blog!

    Stop by my blog post; these g

  3. Hi! This is kind of off topic but I need some help from an established blog.

    Is it tough to set up your own blog? I’m not very techincal but I can figure
    things out pretty quick. I’m thinking about setting up my own but I’m not sure
    where to start. Do you have any tips or suggestions? Cheers

    My webpage :: with g

  4. Fantastic beat ! I wish to apprentice while you amend your web site, how could i subscribe for a blog
    site? The account helped me a acceptable deal. I had been tiny
    bit acquainted of this your broadcast offered bright clear concept

    Have a look at my blog post – man g

  5. I love your blog.. very nice colors & theme. Did you
    make this website yourself or did you hire someone
    to do it for you? Plz answer back as I’m looking to design my own blog and would like to find out
    where u got this from. many thanks

    Also visit my page rsacwgxy g

  6. Thanks for finally writing about > 훈련된 MaskRCNN을
    이용해 예측 파이썬 치트코드 – Go Lab < Liked it!

    Feel free to visit my web blog: cbd oil (tinyurl.com)

  7. Woah! I’m really digging the template/theme of this site.
    It’s simple, yet effective. A lot of times it’s very hard to get cbd oil that works 2020 “perfect balance” between superb usability and visual
    appeal. I must say you have done a very good job with this.
    Also, the blog loads super quick for me on Safari.
    Superb Blog!

  8. This is really interesting, You’re an excessively professional
    blogger. I’ve joined your feed and look forward to searching for more of your magnificent post.
    Also, I have shared your website in my social networks

    my web-site – cbd oil that works 2020

  9. Wow that was strange. I just wrote an really long comment but after I clicked submit my comment didn’t appear.
    Grrrr… well I’m not writing all cbd oil that works 2020 over again. Anyways, just wanted to say great blog!

  10. Знаете ли вы?
    Англичане купили заказанную португальцами рукопись голландца и бельгийца с изображениями монархов десяти королевств.
    Будущего чемпиона Европы по боксу в детстве одновременно дразнили «хохлом» и «москалём».
    Роден назвал свои «Врата ада» напрямую, а его соотечественник только намекнул.
    Команды тренера года АБА и НБА ни разу не стали в них финалистками.
    Иракский физрук получил мировую известность под псевдонимом «ангел смерти».

    [url=http://arbeca.net/]arbeca[/url]

댓글 남기기