Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
363c1ad9
Commit
363c1ad9
authored
Oct 15, 2017
by
Davis King
Browse files
merged
parents
08a74837
a21093d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
0 deletions
+93
-0
dlib/cmake_utils/dlibConfig.cmake.in
dlib/cmake_utils/dlibConfig.cmake.in
+13
-0
dlib/dnn/layers.h
dlib/dnn/layers.h
+2
-0
dlib/rand/rand_kernel_1.h
dlib/rand/rand_kernel_1.h
+29
-0
dlib/rand/rand_kernel_abstract.h
dlib/rand/rand_kernel_abstract.h
+22
-0
dlib/test/rand.cpp
dlib/test/rand.cpp
+27
-0
No files found.
dlib/cmake_utils/dlibConfig.cmake.in
View file @
363c1ad9
...
@@ -33,4 +33,17 @@ set(dlib_LIBRARIES ${dlib_LIBRARIES} "@dlib_needed_libraries@")
...
@@ -33,4 +33,17 @@ set(dlib_LIBRARIES ${dlib_LIBRARIES} "@dlib_needed_libraries@")
set(dlib_LIBS ${dlib_LIBRARIES} "@dlib_needed_libraries@")
set(dlib_LIBS ${dlib_LIBRARIES} "@dlib_needed_libraries@")
set(dlib_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@" "@dlib_needed_includes@")
set(dlib_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@" "@dlib_needed_includes@")
# Mark these variables above as deprecated.
function(__deprecated_var var access)
if(access STREQUAL "READ_ACCESS")
message(WARNING "The variable '${var}' is deprecated! Instead, simply use target_link_libraries(your_app dlib::dlib). See http://dlib.net/examples/CMakeLists.txt.html for an example.")
endif()
endfunction()
variable_watch(dlib_LIBRARIES __deprecated_var)
variable_watch(dlib_LIBS __deprecated_var)
variable_watch(dlib_INCLUDE_DIRS __deprecated_var)
include(@CMAKE_INSTALL_FULL_INCLUDEDIR@/dlib/cmake_utils/use_cpp_11.cmake)
include(@CMAKE_INSTALL_FULL_INCLUDEDIR@/dlib/cmake_utils/use_cpp_11.cmake)
dlib/dnn/layers.h
View file @
363c1ad9
...
@@ -1470,6 +1470,8 @@ namespace dlib
...
@@ -1470,6 +1470,8 @@ namespace dlib
template
<
typename
SUBNET
>
template
<
typename
SUBNET
>
void
forward
(
const
SUBNET
&
sub
,
resizable_tensor
&
output
)
void
forward
(
const
SUBNET
&
sub
,
resizable_tensor
&
output
)
{
{
DLIB_CASSERT
(
num_inputs
==
sub
.
get_output
().
nr
()
*
sub
.
get_output
().
nc
()
*
sub
.
get_output
().
k
(),
"The size of the input tensor to this fc layer doesn't match the size the fc layer was trained with."
);
output
.
set_size
(
sub
.
get_output
().
num_samples
(),
num_outputs
);
output
.
set_size
(
sub
.
get_output
().
num_samples
(),
num_outputs
);
auto
w
=
weights
(
params
,
0
);
auto
w
=
weights
(
params
,
0
);
...
...
dlib/rand/rand_kernel_1.h
View file @
363c1ad9
...
@@ -146,6 +146,35 @@ namespace dlib
...
@@ -146,6 +146,35 @@ namespace dlib
return
begin
+
get_random_double
()
*
(
end
-
begin
);
return
begin
+
get_random_double
()
*
(
end
-
begin
);
}
}
long
long
get_integer_in_range
(
long
long
begin
,
long
long
end
)
{
DLIB_ASSERT
(
begin
<=
end
);
if
(
begin
==
end
)
return
begin
;
auto
r
=
get_random_64bit_number
();
const
auto
limit
=
std
::
numeric_limits
<
decltype
(
r
)
>::
max
();
const
auto
range
=
end
-
begin
;
// Use rejection sampling to remove the biased sampling you would get with
// the naive get_random_64bit_number()%range sampling.
while
(
r
>=
(
limit
/
range
)
*
range
)
r
=
get_random_64bit_number
();
return
begin
+
static_cast
<
long
long
>
(
r
%
range
);
}
long
long
get_integer
(
long
long
end
)
{
DLIB_ASSERT
(
end
>=
0
);
return
get_integer_in_range
(
0
,
end
);
}
double
get_random_double
(
double
get_random_double
(
)
)
{
{
...
...
dlib/rand/rand_kernel_abstract.h
View file @
363c1ad9
...
@@ -149,6 +149,28 @@ namespace dlib
...
@@ -149,6 +149,28 @@ namespace dlib
- returns begin
- returns begin
!*/
!*/
long
long
get_integer_in_range
(
long
long
begin
,
long
long
end
);
/*!
requires
- begin <= end
ensures
- returns a random integer selected from the range: begin <= N < end
The integer is selected uniformly at random.
!*/
long
long
get_integer
(
long
long
end
);
/*!
requires
- 0 <= end
ensures
- returns get_integer_in_range(0,end)
!*/
double
get_random_gaussian
(
double
get_random_gaussian
(
);
);
/*!
/*!
...
...
dlib/test/rand.cpp
View file @
363c1ad9
...
@@ -381,6 +381,32 @@ namespace
...
@@ -381,6 +381,32 @@ namespace
DLIB_TEST
(
std
::
abs
(
max_val
-
1.0
)
<
0.001
);
DLIB_TEST
(
std
::
abs
(
max_val
-
1.0
)
<
0.001
);
}
}
void
test_get_integer
()
{
print_spinner
();
dlib
::
rand
rnd
;
int
big
=
0
;
int
small
=
0
;
const
long
long
maxval
=
(((
unsigned
long
long
)
1
)
<<
62
)
+
(((
unsigned
long
long
)
1
)
<<
61
);
for
(
int
i
=
0
;
i
<
10000000
;
++
i
)
{
if
(
rnd
.
get_integer
(
maxval
)
>
maxval
/
2
)
++
big
;
else
++
small
;
}
// make sure there isn't any funny bias
DLIB_TEST
(
std
::
abs
(
big
/
(
double
)
small
-
1
)
<
0.001
);
cout
<<
big
/
(
double
)
small
<<
endl
;
}
class
rand_tester
:
public
tester
class
rand_tester
:
public
tester
{
{
public:
public:
...
@@ -401,6 +427,7 @@ namespace
...
@@ -401,6 +427,7 @@ namespace
test_normal_numbers
(
rnd
);
test_normal_numbers
(
rnd
);
test_gaussian_random_hash
();
test_gaussian_random_hash
();
test_uniform_random_hash
();
test_uniform_random_hash
();
test_get_integer
();
}
}
}
a
;
}
a
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment