Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RAVEN2YOLO
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephane Chavin
RAVEN2YOLO
Commits
390249f7
Commit
390249f7
authored
9 months ago
by
Stephane Chavin
Browse files
Options
Downloads
Patches
Plain Diff
add vmin option
parent
1f8a8ea6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
get_spectrogram.py
+3
-1
3 additions, 1 deletion
get_spectrogram.py
utils.py
+6
-2
6 additions, 2 deletions
utils.py
yolov5/detect.py
+4
-1
4 additions, 1 deletion
yolov5/detect.py
yolov5/utils/dataloaders.py
+7
-3
7 additions, 3 deletions
yolov5/utils/dataloaders.py
with
20 additions
and
7 deletions
get_spectrogram.py
+
3
−
1
View file @
390249f7
...
...
@@ -54,7 +54,7 @@ def main(data, arguments):
utils
.
create_spectrogram
(
sig
,
arguments
.
directory
,
name
,
arguments
.
cmap
,
window_size
=
int
(
arguments
.
window
),
overlap
=
arguments
.
hop
)
overlap
=
arguments
.
hop
,
vmin
=
arguments
.
vmin
)
except
Exception
as
error
:
folder
=
'
spectrograms
'
...
...
@@ -85,6 +85,8 @@ if __name__ == "__main__":
help
=
'
Overlap in secondes between 2 spectrograms
'
,
default
=
0
)
parser
.
add_argument
(
'
--rf
'
,
type
=
int
,
help
=
'
Resampling Frequency of the signal. If no argument,
'
'
will be original frequency sampling of the recording
'
,
default
=
None
)
parser
.
add_argument
(
'
--vmin
'
,
type
=
str
,
help
=
"
If vmin == True, then the spectrogram
'
s minimum color
"
'
will be stft.mean(). If False stft.min()
'
,
default
=
True
)
parser
.
add_argument
(
'
--cpu
'
,
type
=
int
,
help
=
'
To speed up the process, write 2 or more
'
,
default
=
1
)
parser
.
add_argument
(
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
6
−
2
View file @
390249f7
...
...
@@ -87,7 +87,7 @@ def signal_processing(sig, rf, fs, high=None, low=None):
return
sig
def
create_spectrogram
(
sig
,
directory
,
names
,
cmap
,
window_size
=
1024
,
overlap
=
.
5
,):
def
create_spectrogram
(
sig
,
directory
,
names
,
cmap
,
window_size
=
1024
,
overlap
=
.
5
,
minimum
=
True
):
"""
Create a spectrogram STFT with hanning window and save it into a directory
...
...
@@ -107,9 +107,13 @@ def create_spectrogram(sig, directory, names, cmap, window_size=1024, overlap=.5
hop_length
=
int
(
overlap_size
),
window
=
'
hann
'
)
# Compute the STFT
stft
=
np
.
log10
(
np
.
abs
(
stft
))
# Adapt the Complex-valued matrix
fig
=
plt
.
figure
()
if
minimum
:
vmin
=
stft
.
mean
()
else
:
vmin
=
stft
.
min
()
# plot the spectrogram
plt
.
imshow
(
stft
[::
-
1
],
aspect
=
'
auto
'
,
interpolation
=
None
,
cmap
=
cmap
)
# you can add : vmin=
stft.mean()
)
interpolation
=
None
,
cmap
=
cmap
)
# you can add : vmin=
vmin
)
# Remove all the borders around the plot
plt
.
subplots_adjust
(
top
=
1
,
bottom
=
0
,
left
=
0
,
right
=
1
)
if
names
:
...
...
This diff is collapsed.
Click to expand it.
yolov5/detect.py
+
4
−
1
View file @
390249f7
...
...
@@ -74,6 +74,7 @@ def run(
rf
=
22050
,
window
=
1024
,
hop
=
0.5
,
minimum
=
True
,
# vmin spectrogram is stft.mean()
low
=
None
,
high
=
None
,
cmap
=
'
viridis
'
,
...
...
@@ -136,7 +137,7 @@ def run(
print
(
f
'
You put hop > 1, this has been corrected by putting hop at
{
hop
}
'
)
else
:
hop
=
window
*
hop
dataset
=
LoadSpectros
(
source
,
sampleDur
,
rf
,
window
,
hop
,
low
,
high
,
cmap
,
img_size
=
imgsz
,
stride
=
stride
,
auto
=
pt
)
dataset
=
LoadSpectros
(
source
,
sampleDur
,
rf
,
window
,
hop
,
low
,
high
,
cmap
,
img_size
=
imgsz
,
stride
=
stride
,
auto
=
pt
,
minimum
=
minimum
)
else
:
dataset
=
LoadImages
(
source
,
img_size
=
imgsz
,
stride
=
stride
,
auto
=
pt
,
vid_stride
=
vid_stride
)
vid_path
,
vid_writer
=
[
None
]
*
bs
,
[
None
]
*
bs
...
...
@@ -279,6 +280,8 @@ def parse_opt():
help
=
"
Colormap used for the spectrograms
"
,
type
=
str
)
parser
.
add_argument
(
'
--window
'
,
default
=
1024
,
help
=
"
Window size for each spectrogram for detection
"
,
type
=
int
)
parser
.
add_argument
(
'
--hop
'
,
default
=
0.5
,
help
=
"
Hop lenght for each spectrogram for detection
"
,
type
=
float
)
parser
.
add_argument
(
'
--vmin
'
,
type
=
str
,
help
=
'
If vmin == True, then the spectrogram minimum color
'
'
will be stft.mean(). If False stft.min()
'
,
default
=
True
)
parser
.
add_argument
(
'
--hide-conf
'
,
default
=
False
,
action
=
'
store_true
'
,
help
=
'
hide confidences
'
)
parser
.
add_argument
(
'
--half
'
,
action
=
'
store_true
'
,
help
=
'
use FP16 half-precision inference
'
)
parser
.
add_argument
(
'
--sound
'
,
default
=
False
,
action
=
'
store_true
'
)
...
...
This diff is collapsed.
Click to expand it.
yolov5/utils/dataloaders.py
+
7
−
3
View file @
390249f7
...
...
@@ -239,8 +239,8 @@ class LoadScreenshots:
return
str
(
self
.
screen
),
im
,
im0
,
None
,
s
# screen, img, original img, im0s, s
class
LoadSpectros
:
def
__init__
(
self
,
folder
,
sampleDur
,
rf
,
window
,
hop
,
low
,
high
,
cmap
,
img_size
,
stride
=
32
,
auto
=
True
):
self
.
folder
,
self
.
sampleDur
,
self
.
rf
,
self
.
window
,
self
.
hop
,
self
.
low
,
self
.
high
,
self
.
cmap
,
self
.
img_size
,
self
.
stride
,
self
.
auto
=
folder
,
sampleDur
,
rf
,
window
,
hop
,
low
,
high
,
cmap
,
img_size
,
stride
,
auto
def
__init__
(
self
,
folder
,
sampleDur
,
rf
,
window
,
hop
,
low
,
high
,
cmap
,
img_size
,
stride
=
32
,
auto
=
True
,
minimum
=
True
):
self
.
folder
,
self
.
sampleDur
,
self
.
rf
,
self
.
window
,
self
.
hop
,
self
.
low
,
self
.
high
,
self
.
cmap
,
self
.
img_size
,
self
.
stride
,
self
.
auto
,
self
.
minimum
=
folder
,
sampleDur
,
rf
,
window
,
hop
,
low
,
high
,
cmap
,
img_size
,
stride
,
auto
,
minimum
self
.
files
=
os
.
listdir
(
folder
)
self
.
mode
=
'
image
'
self
.
samples
=
[]
...
...
@@ -290,8 +290,12 @@ class LoadSpectros:
stft
=
librosa
.
stft
(
sig
,
n_fft
=
self
.
window
,
hop_length
=
hop
,
window
=
'
hann
'
)
# Compute the STFT
stft
=
np
.
log10
(
np
.
abs
(
stft
))
if
minimum
:
vmin
=
stft
.
mean
()
else
:
vmin
=
stft
.
min
()
axim
=
plt
.
imshow
(
stft
,
aspect
=
"
auto
"
,
interpolation
=
None
,
cmap
=
self
.
cmap
)
# you can add : vmin=np.mean(stft)
)
cmap
=
self
.
cmap
,
vmin
=
vmin
)
plt
.
subplots_adjust
(
top
=
1
,
bottom
=
0
,
left
=
0
,
right
=
1
)
im0
=
axim
.
make_image
(
fig
.
canvas
)[
0
][:,:,:
-
1
][:,:,::
-
1
]
cv2
.
imwrite
(
path
,
im0
)
...
...
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