Giter VIP home page Giter VIP logo

Comments (1)

mvirgo avatar mvirgo commented on June 29, 2024

Actually will pass on this one - since KITTI doesn't release the ground truths of the test images (since you submit to them to get results), don't have a great measure there.

I did look into whether it was reasonable to just check that training accuracy is above a certain precision for non-road and recall for road (based on the rubric), but it seemed a bit silly since you could just overfit if you wanted.

Putting the related code here in case anyone ever wanted to add again later (there's also a way to do this in Tensorflow directly although a bit more of a pain):

### In main.py at the end of run() ###
# TODO: Test that at least 80% of the road is correctly labelled and no more than 20% of non-road pixels is labelled as road
tests.test_for_training_accuracy(sess, logits, image_input, os.path.join(data_dir, 'data_road/training'), image_shape, keep_prob)
### In project_tests.py ###
## Add below imports ##
import re
import statistics
import scipy.misc
from sklearn.metrics import confusion_matrix

## Add this as final test ##
@test_safe
def test_for_training_accuracy(sess, logits, image_pl, data_dir, image_shape, keep_prob):
    print("Checking that training accuracy meets minimum requirements.")
    print("Passing this test does not necessarily mean submission is passing,\n", 
          "as this is run on the training data and not on the test data. Test images\n", 
          "should be reviewed to see if they meet accuracy requirements.")
    road_right_places = []
    road_wrong_places = []
    
    label_paths = {
        re.sub(r'_(lane|road)_', '_', os.path.basename(path)): path
        for path in glob(os.path.join(data_dir, 'gt_image_2', '*_road_*.png'))}
    
    for image_file in glob(os.path.join(data_dir, 'image_2', '*.png')):
        gt_image_file = label_paths[os.path.basename(image_file)]

        image = scipy.misc.imresize(scipy.misc.imread(image_file), image_shape)
        gt_image = scipy.misc.imresize(scipy.misc.imread(gt_image_file), image_shape)
        
        background_color = np.array([255, 0, 0])
        gt_bg = np.all(gt_image == background_color, axis=2)
        gt_bg = gt_bg.reshape(*gt_bg.shape, 1)
        gt_image = np.concatenate((gt_bg, np.invert(gt_bg)), axis=2)

        im_softmax = sess.run(
            [tf.nn.softmax(logits)],
            {keep_prob: 1.0, image_pl: [image]})
        prediction = im_softmax[0].reshape(image_shape[0], image_shape[1], 2)

        prediction = np.argmax(prediction, axis=-1)

        gt_image = gt_image.astype(int)

        prediction = prediction.flatten()
        road = gt_image[:,:,1].flatten()

        # Need >80% recall for road and <20% false positives of road within non-road
        tn, fp, fn, tp = confusion_matrix(road, prediction).ravel()
        recall = tp / (tp + fn)
        road_wrong_place = fp / (fp + tn)
        
        road_right_places.append(recall)
        road_wrong_places.append(road_wrong_place)

    mean_road_right = statistics.mean(road_right_places)
    mean_road_wrong = statistics.mean(road_wrong_places)
    print("Road identified as road:", mean_road_right)
    print("Non-road identified as road:", mean_road_wrong)

    assert mean_road_right >= 0.8, 'Expected at least 80% recall for road, found {}.'.format(mean_road_right)
    assert mean_road_wrong <= 0.2, 'Expected less than 20% of non-road marked as road, found {}.'.format(mean_road_wrong)

from carnd-semantic-segmentation.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.