当前位置: 首页 > news >正文

淘宝客网站要多大空间漳州哪里做网站

淘宝客网站要多大空间,漳州哪里做网站,wordpress 文章与页面,互联网营销师证书查询入口系列文章 【如何训练一个中译英翻译器】LSTM机器翻译seq2seq字符编码#xff08;一#xff09; 【如何训练一个中译英翻译器】LSTM机器翻译模型训练与保存#xff08;二#xff09; 【如何训练一个中译英翻译器】LSTM机器翻译模型部署#xff08;三#xff09; 【如何训练…系列文章 【如何训练一个中译英翻译器】LSTM机器翻译seq2seq字符编码一 【如何训练一个中译英翻译器】LSTM机器翻译模型训练与保存二 【如何训练一个中译英翻译器】LSTM机器翻译模型部署三 【如何训练一个中译英翻译器】LSTM机器翻译模型部署之onnxpython四 目录 一、事情准备二、模型转换三、ncnn模型加载与推理python版 一、事情准备 这篇是在【如何训练一个中译英翻译器】LSTM机器翻译模型部署之onnxpython四的基础上进行的要用到文件为 input_words.txt target_words.txt config.json encoder_model-sim.onnx decoder_model-sim.onnx 其中的onnx就是用来转为ncnn模型的这里借助了onnx这个中间商所以前面我们需要先通过onnxsim对模型进行simplify要不然在模型转换时会出现op不支持的情况模型转换不仅有中间商这个例子目前还可以通过pnnx直接将pytorch模型转为ncnn感兴趣的小伙伴可以去折腾下 老规矩先给出工具 onnx2ncnnhttps://github.com/Tencent/ncnn netronhttps://netron.app二、模型转换 这里进行onnx转ncnn通过命令进行转换 onnx2ncnn onnxModel/encoder_model-sim.onnx ncnnModel/encoder_model.param ncnnModel/encoder_model.bin onnx2ncnn onnxModel/decoder_model-sim.onnx ncnnModel/decoder_model.param ncnnModel/decoder_model.bin转换成功可以看到 转换之后可以对模型进行优化但是奇怪的是这里优化了不起作用去不了MemoryData这些没用的op ncnnoptimize ncnnModel/encoder_model.param ncnnModel/encoder_model.bin ncnnModel/encoder_model.param ncnnModel/encoder_model.bin 1 ncnnoptimize ncnnModel/decoder_model.param ncnnModel/decoder_model.bin ncnnModel/decoder_model.param ncnnModel/decoder_model.bin 1三、ncnn模型加载与推理python版 跟onnx的推理比较类似就是函数的调用方法有点不同这里先用python实现验证下是否没问题方面后面部署到其它端比如android。 主要包括模型加载、推理模型搭建跟模型推理但要注意的是这里的输入输出名称需要在param这个文件里面获取。 采用netron分别查看encoder与decoder的网络结构获取输入输出名称 有点问题先把调试代码贴在下面了 import numpy as np import ncnn# 加载字符 # 从 input_words.txt 文件中读取字符串 with open(config/input_words.txt, r) as f:input_words f.readlines()input_characters [line.rstrip(\n) for line in input_words]# 从 target_words.txt 文件中读取字符串 with open(config/target_words.txt, r, newline) as f:target_words [line.strip() for line in f.readlines()]target_characters [char.replace(\\t, \t).replace(\\n, \n) for char in target_words]#字符处理以方便进行编码 input_token_index dict([(char, i) for i, char in enumerate(input_characters)]) target_token_index dict([(char, i) for i, char in enumerate(target_characters)])# something readable. reverse_input_char_index dict((i, char) for char, i in input_token_index.items()) reverse_target_char_index dict((i, char) for char, i in target_token_index.items()) num_encoder_tokens len(input_characters) # 英文字符数量 num_decoder_tokens len(target_characters) # 中文文字数量import json with open(config/config.json, r) as file:loaded_data json.load(file)# 从加载的数据中获取max_encoder_seq_length和max_decoder_seq_length的值 max_encoder_seq_length loaded_data[max_encoder_seq_length] max_decoder_seq_length loaded_data[max_decoder_seq_length]encoder_model ncnn.Net()encoder_model.load_param(ncnnModel/encoder_model.param) encoder_model.load_model(ncnnModel/encoder_model.bin)decoder_model ncnn.Net() decoder_model.load_param(ncnnModel/decoder_model.param) decoder_model.load_model(ncnnModel/decoder_model.bin)def decode_sequence(input_seq):# Encode the input as state vectors.ex_encoder encoder_model.create_extractor()ex_encoder.input(input_1, ncnn.Mat(input_seq))_, LSTM_1 ex_encoder.extract(LSTM__31:1)_, LSTM_2 ex_encoder.extract(LSTM__31:2)print(LSTM_1)print(LSTM_2)# Generate empty target sequence of length 1.target_seq np.zeros((1, 1, 849))# Populate the first character of target sequence with the start character.target_seq[0, 0, target_token_index[\t]] 1.# this target_seq you can treat as initial state# Sampling loop for a batch of sequences# (to simplify, here we assume a batch of size 1).stop_condition Falsedecoded_sentence while not stop_condition:ex_decoder decoder_model.create_extractor()print(ncnn.Mat(target_seq))print(---------)ex_decoder.input(input_2, ncnn.Mat(target_seq))ex_decoder.input(input_3, LSTM_1)ex_decoder.input(input_4, LSTM_2)_, output_tokens ex_decoder.extract(dense)_, h ex_decoder.extract(lstm_1)_, c ex_decoder.extract(lstm_1_1)print(output_tokens)print(h)print(c)print(fdsf)output_tokens np.array(output_tokens)h np.array(h)c np.array(c)print(output_tokens.shape)print(output_tokens.shape)print(h.shape)print(c.shape)#print(gfdgd)#output_tokens, h, c decoder_model.predict([target_seq] states_value)# Sample a token# argmax: Returns the indices of the maximum values along an axis# just like find the most possible charsampled_token_index np.argmax(output_tokens[0, -1, :])# find char using indexsampled_char reverse_target_char_index[sampled_token_index]# and append sentencedecoded_sentence sampled_char# Exit condition: either hit max length# or find stop character.if (sampled_char \n or len(decoded_sentence) max_decoder_seq_length):stop_condition True# Update the target sequence (of length 1).# append then ?# creating another new target_seq# and this time assume sampled_token_index to 1.0target_seq np.zeros((1, 1, num_decoder_tokens))target_seq[0, 0, sampled_token_index] 1.# Update states# update states, frome the front partsstates_value [h, c]return decoded_sentenceimport numpy as npinput_text Call me. encoder_input_data np.zeros((1,max_encoder_seq_length, num_encoder_tokens),dtypefloat32) for t, char in enumerate(input_text):print(char)# 3D vector only z-index has char its value equals 1.0encoder_input_data[0,t, input_token_index[char]] 1.input_seq encoder_input_data decoded_sentence decode_sequence(input_seq) print(-) print(Input sentence:, input_text) print(Decoded sentence:, decoded_sentence)
http://wiki.neutronadmin.com/news/280580/

相关文章:

  • 公司网站建设方案详细方案大型购物网站建设费用
  • 南宁网站建设速成培训班浙江网站设计公司
  • 家具网站建设规划书无极招聘信息网
  • 网站建设与推广的销售北京做网站的公司拟
  • 建设银行官网首页网站购纪念币ueditor for wordpress
  • 免费的网站推广重庆网站建设坤思特
  • 网站价值 批量查询花生壳免费域名注册
  • 东盟建设投资有限公司网站顺企网怎么样
  • 网站建设需要经过哪几个步骤关键词优化推广策略
  • 基层建设检索网站wordpress文章密码爆破
  • 网站栏目类型做网站用什么颜色好
  • 公司网站建设服务机构wordpress 手机 重定向 子目录
  • 做网站要注意哪些企业网站开发环境
  • 推荐网站建设服务器wordpress qq登入设置
  • 做百度移动端网站软件下载舟山网站建设开发
  • 专做眼镜的网站建设厅官方网站
  • 官网网站怎么做wordpress主题 可爱
  • 外贸网站建设浩森宇特wordpress邮件发文章
  • 宁波seo排名方案优化搜索引擎优化的报告
  • 外贸平台哪个网站最好不收费企业oa办公系统大概多少钱一套
  • 做网站应该注意哪些问题做电视的视频网站
  • 建设个人网站赚钱的经历黄页号码标记申诉
  • 安徽网站优化好不好wordpress索引
  • 深圳企业网站建设报价php+mysql网站开发
  • 做房产中介需要有内部网站吗wordpress 电商
  • 品牌的三大核心价值无锡网站排名优化费用
  • 重庆建站公司费用网站备案号的区别
  • 给城市建设提议献策的网站字体设计作品赏析
  • 如何做手机网站用于建设教学网站的建站工具有哪些特点
  • 杭州久邦电力建设有限公司网站手机排行榜2021前十名性价比