ibrahimgh25 / EL-GAN-Implementation

A pytorch implementation for the network in "EL-GAN: Embedding Loss Driven Generative Adversarial Networks for Lane Detection" by Ghafoorian et al.
MIT License
3 stars 0 forks source link

how to test? #2

Open samsunq opened 1 year ago

samsunq commented 1 year ago

hi, could u tell me how to test it? I don't find a test file after i trained the model. so I should use which files to test the lane image? thanks a lot, and waiting ur answer.

ibrahimgh25 commented 1 year ago

Hello,

If you mean get the evaluation results on a separate set after training, you'll have to split your training data into three sets (the code in this repo assumes the data is split into training and validation only). If you split your data set correctly and have a separate set for testing, you can use that for the evaluation. The code for evaluation should be very similar to the one for validation (you can find it in elgan_training.py). But I don't have a script for testing in the repository.

If you mean actually visualizing the results of the model, I found this code in an old notebook I used, something like this should work:

import _pickle as pickle
from google.colab.patches import cv2_imshow

def show_img(model_output):
    img = model_output.detach().cpu().numpy()[0]
    img = img.reshape(img.shape[1], img.shape[2], img.shape[0])
    cv2_imshow(img * 255)

with torch.no_grad(), open('generator_check_point_path', 'rb') as f:
    gen = pickle.load(f)
    gen_output = gen(inputs.to(device).float())

show_img(gen_output)

Please note that at the time, I used cpickle (_pickle) instead of the regular pickle, because I thought it's faster for loading and saving the model. Also, for "inputs" you'll have to get from a pytorch dataloader, or process the image the same way as in the dataset implementation, the code should like this:

from torch.utils.data import DataLoader
test_set = LaneDataSet('path/to/testing_set_labels.json', 'testing/set/dir')
test_gen_loader = DataLoader(test_set, batch_size=1)

LanDataSet is implemented in the 'training_utils' directory.

P.s: this code I worked on years ago, it's a little "shaky", but at the time I loved to comment a lot, so at least you can use that to try and know what I was thinking. Also, I haven't trained a model properly, so the parameters aren't fine-tuned. I haven't tried any of the scripts I gave you, I just wrote what I think is a good starting point.

Regards, Ibrahim

samsunq commented 1 year ago

thanks a lot~