andrewzhaoluo / centerfacetvmdemo Goto Github PK
View Code? Open in Web Editor NEWA demo for using CenterFace in TVM
License: MIT License
A demo for using CenterFace in TVM
License: MIT License
tvm/build/libtvm.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/libtvm.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/lib/libtvm.dylib' (no such file)
I finally successfully built tvm on M1, but run your demo got error, what did I miss?
Hi @AndrewZhaoLuo
Thank you very much for your project. I am new to TVM.
Recently, I used TVM to deploy a speech noise reduction model on x86 PC, which can be processed in real time after autoscheduler. Now it also is necessary to consider deploying to android arm64, so a lightweight network is required.
My network structure is Convolution Recurrent Network, can I use your graph_optimize function?
Thanks!
import math
import torch
from torch import nn
import torch.nn.functional as F
class DCRN(nn.Module):
def __init__(self, rnn_hidden=128, fft_len=512, kernel_size=5, kernel_num=(16, 32, 64, 128, 128, 128)):
super(DCRN, self).__init__()
self.rnn_hidden = rnn_hidden
self.fft_len = fft_len
self.kernel_size = kernel_size
self.kernel_num = (2,) + kernel_num
self.encoder = nn.ModuleList()
self.decoder = nn.ModuleList()
for idx in range(len(self.kernel_num) - 1):
self.encoder.append(
nn.Sequential(
nn.Conv2d(
self.kernel_num[idx],
self.kernel_num[idx + 1],
kernel_size=(self.kernel_size, 1),
stride=(2, 1),
padding=(self.kernel_size // 2, 0),
),
nn.BatchNorm2d(self.kernel_num[idx + 1]),
nn.PReLU()
)
)
hidden_dim = self.fft_len // (2 ** (len(self.kernel_num)))
self.enhance = nn.LSTM(
input_size=hidden_dim * self.kernel_num[-1],
hidden_size=self.rnn_hidden,
num_layers=1,
dropout=0.0,
batch_first=False
)
self.transform = nn.Linear(self.rnn_hidden, hidden_dim * self.kernel_num[-1])
for idx in range(len(self.kernel_num) - 1, 0, -1):
if idx != 1:
self.decoder.append(
nn.Sequential(
nn.ConvTranspose2d(
self.kernel_num[idx] * 2,
self.kernel_num[idx - 1],
kernel_size=(self.kernel_size, 1),
stride=(2, 1),
padding=(2, 0),
output_padding=(1, 0)
),
nn.BatchNorm2d(self.kernel_num[idx - 1]),
nn.PReLU()
)
)
else:
self.decoder.append(
nn.Sequential(
nn.ConvTranspose2d(
self.kernel_num[idx] * 2,
self.kernel_num[idx - 1],
kernel_size=(self.kernel_size, 1),
stride=(2, 1),
padding=(2, 0),
output_padding=(1, 0)
)
)
)
if isinstance(self.enhance, nn.LSTM):
self.enhance.flatten_parameters()
def forward(self, stft):
real = stft[:, :self.fft_len // 2 + 1]
imag = stft[:, self.fft_len // 2 + 1:]
spec_mags = torch.sqrt(real ** 2 + imag ** 2 + 1e-8)
spec_phase = torch.atan(imag / (real + 1e-8))
phase_adjust = (real < 0).to(torch.int) * torch.sign(imag) * math.pi
spec_phase = spec_phase + phase_adjust
spec_complex = torch.stack([real, imag], dim=1)[:, :, 1:] # B,2,256
out = spec_complex
encoder_out = []
for idx, encoder in enumerate(self.encoder):
out = encoder(out)
encoder_out.append(out)
B, C, D, T = out.size()
out = out.permute(3, 0, 1, 2)
out = torch.reshape(out, [T, B, C * D])
out, _ = self.enhance(out)
out = self.transform(out)
out = torch.reshape(out, [T, B, C, D])
out = out.permute(1, 2, 3, 0)
for idx in range(len(self.decoder)):
out = torch.cat([out, encoder_out[-1 - idx]], 1)
out = self.decoder[idx](out)
mask_real = out[:, 0]
mask_imag = out[:, 1]
mask_real = F.pad(mask_real, [0, 0, 1, 0], value=1e-8)
mask_imag = F.pad(mask_imag, [0, 0, 1, 0], value=1e-8)
mask_mags = (mask_real ** 2 + mask_imag ** 2) ** 0.5
real_phase = mask_real / (mask_mags + 1e-8)
imag_phase = mask_imag / (mask_mags + 1e-8)
mask_phase = torch.atan(imag_phase / (real_phase + 1e-8))
phase_adjust = (real_phase < 0).to(torch.int) * torch.sign(imag_phase) * math.pi
mask_phase = mask_phase + phase_adjust
mask_mags = torch.tanh(mask_mags) # mask 所以要tanh
est_mags = mask_mags * spec_mags
est_phase = spec_phase + mask_phase
real = est_mags * torch.cos(est_phase)
imag = est_mags * torch.sin(est_phase)
out_spec = torch.cat([real, imag], 1)
return out_spec
model = DCRN()
model = model.eval()
# We grab the TorchScripted model via tracing
torch.manual_seed(0)
x = torch.randn([1, 514, 125])
a = model(x)
Seems face boxes running on MacBook just need about 8ms
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.