能否提供一个MNIST的vim3教程

vim3(A311D,S905D3)的NPU使用过程中问题颇多,且与RK相比,AMLOGIC官方文档简陋、工具太少,经多名程序员反复研究1月有余,但仍旧无法成功转换我们的模型,各环节的问题多如牛毛,甚至至今无法定位问题触发点。
而khadas给出的教程是基于yolo和inception的,对于darknet yolo和inception模型使用不熟悉的话,会加大入门难度。
希望KHADAS能够给些更初级的例程,比如MNIST,以方便后来者入门、排查问题。
谢谢!

@ThinkBird 你们是是用什么模型转换出的问题,mnist之前转过,可以转,但是没有做详细的测试

mnist测试用的源码如下:

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

print(tf.__version__)

# 准备数据
mnist = tf.keras.datasets.mnist
(train_images, train_lables),(test_images, test_lables) = mnist.load_data()

train_images = train_images/255.0
test_images = test_images/255.0

# 建模
model = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=(28,28), name="input"),
    tf.keras.layers.Dense(64,activation=tf.nn.relu),
    tf.keras.layers.Dense(32,activation=tf.nn.relu),
    tf.keras.layers.Dense(10,activation=tf.nn.softmax, name="output")
])

model.summary()

# 定义训练模式
model.compile(optimizer = 'adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

# 训练
train_epochs = 10
batch_size = 30

train_history = model.fit(  train_images,
                            train_lables,
                            validation_split = 0.2,
                            epochs = train_epochs,
                            batch_size = batch_size,
                            verbose = 2 )


# 输出训练历史
train_history.history     

# 画图
def show_train_history(show_train_history,train_metric,val_metric):
    plt.plot(train_history.history[train_metric])
    plt.plot(train_history.history[val_metric])
    plt.title('Train history: %s' % train_metric)
    plt.xlabel('Epoch')
    plt.ylabel(train_metric)
    plt.legend(['train','validation'], loc = 'upper left')
    plt.show()

show_train_history(train_history, 'loss', 'val_loss')

# show_train_history(train_history, 'accuracy', 'val_accuracy')

# 模型评估
test_loss, test_acc = model.evaluate(test_images, test_lables, verbose =2)
test_loss, test_acc, model.metrics_names

# 应用模型
test_pred = model.predict_classes(test_images)
print(test_pred)
# 保存模型
model.save('tf1_mnist_model.h5')

转换工具使用的是论坛中给出的 h5_to_pb 方法

from keras.models import load_model
import tensorflow as tf
import argparse
import sys
import os 
import os.path as osp
from keras import backend as K


def h5_to_pb(h5_model,output_dir,model_name,out_prefix = "output_"):
	if osp.exists(output_dir) == False:
		os.mkdir(output_dir)
	out_nodes = []
	for i in range(len(h5_model.outputs)):
		out_nodes.append(out_prefix + str(i + 1))
		tf.identity(h5_model.output[i],out_prefix + str(i + 1))
	sess = K.get_session()
	from tensorflow.python.framework import graph_util,graph_io
	init_graph = sess.graph.as_graph_def()
	main_graph = graph_util.convert_variables_to_constants(sess,init_graph,out_nodes)
	graph_io.write_graph(main_graph,output_dir,name = model_name,as_text = False)


if __name__ == "__main__" :

	parser = argparse.ArgumentParser()
	parser.add_argument("--model_path", help="the h5 model path ")
	parser.add_argument("--model_output_path", help="the pb model outout path ")
	args = parser.parse_args()

	if args.model_path :
		h5_model_path = args.model_path
	else :
		sys.exit("model_path not found ! Please use this format : --model_path")

	if args.model_output_path :
		cut_out = args.model_output_path.rfind('/')
		h5_model_name = args.model_output_path[cut_out+1:]
		h5_model_dir = args.model_output_path[:cut_out]
	else:
		cut_out = h5_model_path.rfind('/')
		suffix_data = h5_model_path[cut_out+1:]
		h5_model_name =  suffix_data[:-2] + 'pb'
		h5_model_dir = './'

	h5_model = load_model(h5_model_path)
	h5_to_pb(h5_model, h5_model_dir, h5_model_name)

@ThinkBird 你mnist模型是你们自己训练的还是?

这个mnist代码是在自己机器上进行训练的

@ThinkBird 我明天找一个mnist的转换一下,我之前是转换过的

非常感谢!
我这个mnist代码,复制后可以直接运行(tensorflow 1.10),你也可以试一下

@ThinkBird 我会尝试转换的今天,有结果会在这里回复你

请教: MNIST的转换是否完成? 项目进度较紧,急需协助,谢谢!

@ThinkBird 我这边可以转换,使用的是一个之前其他用户提供的mnist的h5文件

h5转pb是没有问题的,conversion_scripts 文件夹下 0_import_model.sh 会有错误提示。
另外,由于没有详细的api说明书,case 代码也不太会改。
能否劳烦一下,把mnist的整个运行过程发一下?

@ThinkBird 没有其他的啊,就是转成pb,然后用转换工具转

放在vim3/vim3L上能正常运行并识别摄像头上的手写字体?

@ThinkBird 之前测试过是可以识别的

劳烦给下源码,我们这边调试的很辛苦 :hot_face:

@ThinkBird 我是直接使用的其他用户h5文件。没有源代码。

@ThinkBird

详细的api文档目前没有,这个转换出来的c的代码你们需要直接阅读源码,默认的到处代码其实就是一个top5.你们需要的函数接口,可以看一下vnn开头的文件,函数的接口都在里面了。

我可以把h5文件给你,但是这个并不是源码,源码我也没有。File on MEGA