模型 windows训练 linux部署,Tensorflow模型保存与加载

一.保存模型所谓的模型保存,也就是冻结(freeze)模型,将该模型的图结构和该模型的权重固化到一起。二.加载模型在恢复模型的时候,通过get_tensor_by_name获得模型中的变量,然后对变量进行赋值。三.代码实例Demo1:单纯地训练,不生成模型#-*- coding:utf-8 -*-import tensorflow as tfimport numpy as npwith tf.va...
摘要由CSDN通过智能技术生成

一.保存模型

所谓的模型保存,也就是冻结(freeze)模型,将该模型的图结构和该模型的权重固化到一起。

二.加载模型

在恢复模型的时候,通过get_tensor_by_name获得模型中的变量,然后对变量进行赋值。

三.代码实例

Demo1:单纯地训练,不生成模型

#-*- coding:utf-8 -*-

import tensorflow as tf

import numpy as np

with tf.variable_scope('Placeholder'):

inputs_placeholder = tf.placeholder(tf.float32,name = 'inputs_placeholder',shape = [None,10])

labels_placeholder = tf.placeholder(tf.float32,name = 'labels_placeholder',shape = [None,1])

with tf.variable_scope('NN'):

W1 = tf.get_variable('W1',shape = [10,1],initializer = tf.random_normal_initializer(stddev = 1e-1))

b1 = tf.get_variable('b1',shape = [1],initializer = tf.constant_initializer(0.1))

W2 = tf.get_variable('W2',shape = [10,1],initializer = tf.random_normal_initializer(stddev = 1e-1))

b2 = tf.get_variable('b2',shape = [1],initializer = tf.constant_initializer(0.1))

a1 = tf.nn.relu(tf.matmul(inputs_placeholder,W1) + b1)

a2 = tf.nn.relu(tf.matmul(inputs_placeholder,W2) + b2)

y = tf.div(tf.add(a1,a2),2)

with tf.variable_scope('Loss'):

loss = tf.red

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值