forked from hotosm/fAIr-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ramp.py
84 lines (69 loc) · 1.88 KB
/
test_ramp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# %%
# Standard library imports
import os
import time
# Third party imports
import tensorflow as tf
print(
f"\nUsing tensorflow version {tf. __version__} with no of gpu : {len(tf.config.experimental.list_physical_devices('GPU'))}\n"
)
print(os.getcwd())
os.environ.update(os.environ)
# Add a new environment variable to the operating system
os.environ["RAMP_HOME"] = os.getcwd()
# Print the environment variables to verify that the new variable was added
print(os.environ["RAMP_HOME"])
start_time = time.time()
# Third party imports
# %%
# import ramp.utils
# Reader imports
import hot_fair_utilities
base_path = f"{os.getcwd()}/ramp-data/sample_2"
# Reader imports
# %%
from hot_fair_utilities import preprocess
model_input_image_path = f"{base_path}/input"
preprocess_output = f"/{base_path}/preprocessed"
preprocess(
input_path=model_input_image_path,
output_path=preprocess_output,
rasterize=True,
rasterize_options=["binary"],
georeference_images=True,
multimasks=True,
)
# Reader imports
# %%
from hot_fair_utilities.training.ramp import train
# %%
train_output = f"{base_path}/train"
final_accuracy, final_model_path = train(
input_path=preprocess_output,
output_path=train_output,
epoch_size=2,
batch_size=2,
model="ramp",
model_home=os.environ["RAMP_HOME"],
)
# %%
print(final_accuracy, final_model_path)
# Reader imports
# %%
from hot_fair_utilities import predict
prediction_output = f"{base_path}/prediction/output"
predict(
checkpoint_path=final_model_path,
input_path=f"{base_path}/prediction/input",
prediction_path=prediction_output,
)
# Reader imports
# %%
from hot_fair_utilities import polygonize
geojson_output = f"{prediction_output}/prediction.geojson"
polygonize(
input_path=prediction_output,
output_path=geojson_output,
remove_inputs=True,
)
print(f"\n Total Process Completed in : {time.time()-start_time} sec")