Giter VIP home page Giter VIP logo

Comments (16)

syaringan357 avatar syaringan357 commented on May 12, 2024

import tensorflow as tf

in_path = "../output/mobilefacenet/frozen_graphs/MobileFaceNet.pb"
out_path = "../output/mobilefacenet/tflite/MobileFaceNet.tflite"

input_tensor_name = ["input"]
input_tensor_shape = {"input": [2, 112, 112, 3]}
classes_tensor_name = ["embeddings"]

converter = tf.lite.TFLiteConverter.from_frozen_graph(in_path, input_tensor_name,
classes_tensor_name, input_shapes=input_tensor_shape)
tflite_model = converter.convert()

with open(out_path, "wb") as f:
f.write(tflite_model)

from android-mobilefacenet-mtcnn-faceantispoofing.

kongdaniel avatar kongdaniel commented on May 12, 2024

我用你的代码依然不行,和版本有关系吗。我是1.15现在
2020-04-26 14:16:25.685949: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 1484 operators, 2717 arrays (0 quantized)
2020-04-26 14:16:25.696619: 他报这个错F .\tensorflow/lite/toco/toco_tooling.h:38] Check failed: s.ok() Found BatchNormalization as non-selected output from Switch, but only Merge supported. Control flow ops like Switch and Merge are not generally supported. We are working on fixing this, please see the Github issue at tensorflow/tensorflow#28485.
Fatal Python error: Aborted`

from android-mobilefacenet-mtcnn-faceantispoofing.

kongdaniel avatar kongdaniel commented on May 12, 2024

from android-mobilefacenet-mtcnn-faceantispoofing.

syaringan357 avatar syaringan357 commented on May 12, 2024

哦,我不是用他原来那个pb转的,用他的ckpt重新固化一个pb,再转。

from android-mobilefacenet-mtcnn-faceantispoofing.

syaringan357 avatar syaringan357 commented on May 12, 2024

import os
import tensorflow as tf
from nets.MobileFaceNet import inference

training_checkpoint = "../output/mobilefacenet/MobileFaceNet_TF.ckpt"
OUTPUT_DIR = '../output/mobilefacenet/frozen_graphs'

def freeze_graph_def(sess, output_node_names):
# Replace all the variables in the graph with constants of the same values
output_graph_def = tf.compat.v1.graph_util.convert_variables_to_constants(
sess, sess.graph_def, output_node_names.split(","))
return output_graph_def

def save():
data_input = tf.placeholder(name='input', dtype=tf.float32, shape=[None, 112, 112, 3])

output, _ = inference(data_input, bottleneck_layer_size=192)
tf.identity(output, name='embeddings')
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)

    saver = tf.train.Saver()
    saver.restore(sess, training_checkpoint)

    # Freeze the graph def
    output_graph_def = freeze_graph_def(sess, 'embeddings')

    output_pnet = os.path.join(OUTPUT_DIR, 'MobileFaceNet.pb')
    # Serialize and dump the output graph to the filesystem
    with tf.gfile.GFile(output_pnet, 'wb') as f:
        f.write(output_graph_def.SerializeToString())

if name == 'main':
save()

from android-mobilefacenet-mtcnn-faceantispoofing.

syaringan357 avatar syaringan357 commented on May 12, 2024

凑合看把 上面都是代码

from android-mobilefacenet-mtcnn-faceantispoofing.

kongdaniel avatar kongdaniel commented on May 12, 2024

凑合看把 上面都是代码

谢谢大佬,跪谢。

from android-mobilefacenet-mtcnn-faceantispoofing.

kongdaniel avatar kongdaniel commented on May 12, 2024

import os
import tensorflow as tf
from nets.MobileFaceNet import inference

training_checkpoint = "../output/mobilefacenet/MobileFaceNet_TF.ckpt"
OUTPUT_DIR = '../output/mobilefacenet/frozen_graphs'

def freeze_graph_def(sess, output_node_names):

Replace all the variables in the graph with constants of the same values

output_graph_def = tf.compat.v1.graph_util.convert_variables_to_constants(
sess, sess.graph_def, output_node_names.split(","))
return output_graph_def

def save():
data_input = tf.placeholder(name='input', dtype=tf.float32, shape=[None, 112, 112, 3])

output, _ = inference(data_input, bottleneck_layer_size=192)
tf.identity(output, name='embeddings')
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)

    saver = tf.train.Saver()
    saver.restore(sess, training_checkpoint)

    # Freeze the graph def
    output_graph_def = freeze_graph_def(sess, 'embeddings')

    output_pnet = os.path.join(OUTPUT_DIR, 'MobileFaceNet.pb')
    # Serialize and dump the output graph to the filesystem
    with tf.gfile.GFile(output_pnet, 'wb') as f:
        f.write(output_graph_def.SerializeToString())

if name == 'main':
save()

大哥,再问个问题,就是这一句output, _ = inference(data_input, bottleneck_layer_size=192)
为啥这里是192,我看他代码里写的都是128,所以说他默认的参数应该是128呀,但是,我用128转换他居然说要求192,这是啥原因。

from android-mobilefacenet-mtcnn-faceantispoofing.

syaringan357 avatar syaringan357 commented on May 12, 2024

我也不太清楚,我也是按报错提示改的。可能是他一些代码经过长时间修改之后对不上了。

from android-mobilefacenet-mtcnn-faceantispoofing.

kongdaniel avatar kongdaniel commented on May 12, 2024

from android-mobilefacenet-mtcnn-faceantispoofing.

yp19940913 avatar yp19940913 commented on May 12, 2024

你好,请问这个问题解决了吗?方便说一下解决方法嘛?多谢

from android-mobilefacenet-mtcnn-faceantispoofing.

kongdaniel avatar kongdaniel commented on May 12, 2024

你好,请问这个问题解决了吗?方便说一下解决方法嘛?多谢

你好,你可以看作者发的代码,可以解决,当时,我就是用他的代码,现在我代码找不到了。换了块硬盘,找起来费劲得很。你如果用他的代码无语,那就正好,如果有误,我就再找找

from android-mobilefacenet-mtcnn-faceantispoofing.

leduy99 avatar leduy99 commented on May 12, 2024

Hi, I'm encouting the same problem and cannot solve this. My approach is to change 'Switch' op -> 'If' and 'Merge' -> 'While' but didn't work. Any suggestion? Tks :D

from android-mobilefacenet-mtcnn-faceantispoofing.

kongdaniel avatar kongdaniel commented on May 12, 2024

from android-mobilefacenet-mtcnn-faceantispoofing.

leduy99 avatar leduy99 commented on May 12, 2024

But how can you export a tflite version from the model? :o

from android-mobilefacenet-mtcnn-faceantispoofing.

redaihanyu avatar redaihanyu commented on May 12, 2024

import tensorflow as tf

in_path = "../output/mobilefacenet/frozen_graphs/MobileFaceNet.pb" out_path = "../output/mobilefacenet/tflite/MobileFaceNet.tflite"

input_tensor_name = ["input"] input_tensor_shape = {"input": [2, 112, 112, 3]} classes_tensor_name = ["embeddings"]

converter = tf.lite.TFLiteConverter.from_frozen_graph(in_path, input_tensor_name, classes_tensor_name, input_shapes=input_tensor_shape) tflite_model = converter.convert()

with open(out_path, "wb") as f: f.write(tflite_model)

您好,为什么您这里的batchsize 设置成 2呢,不应该是1吗?

from android-mobilefacenet-mtcnn-faceantispoofing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.