def create_new_shrinking_factor_model(input_path, new_shrinking_factor, output_path):


    input_model = read_model(input_path)
    
    model_class = input_model.__class__    
    output_model = input_model

    if True:
        if model_class is MultiScalesDetectorModel:
            for detector in output_model.detectors:
                change_shrinking_factor(new_shrinking_factor, detector)
            
        elif model_class is DetectorModel:
            change_shrinking_factor(new_shrinking_factor, output_model)
            
        else:
            raise Exception("Received an unmanaged detector model class {0}".format(model_class) )


    #replace_scale_hack(output_model)

    output_content = output_model.SerializeToString()
    out_file = open(output_path, "wb")
    out_file.write(output_content)
    out_file.close()
    print("Created output model file", output_path)
    return
예제 #2
0
def generate_occlusionClassifier(input_model):
    width = 32
    half_width = 16

    model = read_model(input_model)
    for i in range(1 + half_width):
        yThresh = half_width - i
        new_model = DetectorModel()
        new_model.CopyFrom(model)
        if model.model_window_size:
            model_width = model.model_window_size.x
            model_height = model.model_window_size.y
        print("model.detector_type", model.detector_type)

        if model.detector_type == model.SoftCascadeOverIntegralChannels:
            old_cascade = model.soft_cascade_model
            new_cascade = new_model.soft_cascade_model
            print("Model has %i stages" % len(old_cascade.stages))
            update_cascade(old_cascade, new_cascade, width - yThresh)

            output_path = input_model + "_artificial_crop_" + str(yThresh * 4)

            out_file = open(output_path, "wb")
            out_file.write(new_model.SerializeToString())
            out_file.close()
            print("Create output model file", output_path)
def generate_occlusionClassifier(input_model):
    width = 32
    half_width = 16

    model=read_model(input_model)
    for i in range(1+half_width):
        yThresh = half_width-i
        new_model = DetectorModel()
        new_model.CopyFrom(model)
        if model.model_window_size:
            model_width = model.model_window_size.x
            model_height = model.model_window_size.y        
        print("model.detector_type", model.detector_type)

        if model.detector_type == model.SoftCascadeOverIntegralChannels:
            old_cascade = model.soft_cascade_model    
            new_cascade = new_model.soft_cascade_model    
            print("Model has %i stages" % len(old_cascade.stages))
            update_cascade(old_cascade, new_cascade, width-yThresh)



            output_path = input_model + "_artificial_crop_" + str(yThresh*4)
    

            out_file = open(output_path, "wb")
            out_file.write(new_model.SerializeToString())
            out_file.close()
            print("Create output model file", output_path)
def main():

    #options = parse_input_options()
    #model_filename = options.input_path

    boosted_model_path = "../../src/applications/boosted_learning/2012_04_16_74669_full_size_model_non_recursive_seed_22222_push_up_0.05.bootstrap2crop_32"
    svm_model_path = "../../libs/liblinear-1.8/tmp.model"
    output_boosted_model_path = "test_model_c0.001_e0.001_dataBalanced.out.proto.bin"

    assert boosted_model_path != output_boosted_model_path

    print("Reading boosted model", boosted_model_path)
    model = read_model(boosted_model_path)
    print("Reading svm model", svm_model_path)
    w_vector = get_svm_model_w_vector(open(svm_model_path, "r"))

    if type(model) is detector_model_pb2.DetectorModel:
        print("Cutting model...")
        cut_model(model, len(w_vector))

        print("Saving cut model at", output_boosted_model_path + ".cut")
        out_file = open(output_boosted_model_path + ".cut", "wb")
        out_file.write(model.SerializeToString())
        out_file.close()

        print("Adjusting weights model...")
        adjust_weights(model, w_vector)

        print("Saving result model at", output_boosted_model_path)
        out_file = open(output_boosted_model_path, "wb")
        out_file.write(model.SerializeToString())
        out_file.close()

        output_boosted_model_path
        print("Created output model file", output_boosted_model_path)

    else:
        raise Exception("No model type other than DetectorModel is supported. "
                        "Received %s" % type(model))

    pylab.show()  # blocking call
    return
def main():

    #options = parse_input_options()
    #model_filename = options.input_path

    boosted_model_path = "../../src/applications/boosted_learning/2012_04_16_74669_full_size_model_non_recursive_seed_22222_push_up_0.05.bootstrap2crop_32"
    svm_model_path = "../../libs/liblinear-1.8/tmp.model"
    output_boosted_model_path = "test_model_c0.001_e0.001_dataBalanced.out.proto.bin"
    
    assert boosted_model_path != output_boosted_model_path
    
    print("Reading boosted model", boosted_model_path)
    model = read_model(boosted_model_path)
    print("Reading svm model", svm_model_path)    
    w_vector = get_svm_model_w_vector(open(svm_model_path, "r"))
    
    if type(model) is detector_model_pb2.DetectorModel:
	print("Cutting model...")
        cut_model(model, len(w_vector))

	print("Saving cut model at", output_boosted_model_path + ".cut")
        out_file = open(output_boosted_model_path + ".cut", "wb")
        out_file.write(model.SerializeToString())
        out_file.close()

        print("Adjusting weights model...")
        adjust_weights(model, w_vector)
        
	print("Saving result model at", output_boosted_model_path)
        out_file = open(output_boosted_model_path, "wb")
        out_file.write(model.SerializeToString())
        out_file.close()

	output_boosted_model_path
        print("Created output model file", output_boosted_model_path)

    else: 
        raise Exception("No model type other than DetectorModel is supported. "
                        "Received %s" % type(model) )

    pylab.show() # blocking call
    return
def replace_scale_hack(model):
    """
    Small hack to replace a model of a given scale
    """
    assert isinstance(model, MultiScalesDetectorModel)

    model_path = "/users/visics/mmathias/devel/doppia/src/applications/boosted_learning/eccvWorkshop/2012_05_20_67022_trained_model_octave_-1.proto.bin.bootstrap2"
    replacement_model = read_model(model_path)
    assert isinstance(replacement_model, DetectorModel)
    replacement_scale = 0.5
   
    print("Replacing model of scale {0} " \
          "by the model read at {1}".format(replacement_scale, model_path))    
    
    for detector in model.detectors:
        if detector.scale == replacement_scale:
            detector.CopyFrom(replacement_model)
            detector.scale = replacement_scale # we set the proper new scale
            break
    
    return
        if not is_the_same:
            print("A"); read_tree(a[0], a[1])
            print("B"); read_tree(a[0], a[1])
            print("Found two different stages after %i comparisons" % counter)
            differences += 1
        if differences > 5:
            raise Exception("To many differences, the two models are not identical")

# end of compare_detectors

print("Reading the two models; please wait...")

#model_a_path = "../../src/applications/boosted_learning/2011_10_12_64789_trained_model_octave_0.proto.softcascade.bin"
#model_b_path = "../../src/applications/boosted_learning/2011_11_04_61124_2011_10_12_64789_trained_model_octave_0.proto.softcascade.softcascade.bin"

model_a_path = "/users/visics/rbenenso/code/europa/code/kul-rwth/objects_detection_lib/2012_04_04_1417_trained_model_multiscales_synthetic_softcascade.proto.bin"
model_b_path = "2012_04_04_1417_trained_model_multiscales_synthetic_softcascade.shrinking_factor_2_back_to_4.proto.bin"

model_a = read_model(model_a_path)
model_b = read_model(model_b_path)

if isinstance(model_a, detector_model_pb2.MultiScalesDetectorModel):
    assert isinstance(model_b, detector_model_pb2.MultiScalesDetectorModel)
    for i in range(len(model_a.detectors)):
        detector_a = model_a.detectors[i]
        detector_b = model_b.detectors[i]
        compare_detectors(detector_a, detector_b)
else:
    compare_detectors(model_a, model_b)

print("End of game, have a nice day !")
예제 #8
0
            read_tree(a[0], a[1])
            print("Found two different stages after %i comparisons" % counter)
            differences += 1
        if differences > 5:
            raise Exception(
                "To many differences, the two models are not identical")


# end of compare_detectors

print("Reading the two models; please wait...")

#model_a_path = "../../src/applications/boosted_learning/2011_10_12_64789_trained_model_octave_0.proto.softcascade.bin"
#model_b_path = "../../src/applications/boosted_learning/2011_11_04_61124_2011_10_12_64789_trained_model_octave_0.proto.softcascade.softcascade.bin"

model_a_path = "/users/visics/rbenenso/code/europa/code/kul-rwth/objects_detection_lib/2012_04_04_1417_trained_model_multiscales_synthetic_softcascade.proto.bin"
model_b_path = "2012_04_04_1417_trained_model_multiscales_synthetic_softcascade.shrinking_factor_2_back_to_4.proto.bin"

model_a = read_model(model_a_path)
model_b = read_model(model_b_path)

if isinstance(model_a, detector_model_pb2.MultiScalesDetectorModel):
    assert isinstance(model_b, detector_model_pb2.MultiScalesDetectorModel)
    for i in range(len(model_a.detectors)):
        detector_a = model_a.detectors[i]
        detector_b = model_b.detectors[i]
        compare_detectors(detector_a, detector_b)
else:
    compare_detectors(model_a, model_b)

print("End of game, have a nice day !")