azeme1 / keras2ncnn

MIT License
24 stars 0 forks source link

How to add new Layer in this repo #18

Open fiyud opened 3 months ago

fiyud commented 3 months ago

i'm trying to convert the Gamma pose model into ncnn by using this repo, still getting struggle while converting cus some of the layer got defined by the authors not from the library

azeme1 commented 3 months ago

I'm very surprised that this project is still working. Send me a model with random weights, I'll see what the problem is

fiyud commented 3 months ago

Thanks you very much man

Here is link to the weight Download_link, i'm using weight from this repo Link_to_repo, while i encountering this error:

/usr/local/lib/python3.10/dist-packages/keras/src/layers/core/lambda_layer.py in (video)

NameError: Exception encountered when calling layer "lambda" (type Lambda).

name 'frame_func' is not defined

Call arguments received by layer "lambda" (type Lambda): • inputs=tf.Tensor(shape=(None, 51, 100, 100, 3), dtype=float32) • mask=None • training=None

And here is the frame_func function that from the repo:

import tensorflow.keras.backend as K

def tf_frame_diff(video): return video[1:] - video[:-1]

def tf_frame_dist(video): video_diff = tf_frame_diff(video) return K.sqrt(K.sum(K.square(video_diff), axis=-1, keepdims=True))

if WEIGHT_CURRENT: def tf_frame_diff_dist_combined(video): video_diff = tf_frame_diff(video) video_diff_current = tf.nn.relu(-video_diff) video_diff_next = tf.nn.relu(video_diff) video_diff_next_norm = K.sqrt(K.sum(K.square(video_diff_next), axis=-1, keepdims=True)) return K.concatenate([video_diff_current, video_diff_next_norm]) else: def tf_frame_diff_dist_combined(video): video_diff = tf_frame_diff(video) video_diff_current = tf.nn.relu(video_diff) video_diff_prev = tf.nn.relu(-video_diff) video_diff_prev_norm = K.sqrt(K.sum(K.square(video_diff_prev), axis=-1, keepdims=True)) return K.concatenate([video_diff_current, video_diff_prev_norm])

frame_func_dict = {'frame_diff': tf_frame_diff, 'frame_dist': tf_frame_dist, 'frame_diff_dist_combined': tf_frame_diff_dist_combined} frame_func = frame_func_dict[FRAME_FUNC]