承前 接上节代码『TensotFlow』RNN中文文本_上, import numpy as np import tensorflow as tf from collections import Counter poetry_file = 'poetry.txt' poetrys = [] with open(poetry_file, 'r', encoding='utf-8') as f: for line in f: try: title, content = line.strip().sp…
『PyTorch』第四弹_通过LeNet初识pytorch神经网络_上 # Author : Hellcat # Time : 2018/2/11 import torch as t import torch.nn as nn import torch.nn.functional as F class LeNet(nn.Module): def __init__(self): super(LeNet,self).__init__() self.conv1 = nn.Conv2d(3, 6, 5)…
首更: 由于TensorFlow的奇怪形式,所以载入保存的是sess,把会话中当前激活的变量保存下来,所以必须保证(其他网络也要求这个)保存网络和载入网络的结构一致,且变量名称必须一致,这是caffe...好吧,caffe也没有这种python风格的设定... 废话少说,导入包: import numpy as np import tensorflow as tf 保存会话: W = tf.Variable([[1,2,3],[4,5,6]],dtype=tf.float32) b = tf.V…
多变量赋值 a = [1,2,(3,4)] b,c,d = a print(b,c,d) b,c,(d,e) = a print(b,c,d,e) 1 2 (3, 4) 1 2 3 4 a = "zxc" b,c,d = a print(b,c,d) z x c *:集成不定长元素 & 集合型实参展开为多个虚参 record = ('Dave', 'dave@example.com', '773-555-1212', '847-555-1212') name, email, *…
一.collections.defaultdict:多值映射字典 defaultdict省去了初始化容器的过程,会默认value对象为指定类型的容器 指定list时可以使用.append, from collections import defaultdict d = defaultdict(list) d['a'].append(1) d defaultdict(list, {'a': [1]}) 指定set时可以使用.add, d = defaultdict(set) d['a'].add(…