Tensorflow最初接触


完整报错:
Cannot uninstall ‘html5lib’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Tensorflow下载中所遇到的问题1.0

1、问题的产生:
由于刚学习使用这种框架,当我用它做一些简单训练时,出现了ImportError:DLL load failed动态链接库(DLL)初始化例程失败
然后我查询网上,说是版本xxx不支持,然后需要下载老版本,我就把我的1.10版本卸载了,下载老版本时出现如题目的问题

2、问题的解决:
https://blog.csdn.net/qq_20373723/article/details/80323344
题目中问题可以参见上方地址,由于原地址是图片,我有好几次没有加载出来,所以这里给出一下简单的总结:

找到anaconda->Lib->site-packages->html5lib-0.999-py3.6.egg-info

删除它

然后就可以成功下载咯~

3、不知所云:
实验代码如下↓来自:https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/2-2-example2/ 视频提供,是像我这种初学者的好去处~

import tensorflow as tf
import numpy as np
#create data
x_data=np.random.rand(100).astype(np.float32)
y_data=x_data*0.1+0.3

###create tensorflow structure start###
Weights=tf.Variable(tf.random_uniform(-1.0,1.0))
biases=tf.Variable(tf.zeros[1])

y=Weights*x_data+biases

loss=tf.reduce_mean(tf.square(y-y_data))
optimizer=tf.train.GradientDescentOptimizer(0.5)
train=optimizer.minimize(loss)

init=tf.initialize_all_variables()
###create tensorflow structure start###

sess=tf.Session()
sess.run(init)  #Very important

for step in range(201):
    sess.run(train)
    if step%20==0 :
        print(step,sess.run(Weights),sess.run(biases))

再次出现报错:
TypeError: Value passed to parameter ‘shape’ has DataType float32 not in list of allowed values: int32, int64

解决:

###create tensorflow structure start###
Weights=tf.Variable(tf.random_uniform([1],-1.0,1.0))
biases=tf.Variable(tf.zeros[1])

然鹅……高兴太早,出现TypeError: ‘function’ object is not subscriptable错误

biases=tf.Variable(tf.zeros([1])) #tf.zeros([x]) Attention!

好了~终于输出结果了!
附完整修改好代码:

import tensorflow as tf
import numpy as np
#creat data
x_data=np.random.rand(100).astype(np.float32)
y_data=x_data*0.1+0.3

###create tensorflow structure start###
Weights=tf.Variable(tf.random_uniform([1],-1.0,1.0))
biases=tf.Variable(tf.zeros([1]))

y=Weights*x_data+biases

loss=tf.reduce_mean(tf.square(y-y_data))
optimizer=tf.train.GradientDescentOptimizer(0.5)
train=optimizer.minimize(loss)

# init = tf.initialize_all_variables() # tf 马上就要废弃这种写法
init = tf.global_variables_initializer()  # 替换成这样就好
###create tensorflow structure start###

sess=tf.Session()
sess.run(init)  #Very important

for step in range(201):
    sess.run(train)
    if step%20==0 :
        print(step,sess.run(Weights),sess.run(biases))

结果:(不想弄格式了,就酱~)
0 [-0.3792392] [0.73718214]
20 [-0.06252494] [0.38364783]
40 [0.05255738] [0.32441762]
60 [0.08615105] [0.30712774]
80 [0.09595735] [0.30208066]
100 [0.09881992] [0.30060738]
120 [0.09965552] [0.3001773]
140 [0.09989945] [0.30005178]
160 [0.09997065] [0.30001512]
180 [0.09999145] [0.30000442]
200 [0.0999975] [0.3000013]

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值