ICNet-tensorflow icon indicating copy to clipboard operation
ICNet-tensorflow copied to clipboard

Request for demo.ipynb

Open david-bernstein opened this issue 7 years ago • 6 comments

Could you include a cell that shows how to use a checkpoint created by train.py for inference?

david-bernstein avatar Oct 17 '18 23:10 david-bernstein

@david-bernstein ,

I will update demo.ipynb in recent weeks. Thank you for your advice!

hellochick avatar Oct 22 '18 11:10 hellochick

Thanks!

david-bernstein avatar Oct 22 '18 17:10 david-bernstein

@david-bernstein

You may refer my modify --- a/network.py +++ b/network.py @@ -76,8 +76,13 @@ class Network(object): if data_path.endswith('.npy'): self.load_npy(data_path, self.sess) else:

  •        loader = tf.train.Saver(var_list=tf.global_variables())
    
  •        loader.restore(self.sess, data_path)
    
  • loader = tf.train.Saver(var_list=tf.global_variables())

  • loader.restore(self.sess, data_path)

  •          ckpt = tf.train.get_checkpoint_state(data_path)
    
  •          print("ckpt: ", ckpt)
    
  •          if ckpt and ckpt.model_checkpoint_path:
    
  •              loader = tf.train.Saver(var_list=tf.global_variables())
    
  •              loader.restore(self.sess, ckpt.all_model_checkpoint_paths[3])
    

liwedol avatar Oct 24 '18 05:10 liwedol

hi, i use this demo.py modified by the demo.ipynb, it can run and return teh result ,but the result is all wrong。

the code is:

#!/usr/bin/env python

-- coding: utf-8 --

import argparse import tensorflow as tf import numpy as np import cv2 import time import matplotlib.pyplot as plt

from tqdm import trange from utils.config import Config from model import ICNet, ICNet_BN

########【1】Setup configurations model_config = {'train': ICNet, 'trainval': ICNet, 'train_bn': ICNet_BN, 'trainval_bn': ICNet_BN, 'others': ICNet_BN}

dataset = 'others' filter_scale = 1

class InferenceConfig(Config): def init(self, dataset, is_training, filter_scale): Config.init(self, dataset, is_training, filter_scale)

model_type = 'others'
model_weight = '/disk3t-2/zym/tensorflow-ICNet/snapshots/model.ckpt-23000'

INFER_SIZE = (512, 512, 3)
              

cfg = InferenceConfig(dataset, is_training=False, filter_scale=filter_scale) cfg.display()

########【2】Create graph, session, and restore weights

Create graph here

model = model_config[cfg.model_type] net = model(cfg=cfg, mode='inference')

Create session & restore weight!

net.create_session() net.restore(cfg.model_weight)

########【3】Run segmentation on single image im1 = cv2.imread('./data/input/4.jpg')

if im1.shape != cfg.INFER_SIZE: im1 = cv2.resize(im1, (cfg.INFER_SIZE[1], cfg.INFER_SIZE[0]))

results1 = net.predict(im1) overlap_results1 = 0.5 * im1 + 0.5 * results1[0] vis_im1 = np.concatenate([im1/255.0, results1[0]/255.0, overlap_results1/255.0], axis=1)

plt.figure(figsize=(20, 15))

#######【4】Test inference speed elapsed_times = []

for i in range(50): start_t = time.time()

_ = net.predict(im1)

duration = time.time() - start_t

if i > 0:
    elapsed_times.append(duration)

print('Average time: {:.4f}, about {:.6f} fps'.format(np.mean(elapsed_times), 1/np.mean(elapsed_times)))

zhangyunming avatar Nov 09 '18 06:11 zhangyunming

Hi,@zhangyunming. I have the same problem with you. Have you dealed with it?

zaibian avatar Nov 23 '18 02:11 zaibian

Hi,@zhangyunming. I have the same problem with you. Have you dealed with it?

RobinHan24 avatar Jan 21 '19 02:01 RobinHan24