Beispiel #1
0
def mod(tmpdir):
    mod = AttentionModel(config="conf/tree_config.yml")   
    mod.sites = 2
    mod.domains = 2    
    mod.RGB_channels = 3
    mod.HSI_channels = 3
    
    train_dir = tmpdir.mkdir("train")
    
    label_file = "{}/label_file.csv".format(train_dir)
    
    mod.config["train"]["tfrecords"] = train_dir
    mod.classes_file = "data/processed/species_class_labels.csv"
    
    domain = "D17"
    numeric_domain = domain_label_dict[domain]   

    site = "BART"    
    numeric_site = site_label_dict[site]
    
    created_records = mod.generate(shapefile=test_predictions, site=numeric_site, domain=numeric_domain, elevation=100/1000,
                                   HSI_sensor_path=test_sensor_tile,
                                   RGB_sensor_path=test_sensor_tile,
                                   train=True,
                                   chunk_size=2,
                                   savedir = mod.config["train"]["tfrecords"])
    
    #create a fake label file
    pd.DataFrame({"taxonID":["Ben","Jon"],"label":[0,1]}).to_csv(label_file)
    mod.classes_file = label_file
    
    mod.create()
    mod.ensemble(experiment=None)
        
    return mod
Beispiel #2
0
def mod(tmpdir):
    mod = AttentionModel(config="conf/tree_config.yml")
    mod.sites = 2
    mod.domains = 2
    mod.RGB_channels = 3
    mod.HSI_channels = 3

    train_dir = tmpdir.mkdir("train")

    label_file = "{}/label_file.csv".format(train_dir)

    shp = gpd.read_file(test_predictions)
    mod.config["train"]["tfrecords"] = train_dir
    mod.classes_file = "data/processed/species_class_labels.csv"
    created_records = mod.generate(shapefile=test_predictions,
                                   site=0,
                                   domain=1,
                                   elevation=100,
                                   heights=np.random.random(shp.shape[0]),
                                   HSI_sensor_path=test_sensor_tile,
                                   RGB_sensor_path=test_sensor_tile,
                                   train=True,
                                   chunk_size=2)

    #create a fake label file
    pd.DataFrame({
        "taxonID": ["Ben", "Jon"],
        "label": [0, 1]
    }).to_csv(label_file)
    mod.classes_file = label_file

    mod.create()
    mod.ensemble(experiment=None, train=False)

    #turn ensemble model into a feature extractor of the 2nd to last layer.
    mod.ensemble_model = tfk.Model(
        mod.ensemble_model.inputs,
        mod.ensemble_model.get_layer("submodel_concat").output)

    return mod
def mod(tmpdir):
    mod = AttentionModel(config="conf/tree_config.yml")

    train_dir = tmpdir.mkdir("train")
    predict_dir = tmpdir.mkdir("predict")
    label_file = "{}/label_file.csv".format(train_dir)

    #create a fake label file
    pd.DataFrame({
        "taxonID": ["Ben", "Jon"],
        "label": [0, 1]
    }).to_csv(label_file)

    config = {}
    train_config = {}
    train_config["tfrecords"] = train_dir
    train_config["batch_size"] = 1
    train_config["epochs"] = 1
    train_config["steps"] = 1
    train_config["gpus"] = 1
    train_config["crop_size"] = 20
    train_config["shuffle"] = True
    train_config["weighted_sum"] = False
    train_config["classes"] = 2
    train_config["species_class_file"] = label_file

    #evaluation
    eval_config = {}
    eval_config["tfrecords"] = None
    eval_config["steps"] = 1
    eval_config["ground_truth_path"] = "data/processed/test.shp"

    predict_config = {}
    predict_config["tfrecords"] = predict_dir

    config["train"] = train_config
    config["evaluation"] = eval_config
    config["predict"] = predict_config

    #Replace config for testing env
    for key, value in config.items():
        for nested_key, nested_value in value.items():
            mod.config[key][nested_key] = nested_value

    #Update the inits
    mod.RGB_size = mod.config["train"]["RGB"]["crop_size"]
    mod.HSI_size = mod.config["train"]["HSI"]["crop_size"]
    mod.HSI_channels = 369
    mod.RGB_channels = 3
    mod.extend_HSI_box = mod.config["train"]["HSI"]["extend_box"]
    mod.classes_file = label_file
    mod.train_shp = pd.DataFrame({
        "taxonID": ["Jon", "Ben"],
        "siteID": [0, 1],
        "domainID": [0, 1],
        "plotID": [0, 1],
        "canopyPosition": ["a", "b"],
        "scientific": ["genus species", "genus species"]
    })
    mod.train_shp.index = [2, 7]
    mod.sites = 23
    mod.domains = 15

    #Create a model with input sizes
    mod.create()

    return mod