View pytorch_imagenet.py
import time | |
import shutil | |
import os | |
import torch | |
import torch.nn as nn | |
import torchvision.datasets as datasets | |
import torchvision.transforms as transforms | |
import torchvision.models as models | |
import torch.backends.cudnn as cudnn |
View anaconda_sync.py
#!/usr/bin/env python3 | |
import os | |
import json | |
import hashlib | |
import tempfile | |
import shutil | |
import logging | |
import subprocess as sp | |
from pathlib import Path | |
from email.utils import parsedate_to_datetime |
View deep_feedforward_networks_03.py
import tensorflow as tf | |
# 输入训练数据,这里是python的list, 也可以定义为numpy的ndarray | |
x_data = [[1., 0.], [0., 1.], [0., 0.], [1., 1.]] | |
x = tf.placeholder(tf.float32, shape=[None, 2]) # 定义占位符,占位符在运行图的时候必须feed数据 | |
y_data = [[1], [1], [0], [0]] # 训练数据的标签,注意维度 | |
y = tf.placeholder(tf.float32, shape=[None, 1]) | |
# 定义variables,在运行图的过程中会被按照优化目标改变和保存 | |
weights = {'w1': tf.Variable(tf.random_normal([2, 16])), | |
'w2': tf.Variable(tf.random_normal([16, 1]))} |
View deep_feedforward_networks_02.py
with tf.Session() as sess: | |
sess.run(tf.global_variables_initializer()) | |
for i in range(1000): | |
for j in range(4): | |
sess.run(train, feed_dict={x: np.expand_dims(X[j], 0), y: np.expand_dims(Y[j], 0)}) | |
loss_ = sess.run(loss, feed_dict={x: X, y: Y}) | |
print("step: %d, loss: %.3f" % (i, loss_)) | |
print("X: %r" % X) | |
print("pred: %r" % sess.run(out, feed_dict={x: X})) |
View deep_feedforward_networks_01.py
import tensorflow as tf | |
import numpy as np | |
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) | |
Y = np.array([[0], [1], [1], [0]]) | |
x = tf.placeholder(tf.float32, [None, 2]) | |
y = tf.placeholder(tf.float32, [None, 1]) | |
w = tf.Variable(tf.random_normal([2, 1])) |