one_with_two 2021-03-13 21:59 采纳率: 0%
浏览 93

tensor计算一次简单卷积和池化,一直计算不出来结果

配置:gpu:3060,cuda:10.0,cudnn:7.4,pyrhon:3.7,anaconda3,tensor:1.14。一直计算不出结果!

import tensorflow as tf
import numpy as np

M = np.array([[-2, 2, 0, 3], [1, 2, -1, 2], [0, -1, 1, 0]]).reshape(1, 3, 4, 1)
filter_weight = tf.get_variable("weights", [2, 2, 1, 1], initializer=tf.constant_initializer([[2, 0],[-1, 1]]))
biases = tf.get_variable("biases", [1], initializer=tf.constant_initializer(1))
# 设置初始值,卷积核大小,tf.get_variable为共享数据

x = tf.placeholder("float32", shape=[1, None, None, 1])
# 设置输入形式

conv = tf.nn.conv2d(x, filter_weight, strides=[1, 1, 1, 1], padding="SAME")
add_bias = tf.nn.bias_add(conv, biases)
# 设置卷积计算和偏置计算。

pool = tf.nn.max_pool(add_bias, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")

with tf.Session() as sess:
    tf.global_variables_initializer().run()
    M_conv = sess.run(add_bias, feed_dict={x: M})
    M_pool = sess.run(pool, feed_dict={x:  M})
    print("after average pooled:\n", M_conv)
    print("after average pooled:\n",M_pool)

显示:

E:\anacondafile\envs\TENSOR-1\python.exe E:/yolo/tensorflow/7.3.3.py
WARNING:tensorflow:From E:/yolo/tensorflow/7.3.3.py:5: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.

WARNING:tensorflow:From E:/yolo/tensorflow/7.3.3.py:9: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From E:/yolo/tensorflow/7.3.3.py:16: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From E:/yolo/tensorflow/7.3.3.py:18: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2021-03-13 21:46:15.538508: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll
2021-03-13 21:46:15.578155: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
name: GeForce RTX 3060 major: 8 minor: 6 memoryClockRate(GHz): 1.777
pciBusID: 0000:01:00.0
2021-03-13 21:46:15.578367: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2021-03-13 21:46:15.578557: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2021-03-13 21:46:15.578948: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-03-13 21:46:15.581663: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
name: GeForce RTX 3060 major: 8 minor: 6 memoryClockRate(GHz): 1.777
pciBusID: 0000:01:00.0
2021-03-13 21:46:15.581870: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2021-03-13 21:46:15.582042: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2021-03-13 21:47:57.493920: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-03-13 21:47:57.494087: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0 
2021-03-13 21:47:57.494182: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N 
2021-03-13 21:47:57.494444: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10627 MB memory) -> physical GPU (device: 0, name: GeForce RTX 3060, pci bus id: 0000:01:00.0, compute capability: 8.6)
WARNING:tensorflow:From E:/yolo/tensorflow/7.3.3.py:19: The name tf.global_variables_initializer is deprecated. Please use tf.compat.v1.global_variables_initializer instead.


Process finished with exit code -1

  • 写回答

1条回答 默认 最新

  • 爱晚乏客游 2021-03-14 01:56
    关注

    我这里试了下可以运行的。所以应该是你的显卡驱动,cuda或者cudnn的问题了。你可以试试看tensorflow设置cpu运行,如果cpu没问题的话就是你的cuda或者cudnn甚至是显卡驱动的问题了。

    with tf.Session() as sess:
        with tf.device('/cpu:0'):
    after average pooled:
     [[[[-2.]
       [ 2.]
       [ 4.]
       [ 5.]]
    
      [[ 2.]
       [ 7.]
       [-2.]
       [ 5.]]
    
      [[ 1.]
       [-1.]
       [ 3.]
       [ 1.]]]]
    after average pooled:
     [[[[7.]
       [5.]]
    
      [[1.]
       [3.]]]]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用mmpose库时出现了问题
  • ¥15 IRI2016模型matlab运行报错
  • ¥50 bat怎么设置电脑后台自动点击网页指定词运行脚本,输入指定网页链接,指定点击词,指定间隔时间,指定网页出现的词,指定网页出现词出现后后点击锁定,放在后台运行不影响前台鼠标工作
  • ¥20 20CrMnMo的高温变形抗力
  • ¥15 RTX3.6 5565驱动中断报错
  • ¥50 带防重放token(Antireplay-Token)的网站怎么用Python发送请求
  • ¥15 visa版本没问题,串口调试助手调试串口正常使用,但是labview刷新不出来
  • ¥15 java MQTT SSL证书
  • ¥20 求一个手机号或者Wxid转微信号的工具
  • ¥15 对email表单做了一般邮箱正则校验,现在需要额外输入为hotmail或outlook、gmail时做特定邮箱校验,不符合提示出来。并且保证不影响其他正确的邮箱格式通过校验,通过不会提示。