Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
atlasui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
INM-1
BDA
software
analysis
atlas
atlasui
Commits
0e86b77a
Commit
0e86b77a
authored
3 years ago
by
Schiffer, Christian
Browse files
Options
Downloads
Patches
Plain Diff
Implemented some functions to retrieve prediction annotations
parent
a76d7def
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
atlas_controller/atlas_controller/app.py
+27
-11
27 additions, 11 deletions
atlas_controller/atlas_controller/app.py
atlas_server/src/app.py
+30
-5
30 additions, 5 deletions
atlas_server/src/app.py
with
57 additions
and
16 deletions
atlas_controller/atlas_controller/app.py
+
27
−
11
View file @
0e86b77a
...
...
@@ -3,7 +3,7 @@ import os
import
base64
from
subprocess
import
CalledProcessError
from
flask
import
Flask
from
flask
import
Flask
,
request
from
flask_restx
import
Api
,
Resource
,
fields
,
abort
from
models
import
JobSchema
...
...
@@ -187,6 +187,7 @@ class Predictions(Resource):
import
os
import
glob
import
h5py
import
json
work_dir
=
"
/
"
.
join
([
WORK_DIR_ROOT
,
work_dir
])
if
not
os
.
path
.
exists
(
work_dir
):
...
...
@@ -198,17 +199,32 @@ class Predictions(Resource):
abort
(
404
,
f
"
Could not find prediction directory
{
prediction_dir
}
"
)
return
# If this is True, return annotations instead of information on the files
annotations
=
request
.
args
.
get
(
"
annotations
"
,
""
).
lower
()
in
(
"
true
"
,
)
results
=
[]
prediction_files
=
glob
.
glob
(
os
.
path
.
join
(
prediction_dir
,
"
*.hdf5
"
))
for
prediction_file
in
prediction_files
:
with
h5py
.
File
(
prediction_file
,
"
r
"
)
as
f
:
hw
=
f
[
"
pyramid/00
"
].
shape
[:
2
]
results
.
append
(
{
"
path
"
:
prediction_file
.
replace
(
WORK_DIR_ROOT
,
""
),
"
shape
"
:
hw
,
}
)
if
annotations
:
# Search for annotation files
prediction_files
=
glob
.
glob
(
os
.
path
.
join
(
prediction_dir
,
"
.coordinates.json
"
))
for
prediction_file
in
prediction_files
:
with
open
(
prediction_file
,
"
r
"
)
as
f
:
prediction_files
.
append
(
{
"
path
"
:
prediction_file
.
replace
(
WORK_DIR_ROOT
,
""
),
"
annotations
"
:
json
.
load
(
f
)
})
else
:
# Search for prediction files
prediction_files
=
glob
.
glob
(
os
.
path
.
join
(
prediction_dir
,
"
*.hdf5
"
))
for
prediction_file
in
prediction_files
:
with
h5py
.
File
(
prediction_file
,
"
r
"
)
as
f
:
hw
=
f
[
"
pyramid/00
"
].
shape
[:
2
]
results
.
append
(
{
"
path
"
:
prediction_file
.
replace
(
WORK_DIR_ROOT
,
""
),
"
shape
"
:
hw
,
}
)
return
results
...
...
This diff is collapsed.
Click to expand it.
atlas_server/src/app.py
+
30
−
5
View file @
0e86b77a
...
...
@@ -317,7 +317,7 @@ class TaskJob(Resource):
except
JobStatusNotFoundError
:
# If the job status could not be found, it could mean the job has finished to long ago
result
[
"
status
"
]
=
f
"
Could not determine job status for job with id
{
job_id
}
.
"
\
f
"
This could mean that the job does not exist or finished too long ago.
"
f
"
This could mean that the job does not exist or finished too long ago.
"
return
result
...
...
@@ -368,15 +368,15 @@ class TaskTileServerConfig(Resource):
with
Database
()
as
db
:
project
=
db
.
get_project_by_id
(
project_id
=
project_id
)
except
ProjectNotFoundError
:
abort
(
404
,
f
"
No project found for id
{
project_id
}
"
)
return
abort
(
404
,
f
"
No project found for id
{
project_id
}
"
)
return
try
:
with
Database
()
as
db
:
task
=
db
.
get_task_by_id
(
project_id
=
project_id
,
task_id
=
task_id
)
except
ProjectNotFoundError
:
abort
(
404
,
f
"
No task found for id
{
task_id
}
"
)
return
abort
(
404
,
f
"
No task found for id
{
task_id
}
"
)
return
# Determine
work_dir
=
f
"
atlas_ui_project
{
project_id
}
_task
{
task_id
}
"
...
...
@@ -517,6 +517,31 @@ class AnnotationImportExport(Resource):
"
status
"
:
"
ok
"
,
}
@annotation_namespace.route
(
"
/<int:project_id>/tasks/<int:task_id>
"
)
class
PredictionAnnotationExport
(
Resource
):
@annotation_namespace.doc
(
"
Retrieve annotations based on predictions of a specific task
"
)
def
get
(
self
,
project_id
,
task_id
):
import
requests
from
.config
import
ATLAS_CONTROLLER_URL
# Determine
work_dir
=
f
"
atlas_ui_project
{
project_id
}
_task
{
task_id
}
"
# Query predictions
result
=
requests
.
get
(
url
=
f
"
{
ATLAS_CONTROLLER_URL
}
/predictions/
{
work_dir
}
?annotations=true
"
)
if
result
.
status_code
>=
400
:
abort
(
404
,
f
"
Failed to find predictions
"
)
return
result
=
result
.
json
()
return
{
"
project_id
"
:
project_id
,
"
task_id
"
:
task_id
,
"
path
"
:
result
[
"
path
"
],
"
annotations
"
:
result
[
"
annotations
"
],
}
# -----------------------------------
# Main entry point
# -----------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment