Skip to content

Commit

Permalink
Update rknn_model_zoo to V2.3.0. Support more examples, such as zipfo…
Browse files Browse the repository at this point in the history
…rmer yolo11 etc.

Signed-off-by: Randall Zhuo <randall.zhuo@rock-chips.com>
  • Loading branch information
Randall Zhuo committed Nov 11, 2024
1 parent 333f951 commit c918ec6
Show file tree
Hide file tree
Showing 101 changed files with 15,811 additions and 226 deletions.
7 changes: 6 additions & 1 deletion 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ set(LIBSNDFILE ${LIBSNDFILE_PATH}/${CMAKE_SYSTEM_NAME}/${TARGET_LIB_ARCH}/libsnd
# fftw
set(LIBFFTW_PATH ${CMAKE_CURRENT_SOURCE_DIR}/fftw)
set(LIBFFTW_INCLUDES ${LIBFFTW_PATH}/include PARENT_SCOPE)
set(LIBFFTW ${LIBFFTW_PATH}/${CMAKE_SYSTEM_NAME}/${TARGET_LIB_ARCH}/libfftw3f.a PARENT_SCOPE)
set(LIBFFTW ${LIBFFTW_PATH}/${CMAKE_SYSTEM_NAME}/${TARGET_LIB_ARCH}/libfftw3f.a PARENT_SCOPE)

# kaldi_native_fbank
set(LIBKALDI_NATIVE_FBANK_PATH ${CMAKE_CURRENT_SOURCE_DIR}/kaldi_native_fbank)
set(LIBKALDI_NATIVE_FBANK_INCLUDES ${LIBKALDI_NATIVE_FBANK_PATH}/include PARENT_SCOPE)
set(LIBKALDI_NATIVE_FBANK ${LIBKALDI_NATIVE_FBANK_PATH}/${CMAKE_SYSTEM_NAME}/${TARGET_LIB_ARCH}/libkaldi-native-fbank-core.a PARENT_SCOPE)
23 changes: 16 additions & 7 deletions 3rdparty/allocator/dma/dma_alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* limitations under the License.
*/

#ifndef _DMA_ALLOC_HPP_
#define _DMA_ALLOC_HPP_

#include <getopt.h>
#include <sys/mman.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -46,9 +49,16 @@
#include <memory.h>
#include <sys/time.h>

#include "dma_alloc.h"
// #include "dma_alloc.h"
#include "RgaUtils.h"

#define DMA_HEAP_UNCACHE_PATH "/dev/dma_heap/system-uncached"
#define DMA_HEAP_PATH "/dev/dma_heap/system"
#define DMA_HEAP_DMA32_UNCACHE_PATCH "/dev/dma_heap/system-uncached-dma32"
#define DMA_HEAP_DMA32_PATCH "/dev/dma_heap/system-dma32"
#define CMA_HEAP_UNCACHE_PATH "/dev/dma_heap/cma-uncached"
#define RV1106_CMA_HEAP_PATH "/dev/rk_dma_heap/rk-dma-heap-cma"

typedef unsigned long long __u64;
typedef unsigned int __u32;

Expand Down Expand Up @@ -87,21 +97,21 @@ struct dma_buf_sync {

#define CMA_HEAP_SIZE 1024 * 1024

int dma_sync_device_to_cpu(int fd) {
static int dma_sync_device_to_cpu(int fd) {
struct dma_buf_sync sync = {0};

sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW;
return ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
}

int dma_sync_cpu_to_device(int fd) {
static int dma_sync_cpu_to_device(int fd) {
struct dma_buf_sync sync = {0};

sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW;
return ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
}

int dma_buf_alloc(const char *path, size_t size, int *fd, void **va) {
static int dma_buf_alloc(const char *path, size_t size, int *fd, void **va) {
int ret;
int prot;
void *mmap_va;
Expand Down Expand Up @@ -149,7 +159,7 @@ int dma_buf_alloc(const char *path, size_t size, int *fd, void **va) {
return 0;
}

void dma_buf_free(size_t size, int *fd, void *va) {
static void dma_buf_free(size_t size, int *fd, void *va) {
int len;

len = size;
Expand All @@ -159,5 +169,4 @@ void dma_buf_free(size_t size, int *fd, void *va) {
*fd = -1;
}



#endif // _DMA_ALLOC_HPP_
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* Copyright (c) 2022 Xiaomi Corporation (authors: Fangjun Kuang)
*
* See LICENSE for clarification regarding multiple authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// This file is copied/modified from kaldi/src/feat/feature-fbank.h

#ifndef KALDI_NATIVE_FBANK_CSRC_FEATURE_FBANK_H_
#define KALDI_NATIVE_FBANK_CSRC_FEATURE_FBANK_H_

#include <map>
#include <string>
#include <vector>
#include <cstdint>
#include <sstream>

#include "kaldi-native-fbank/csrc/feature-window.h"
#include "kaldi-native-fbank/csrc/mel-computations.h"
#include "kaldi-native-fbank/csrc/rfft.h"

namespace knf {

struct FbankOptions {
FrameExtractionOptions frame_opts;
MelBanksOptions mel_opts;
// append an extra dimension with energy to the filter banks
bool use_energy = false;
float energy_floor = 0.0f; // active iff use_energy==true

// If true, compute log_energy before preemphasis and windowing
// If false, compute log_energy after preemphasis ans windowing
bool raw_energy = true; // active iff use_energy==true

// If true, put energy last (if using energy)
// If false, put energy first
bool htk_compat = false; // active iff use_energy==true

// if true (default), produce log-filterbank, else linear
bool use_log_fbank = true;

// if true (default), use power in filterbank
// analysis, else magnitude.
bool use_power = true;

FbankOptions() { mel_opts.num_bins = 23; }

std::string ToString() const {
std::ostringstream os;
os << "frame_opts: \n";
os << frame_opts << "\n";
os << "\n";

os << "mel_opts: \n";
os << mel_opts << "\n";

os << "use_energy: " << use_energy << "\n";
os << "energy_floor: " << energy_floor << "\n";
os << "raw_energy: " << raw_energy << "\n";
os << "htk_compat: " << htk_compat << "\n";
os << "use_log_fbank: " << use_log_fbank << "\n";
os << "use_power: " << use_power << "\n";
return os.str();
}
};

std::ostream &operator<<(std::ostream &os, const FbankOptions &opts);

class FbankComputer {
public:
using Options = FbankOptions;

explicit FbankComputer(const FbankOptions &opts);
~FbankComputer();

int32_t Dim() const {
return opts_.mel_opts.num_bins + (opts_.use_energy ? 1 : 0);
}

// if true, compute log_energy_pre_window but after dithering and dc removal
bool NeedRawLogEnergy() const { return opts_.use_energy && opts_.raw_energy; }

const FrameExtractionOptions &GetFrameOptions() const {
return opts_.frame_opts;
}

const FbankOptions &GetOptions() const { return opts_; }

/**
Function that computes one frame of features from
one frame of signal.
@param [in] signal_raw_log_energy The log-energy of the frame of the signal
prior to windowing and pre-emphasis, or
log(numeric_limits<float>::min()), whichever is greater. Must be
ignored by this function if this class returns false from
this->NeedsRawLogEnergy().
@param [in] vtln_warp The VTLN warping factor that the user wants
to be applied when computing features for this utterance. Will
normally be 1.0, meaning no warping is to be done. The value will
be ignored for feature types that don't support VLTN, such as
spectrogram features.
@param [in] signal_frame One frame of the signal,
as extracted using the function ExtractWindow() using the options
returned by this->GetFrameOptions(). The function will use the
vector as a workspace, which is why it's a non-const pointer.
@param [out] feature Pointer to a vector of size this->Dim(), to which
the computed feature will be written. It should be pre-allocated.
*/
void Compute(float signal_raw_log_energy, float vtln_warp,
std::vector<float> *signal_frame, float *feature);

private:
const MelBanks *GetMelBanks(float vtln_warp);

FbankOptions opts_;
float log_energy_floor_;
std::map<float, MelBanks *> mel_banks_; // float is VTLN coefficient.
Rfft rfft_;
};

} // namespace knf

#endif // KALDI_NATIVE_FBANK_CSRC_FEATURE_FBANK_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2022 Xiaomi Corporation (authors: Fangjun Kuang)
*
* See LICENSE for clarification regarding multiple authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// This file is copied/modified from kaldi/src/feat/feature-functions.h
#ifndef KALDI_NATIVE_FBANK_CSRC_FEATURE_FUNCTIONS_H_
#define KALDI_NATIVE_FBANK_CSRC_FEATURE_FUNCTIONS_H_

#include <vector>
namespace knf {

// ComputePowerSpectrum converts a complex FFT (as produced by the FFT
// functions in csrc/rfft.h), and converts it into
// a power spectrum. If the complex FFT is a vector of size n (representing
// half of the complex FFT of a real signal of size n, as described there),
// this function computes in the first (n/2) + 1 elements of it, the
// energies of the fft bins from zero to the Nyquist frequency. Contents of the
// remaining (n/2) - 1 elements are undefined at output.

void ComputePowerSpectrum(std::vector<float> *complex_fft);

} // namespace knf

#endif // KALDI_NATIVE_FBANK_CSRC_FEATURE_FUNCTIONS_H_
Loading

0 comments on commit c918ec6

Please sign in to comment.