Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sparse_coding_torch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teachable AI Lab
sparse_coding_torch
Commits
2ae88a8e
Commit
2ae88a8e
authored
3 years ago
by
hannandarryl
Browse files
Options
Downloads
Patches
Plain Diff
first fully functioning surface model
parent
41996eae
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/run_on_single_image.py
+36
-11
36 additions, 11 deletions
scripts/run_on_single_image.py
yolov4
+1
-0
1 addition, 0 deletions
yolov4
with
37 additions
and
11 deletions
scripts/run_on_single_image.py
+
36
−
11
View file @
2ae88a8e
...
...
@@ -16,6 +16,7 @@ from sparse_coding_torch.mobile_model import NetTensorFlowWrapper
import
time
import
csv
from
datetime
import
datetime
from
yolov4.get_bounding_boxes
import
YoloModel
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
()
...
...
@@ -64,6 +65,8 @@ if __name__ == "__main__":
checkpoint
=
torch
.
load
(
args
.
checkpoint
,
map_location
=
device
)
predictive_model
.
load_state_dict
(
checkpoint
[
'
model_state_dict
'
])
yolo_model
=
YoloModel
()
transform
=
torchvision
.
transforms
.
Compose
(
[
VideoGrayScaler
(),
MinMaxScaler
(
0
,
255
),
...
...
@@ -85,18 +88,40 @@ if __name__ == "__main__":
vc
=
VideoClips
([
os
.
path
.
join
(
args
.
input_directory
,
f
)],
clip_length_in_frames
=
5
,
frame_rate
=
20
,
frames_between_clips
=
1
)
frames_between_clips
=
5
)
clip_predictions
=
[]
for
i
in
range
(
vc
.
num_clips
()):
clip
,
_
,
_
,
_
=
vc
.
get_clip
(
i
)
clip
=
clip
.
swapaxes
(
1
,
3
).
swapaxes
(
0
,
1
).
swapaxes
(
2
,
3
).
to
(
torch
.
float
)
clip
=
transform
(
clip
)
clip
=
clip
.
swapaxes
(
1
,
3
).
swapaxes
(
0
,
1
).
swapaxes
(
2
,
3
).
numpy
()
bounding_boxes
=
yolo_model
.
get_bounding_boxes
(
clip
[:,
2
,
:,
:].
swapaxes
(
0
,
2
).
swapaxes
(
0
,
1
)).
squeeze
(
0
)
if
bounding_boxes
.
size
==
0
:
continue
for
bb
in
bounding_boxes
:
center_x
=
bb
[
0
]
*
1920
center_y
=
bb
[
1
]
*
1080
# width = region['relative_coordinates']['width'] * 1920
# height = region['relative_coordinates']['height'] * 1080
width
=
400
height
=
400
lower_y
=
round
(
center_y
-
height
/
2
)
upper_y
=
round
(
center_y
+
height
/
2
)
lower_x
=
round
(
center_x
-
width
/
2
)
upper_x
=
round
(
center_x
+
width
/
2
)
trimmed_clip
=
clip
[:,
:,
lower_y
:
upper_y
,
lower_x
:
upper_x
]
trimmed_clip
=
torch
.
tensor
(
trimmed_clip
).
to
(
torch
.
float
)
trimmed_clip
=
transform
(
trimmed_clip
)
with
torch
.
no_grad
():
clip
=
clip
.
unsqueeze
(
0
).
to
(
device
)
trimmed_clip
=
trimmed_
clip
.
unsqueeze
(
0
).
to
(
device
)
start_sparse_time
=
time
.
time
()
activations
=
frozen_sparse
(
clip
)
activations
=
frozen_sparse
(
trimmed_
clip
)
end_sparse_time
=
time
.
time
()
# Note that you can get activations here
...
...
This diff is collapsed.
Click to expand it.
yolov4
@
9f16748a
Subproject commit 9f16748aa3f45ff240608da4bd9b1216a29127f5
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