Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit b1121f4

Browse files
committed
Add method to evaluate model
1 parent 0a0d65a commit b1121f4

File tree

2 files changed

+109
-6
lines changed

2 files changed

+109
-6
lines changed

examples/Ship Detection.ipynb

+64-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 8,
13-
"metadata": {},
12+
"execution_count": 1,
13+
"metadata": {
14+
"collapsed": true
15+
},
1416
"outputs": [],
1517
"source": [
1618
"from rasterfoundry.api import API\n",
17-
"refresh_token = '<INSERT-TOKEN>'\n",
19+
"refresh_token = '<'\n",
1820
"api = API(refresh_token=refresh_token)"
1921
]
2022
},
@@ -520,6 +522,18 @@
520522
"# Raster Vision"
521523
]
522524
},
525+
{
526+
"cell_type": "code",
527+
"execution_count": 3,
528+
"metadata": {
529+
"collapsed": true
530+
},
531+
"outputs": [],
532+
"source": [
533+
"from rasterfoundry.utils import RasterVisionBatchClient\n",
534+
"rv_batch_client = RasterVisionBatchClient()"
535+
]
536+
},
523537
{
524538
"cell_type": "markdown",
525539
"metadata": {},
@@ -544,9 +558,6 @@
544558
}
545559
],
546560
"source": [
547-
"from rasterfoundry.utils import RasterVisionBatchClient\n",
548-
"rv_batch_client = RasterVisionBatchClient(branch_name='lf/filter')\n",
549-
"\n",
550561
"# A set of projects and corresponding annotation GeoJSON files.\n",
551562
"project_ids = [\n",
552563
" '357ddf1f-2e5e-4420-8e75-0eed12d2d20f',\n",
@@ -610,6 +621,53 @@
610621
" label_map_uri, predictions_uri)"
611622
]
612623
},
624+
{
625+
"cell_type": "markdown",
626+
"metadata": {
627+
"collapsed": true
628+
},
629+
"source": [
630+
"## Evaluating a model on a set of projects"
631+
]
632+
},
633+
{
634+
"cell_type": "code",
635+
"execution_count": 4,
636+
"metadata": {},
637+
"outputs": [
638+
{
639+
"data": {
640+
"text/plain": [
641+
"u'47caf222-729c-4351-85e3-9fe8e2edf1ed'"
642+
]
643+
},
644+
"execution_count": 4,
645+
"metadata": {},
646+
"output_type": "execute_result"
647+
}
648+
],
649+
"source": [
650+
"# A set of projects and corresponding annotation GeoJSON files.\n",
651+
"project_ids = [\n",
652+
" '357ddf1f-2e5e-4420-8e75-0eed12d2d20f',\n",
653+
" '1ab2734c-d2b1-4e0b-8c54-24f4f121c77b',\n",
654+
"]\n",
655+
"\n",
656+
"annotation_uris = [\n",
657+
" 's3://raster-vision-od/raw-data/annotations/jm-ships/2017-09-18-singapore-final.geojson',\n",
658+
" 's3://raster-vision-od/raw-data/annotations/jm-ships/2017-07-04-panama-final.geojson',\n",
659+
"]\n",
660+
"\n",
661+
"output_uri = 's3://raster-vision-od/evals/singapore-panama.json'\n",
662+
"label_map_uri = 's3://raster-vision-od/configs/label-maps/jm-ships-single-label.pbtxt'\n",
663+
"inference_graph_uri = 's3://raster-vision-od/trained-models/lhf-ships-neg0/inference_graph.pb'\n",
664+
"\n",
665+
"api.start_eval_model_job(\n",
666+
" rv_batch_client, inference_graph_uri,\n",
667+
" project_ids, annotation_uris, label_map_uri,\n",
668+
" output_uri)"
669+
]
670+
},
613671
{
614672
"cell_type": "code",
615673
"execution_count": null,

rasterfoundry/api.py

+45
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,48 @@ def start_prep_train_data_job(self, rv_batch_client, project_ids,
208208
job_name = 'prep_train_data_{}'.format(uuid.uuid1())
209209
job_id = rv_batch_client.start_raster_vision_job(job_name, command)
210210
return job_id
211+
212+
def start_eval_model_job(self, rv_batch_client, inference_graph_uri,
213+
project_ids, annotation_uris, label_map_uri,
214+
output_uri,
215+
proj_config_dir_uri=RV_PROJ_CONFIG_DIR_URI,
216+
channel_order=None):
217+
"""Start a Batch job to evaluate a model using a set of projects.
218+
219+
Args:
220+
rv_batch_client: a RasterVisionBatchClient object used to start
221+
Batch jobs
222+
project_ids (list of str): ids of projects to make train data for
223+
annotation_uris (list of str): annotation URIs for projects
224+
label_map_uri (str): URI of output label map
225+
output_uri (str): URI of output zip file
226+
proj_config_dir_uri (str): The root of generated URIs for config
227+
files
228+
channel_order: list of length 3 with GeoTIFF channel indices to
229+
map to RGB.
230+
231+
Returns:
232+
job_id (str): job_id of job started on Batch
233+
"""
234+
project_configs = self.get_project_configs(
235+
project_ids, annotation_uris)
236+
projects_uri = upload_raster_vision_config(
237+
project_configs, proj_config_dir_uri)
238+
239+
base_command = \
240+
'python -m rv.run eval_model --chip-size 300 '
241+
242+
channel_order_opt = ''
243+
if channel_order is not None:
244+
channel_order_str = ' '.join([
245+
str(channel_ind) for channel_ind in channel_order])
246+
channel_order_opt = ('--channel-order {} '
247+
.format(channel_order_str))
248+
249+
command = (base_command + channel_order_opt + '{} {} {} {}')
250+
command = command.format(inference_graph_uri, projects_uri,
251+
label_map_uri, output_uri)
252+
253+
job_name = 'eval_model_{}'.format(uuid.uuid1())
254+
job_id = rv_batch_client.start_raster_vision_job(job_name, command)
255+
return job_id

0 commit comments

Comments
 (0)