-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2019 JD.com Inc. JD AI | ||
|
||
#include "PRelu.h" | ||
|
||
namespace bnn { | ||
void PRelu::forward_impl() const { | ||
BNN_ASSERT(slope_mat->total() == 1 || | ||
slope_mat->total() == static_cast<size_t>(data_mat->c), | ||
"slope must have size 1 or input.channels"); | ||
float *ptr = static_cast<float *>(*data_mat); | ||
float *slope_ptr = static_cast<float *>(*slope_mat); | ||
if (slope_mat->total() == 1) { | ||
const auto slope = *slope_ptr; | ||
FORZ(i, data_mat->total()) { | ||
if (*ptr < 0) { | ||
*ptr = (*ptr) * slope; | ||
} | ||
ptr++; | ||
} | ||
} else if (slope_mat->total() == static_cast<size_t>(data_mat->c)) { | ||
const auto nhw = data_mat->n * data_mat->h * data_mat->w; | ||
FORZ(i, nhw) { | ||
FORZ(j, data_mat->c) { | ||
if (*ptr < 0) { | ||
*ptr = (*ptr) * slope_ptr[j]; | ||
} | ||
ptr++; | ||
} | ||
} | ||
} | ||
} | ||
} // namespace bnn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2019 JD.com Inc. JD AI | ||
|
||
#ifndef BNN_PRELU_H | ||
#define BNN_PRELU_H | ||
|
||
#include <dabnn/layer.h> | ||
|
||
namespace bnn { | ||
class PRelu : public Layer { | ||
public: | ||
MatCP data_mat; | ||
MatCP slope_mat; | ||
|
||
PRelu(NetCP net, const std::string &name, css data) | ||
: Layer(net, name, "PRelu"), data_mat(mat(data)) {} | ||
virtual void forward_impl() const; | ||
}; | ||
} // namespace bnn | ||
|
||
#endif /* BNN_PRELU_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters