测试tensorflow是否安装正确代码

# -*- coding: utf-8 -*-
"""
测试tensorflow版是否安装正确
"""

import tensorflow as tf
import numpy as np
import time

value = np.random.randn(5000, 1000)
a = tf.constant(value)

b = a * a

c =0
tic = time.time()
with tf.Session() as sess:
        for i in range(1000):
            sess.run(b)

            c+=1
            if c%100 == 0:

                d = c / 10
                # print(d)
                print("计算进行%s%%" % d)

toc = time.time()
t_cost = toc - tic

print("测试所用时间%s"%t_cost)
print("Ubuntu测试时间为7.99727988243103")

运行效果

 

2019-02-22 21:55:18.595152: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-02-22 21:55:18.673060: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:964] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-02-22 21:55:18.673437: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1411] Found device 0 with properties: 
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.62
pciBusID: 0000:01:00.0
totalMemory: 3.95GiB freeMemory: 3.53GiB
2019-02-22 21:55:18.673448: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1490] Adding visible gpu devices: 0
2019-02-22 21:55:18.881182: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-02-22 21:55:18.881208: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977]      0 
2019-02-22 21:55:18.881213: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0:   N 
2019-02-22 21:55:18.881315: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1103] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3247 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
计算进行10.0%
计算进行20.0%
计算进行30.0%
计算进行40.0%
计算进行50.0%
计算进行60.0%
计算进行70.0%
计算进行80.0%
计算进行90.0%
计算进行100.0%
测试所用时间8.04111933708191
Ubuntu上测试时间为7.99727988243103

Process finished with exit code 0
 

你可能感兴趣的:(机器学习,人工智能)