Keras_HED icon indicating copy to clipboard operation
Keras_HED copied to clipboard

How do i run this?

Open athiselvam opened this issue 7 years ago • 16 comments

What is the necessary configuration needed?

athiselvam avatar Nov 14 '17 13:11 athiselvam

Hi,friend!Have you solved the issue ?I also have no ideas how to run it.

JingangLang avatar Nov 20 '17 13:11 JingangLang

Download the repo. Add the path for the list file(list file space separated with img and gnd truth) and also the folder containing images in the file HED_data_parser.py.

  • Remove the pdb(python debugger) trace set in the main_segmentation.py file.
  • Run the file main_segmentation and it will start the training.

jaiprasadreddy avatar Dec 24 '17 09:12 jaiprasadreddy

To get the output for the Trained model. Try this code.

from future import print_function import os from src.utils.HED_data_parser import DataParser from src.networks.hed import hed from keras.utils import plot_model from keras import backend as K from keras import callbacks import numpy as np import glob from PIL import Image import cv2

test = glob.glob('images/*') if name == "main": #environment K.set_image_data_format('channels_last') K.image_data_format() os.environ["CUDA_VISIBLE_DEVICES"]= '0' if not os.path.isdir(model_dir): os.makedirs(model_dir)

# model
model = hed()
# plot_model(model, to_file=os.path.join(model_dir, 'model.pdf'), show_shapes=True)

# training
# call backs
model.load_weights('checkpoint.03-0.31.hdf5')
# train_history = model.predict()
for image in test:
    name = image.split('/')[-1]
    x_batch = []
    im = Image.open(image)
    im = im.resize((480,480))
    im = np.array(im, dtype=np.float32)
    im = im[..., ::-1]  # RGB 2 BGR
    R = im[..., 0].mean()
    G = im[..., 1].mean()
    B = im[..., 2].mean()
    im[..., 0] -= R
    im[..., 1] -= G
    im[..., 2] -= B
    x_batch.append(im)
    x_batch = np.array(x_batch, np.float32)
    prediction = model.predict(x_batch)
    mask = np.zeros_like(im[:,:,0])
    for i in xrange(len(prediction)):
        mask += np.reshape(prediction[i],(480,480))
    ret,mask = cv2.threshold(mask,np.mean(mask)+1.2*np.std(mask),255,cv2.THRESH_BINARY)
    cv2.imwrite("output/%s"%name,mask)

jaiprasadreddy avatar Dec 25 '17 19:12 jaiprasadreddy

Thank you very much!

JingangLang avatar Jan 02 '18 03:01 JingangLang

Is that working with your own images? @JingangLang @jaiprasadreddy

athiselvam avatar Jan 02 '18 04:01 athiselvam

yes.. The more simpler way can be

  • During training save the model to the json.
  • load model during inference or testing from json and predict it on image.

check this link - https://machinelearningmastery.com/save-load-keras-deep-learning-models/

jaiprasadreddy avatar Jan 02 '18 05:01 jaiprasadreddy

What kinf of files does it need to train this model? What Dataset is used on this implementation?

JuanuMusic avatar Mar 07 '18 17:03 JuanuMusic

You can find it in http://vcl.ucsd.edu/hed/HED-BSDS. @HarkDev

JackLongKing avatar Apr 05 '18 05:04 JackLongKing

@jaiprasadreddy

I have tried to reproduce the test code by making a new python file and putting it in the Keras-HED master folder named test file. After I run it, the code gets compiled but there is no output. What am I doing wrong?

Here's how I have used the code.

#from future import print_function import os from src.utils.HED_data_parser import DataParser from src.networks.hed import hed from keras.utils import plot_model from keras import backend as K from keras import callbacks import numpy as np import glob from PIL import Image import cv2

test = glob.glob('images/*') if name == "main": model_name = 'HEDSeg' model_dir = os.path.join('checkpoints', model_name) csv_fn = os.path.join(model_dir, 'train_log.csv') checkpoint_fn = os.path.join(model_dir, 'checkpoint.01-0.14.hdf5') K.set_image_data_format('channels_last') K.image_data_format() os.environ["CUDA_VISIBLE_DEVICES"]= '0' if not os.path.isdir(model_dir): os.makedirs(model_dir)

model

model = hed() plot_model(model, to_file=os.path.join(model_dir, 'model.pdf'), show_shapes=True)

training

call backs

model.load_weights('checkpoint.01-0.14.hdf5')

train_history = model.predict()

for image in test: name = image.split('/')[-1] x_batch = [] im = Image.open(image) im = im.resize((480,480)) im = np.array(im, dtype=np.float32) im = im[..., ::-1] # RGB 2 BGR R = im[..., 0].mean() G = im[..., 1].mean() B = im[..., 2].mean() im[..., 0] -= R im[..., 1] -= G im[..., 2] -= B x_batch.append(im) x_batch = np.array(x_batch, np.float32) prediction = model.predict(x_batch) mask = np.zeros_like(im[:,:,0]) for i in xrange(len(prediction)): mask += np.reshape(prediction[i],(480,480)) ret,mask = cv2.threshold(mask,np.mean(mask)+1.2*np.std(mask),255,cv2.THRESH_BINARY) cv2.imwrite("output/%s"%name,mask)

arnavpuri115 avatar Aug 13 '18 04:08 arnavpuri115

@arnavpuri115 I didn't understand your question. what exactly does it mean by not getting the output.?

jaiprasadreddy avatar Aug 18 '18 09:08 jaiprasadreddy

@arnavpuri115 I didn't understand your question. what exactly does it mean by not getting the output.?

there is no output PICS in the folder output/.

ChenCong7375 avatar Jan 03 '19 14:01 ChenCong7375

Hmmm... Where to get the training examples?

feiyangsuo avatar Sep 06 '19 12:09 feiyangsuo

How to delete pdb?

下载仓库。在文件HED_data_parser.py中添加列表文件的路径(列表文件空间用img和gnd true分隔),以及包含图像的文件夹。

  • 删除main_segmentation.py文件中的pdb(python调试器)跟踪集。
  • 运行文件main_segmentation,它将开始训练。

how to delete pdb?

sly522 avatar Nov 28 '19 10:11 sly522

Hi, where can I find the file "vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5" needed as starting weights for the training?

marza1993 avatar Oct 21 '21 17:10 marza1993

Hi, where can I find the file "vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5" needed as starting weights for the training?

@marza1993 You can download model assets from this release page - https://github.com/fchollet/deep-learning-models/releases/tag/v0.1

ravip18596 avatar Oct 23 '21 03:10 ravip18596

@ravip18596 Thank you!

marza1993 avatar Oct 25 '21 14:10 marza1993