Skip to content

Instantly share code, notes, and snippets.

View TakaoNarikawa's full-sized avatar

Narikawa TakaoNarikawa

View GitHub Profile
import numpy as np
import matplotlib.pyplot as plt
def x(n):
return (1 - np.cos(n * np.pi)) / ((np.pi * n)** 2) if n != 0 else 0.5
def y(n):
return x(n // 2) if n % 2 == 0 else 0
def Xd(w, N=1000):
import Foundation
import CoreML
import Accelerate
@objc(Mish) class Mish: NSObject, MLCustomLayer {
let mishPipeline: MTLComputePipelineState
required init(parameters: [String : Any]) throws {
// Create the Metal compute kernels.
#include <metal_stdlib>
using namespace metal;
kernel void mish(
texture2d_array<half, access::read> inTexture [[texture(0)]],
texture2d_array<half, access::write> outTexture [[texture(1)]],
ushort3 gid [[thread_position_in_grid]])
{
if (gid.x >= outTexture.get_width() || gid.y >= outTexture.get_height()) {
return;
@TakaoNarikawa
TakaoNarikawa / convert.py
Created April 24, 2020 21:27
Convert darknet pre-trained model to CoreML model
#! /usr/bin/env python
"""
Reads Darknet config and weights and creates Keras model with TF backend.
"""
import argparse
import configparser
import io
import os