配置: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