pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

Tensorflow 似乎使用的是系統內存而不是 GPU,并且

Tensorflow seems to be using system memory not GPU, and the Program stops after global_variable_inititializer()(Tensorflow 似乎使用的是系統內存而不是 GPU,并且程序在 global_variable_initializer() 之后停止) - IT屋-程序
本文介紹了Tensorflow 似乎使用的是系統內存而不是 GPU,并且程序在 global_variable_initializer() 之后停止的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我剛剛為我的桌面添加了一個新的 GTX 1070 Founders Addition,我正在嘗試在這個新的 GPU 上運行 tensorflow.我正在使用 tensorflow.device() 在我的 GPU 上運行 tensorflow,但似乎沒有發生這種情況.相反,它使用的是 cpu,而我的幾乎所有系統都使用 8GB 內存.這是我的代碼:

I just got a new GTX 1070 Founders Addition for my desktop, and I am trying to run tensorflow on this new GPU. I am using tensorflow.device() to run tensorflow on my GPU, but it seems like this is not happening. Instead it is using cpu, and almost all of my systems 8GB of ram. Here is my code:

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import os
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
import matplotlib.image as mpimg
import math

print("

")
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
#
with tf.device("/gpu:0"):
    # Helper Function To Print Percentage
    def showPercent(num, den, roundAmount):
        print(  str( round((num / den) * roundAmount )/roundAmount ) + " % ", end="
")
    # Defince The Number Of Images To Get
    def getFile(dir, getEveryNthLine):
        allFiles = list(os.listdir(dir))
        fileNameList = []

        numOfFiles = len(allFiles)
        i = 0
        for fichier in allFiles:
            if(i % 100 == 0):
                showPercent(i, numOfFiles, 100)

            if(i % getEveryNthLine == 0):
                if(fichier.endswith(".png")):
                    fileNameList.append(dir + "/" + fichier[0:-4])
            i += 1
        return fileNameList

    # Other Helper Functions
    def init_weights(shape):
        init_random_dist = tf.truncated_normal(shape, stddev=0.1, dtype=tf.float16)
        return tf.Variable(init_random_dist)
    def init_bias(shape):
        init_bias_vals = tf.constant(0.1, shape=shape, dtype=tf.float16)
        return tf.Variable(init_bias_vals)
    def conv2d(x, W):
        # x --> [batch, H, W, Channels]
        # W --> [filter H, filter W, Channels IN, Channels Out]

        return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding="SAME")
    def max_pool_2by2(x):
        # x --> [batch, H, W, Channels]
        return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")
    def convolutional_layer(input_x, shape):
        W = init_weights(shape)
        b = init_bias([ shape[3] ])
        return tf.nn.relu(conv2d(input_x, W) + b)
    def normal_full_layer(input_layer, size):
        input_size = int(input_layer.get_shape()[1])
        W = init_weights([input_size, size])
        b = init_bias([size])
        return tf.matmul(input_layer, W) + b

    print("Getting Images")
    fileNameList = getFile("F:cartoonset10k-small", 1000)
    print("
loaded " + str(len(fileNameList)) + " files")

    print("Defining Placeholders")
    x_ph = tf.placeholder(tf.float16, shape=[None, 400, 400, 4])
    y_ph = tf.placeholder(tf.float16, shape=[None])

    print("Defining Conv and Pool layer 1")
    convo_1 = convolutional_layer(x_ph, shape=[5, 5, 4, 32])
    convo_1_pooling = max_pool_2by2(convo_1)

    print("Defining Conv and Pool layer 2")
    convo_2 = convolutional_layer(convo_1_pooling, shape=[5, 5, 32, 64])
    convo_2_pooling = max_pool_2by2(convo_2)

    print("Define Flat later and a Full layer")
    convo_2_flat = tf.reshape(convo_2_pooling, [-1, 400 * 400 * 64])
    full_layer_one = tf.nn.relu(normal_full_layer(convo_2_flat, 1024))
    y_pred = full_layer_one # Add Dropout Later

    def getLabels(filePath):
        df = []
        with open(filePath, "r") as file:
            for line in list(file):
                tempList = line.replace("
", "").replace('"', "").replace(" ", "").split(",")
                df.append({
                    "attr": tempList[0],
                    "value":int(tempList[1]),
                    "maxValue":int(tempList[2])
                })
        return df

    print("
Splitting And Formating X, and Y Data")
    x_data = []
    y_data = []
    numOfFiles = len(fileNameList)
    i = 0
    for file in fileNameList:
        if i % 10 == 0:
            showPercent(i, numOfFiles, 100)
        x_data.append(mpimg.imread(file + ".png"))
        y_data.append(pd.DataFrame(getLabels(file + ".csv"))["value"][0])
        i += 1

    print("
Conveting x_data to list")
    i = 0
    for indx in range(len(x_data)):
        if i % 10 == 0:
            showPercent(i, numOfFiles, 100)
        x_data[indx] = x_data[indx].tolist()
        i += 1

    print("

Performing Train Test Split")
    train_x, test_x, train_y, test_y = train_test_split(x_data, y_data, test_size=0.2)

    print("Defining Loss And Optimizer")
    cross_entropy = tf.reduce_mean(
        tf.nn.softmax_cross_entropy_with_logits_v2(
            labels=y_ph,
            logits=y_pred
        )
    )
    optimizer = tf.train.AdadeltaOptimizer(learning_rate=0.001)
    train = optimizer.minimize(cross_entropy)

    print("Define Var Init")
    init = tf.global_variables_initializer()
    with tf.Session() as sess:
        print("Checkpoint Before Initializer")
        sess.run(init)
        print("Checkpoint After Initializer")
        batch_size = 8
        steps = 1
        i = 0
        for i in range(steps):
            if i % 10:
                print(i / 100, end="
")

            batch_x = []
            i = 0
            for i in np.random.randint(len(train_x), size=batch_size):
                showPercent(i, len(train_x), 100)
                train_x[i]
            batch_x = [train_x[i] for i in np.random.randint(len(train_x), size=batch_size) ]
            batch_y = [train_y[i] for i in np.random.randint(len(train_y), size=batch_size) ]
            print(sess.run(train, {
                x_ph:train_x,
                y_ph:train_y,
            }))

如果你運行它,當我運行 global_variable_initializer() 時,這個程序似乎退出了.它還在終端中打印:20971520000 的分配超過了系統內存的 10%. 在查看我的任務管理器時,我看到了這個:

If you run this, this program seems to quit when I run global_variable_initializer(). It also prints in the terminal: Allocation of 20971520000 exceeds 10% of system memory. When looking at my task manager, I see this:

該程序占用了我的大量 CPU.

程序占用了我的大量內存.

程序沒有使用我的 GPU.

我不知道為什么會發生這種情況.我正在使用 anaconda 環境,并安裝了 tensorflow-gpu.我非常感謝任何人的建議和幫助.

I am not shore why this is happening. I am using an anaconda environment, and have installed tensorflow-gpu. I would really appreciate anyones suggestions and help.

另外,當我運行它時,程序在 global_variable_initializer() 之后停止.我不確定這是否與上述問題有關.

In addition, when I run this, the program stops after global_variable_initializer(). I am not sure if this is related to the problem above.

Tensorflow 是 1.12 版.CUDA 是 10.0.130 版本.

Tensorflow is version 1.12. CUDA is version 10.0.130.

我們將不勝感激.

推薦答案

嘗試用這個簡單的例子比較時間(GPU vs CPU):

Try compare time (GPU vs CPU) with this simple example:

import tensorflow as tf
mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

def create_model():
    model = tf.keras.models.Sequential([
      tf.keras.layers.Flatten(input_shape=(28, 28)),
      tf.keras.layers.Dense(512, activation=tf.nn.relu),
      tf.keras.layers.Dropout(0.2),
      tf.keras.layers.Dense(10, activation=tf.nn.softmax)
    ])
    model.compile(optimizer='adam',
                  loss='sparse_categorical_crossentropy',
                  metrics=['accuracy'])
    return model    

epoch = 3

print('GPU:')
with tf.device('/gpu:0'):   
    model = create_model()

    model.fit(x_train, y_train, epochs=epoch)

print('
CPU:')
with tf.device('/cpu:0'):   
    model = create_model()

    model.fit(x_train, y_train, epochs=epoch)

這篇關于Tensorflow 似乎使用的是系統內存而不是 GPU,并且程序在 global_variable_initializer() 之后停止的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to install Selenium in a conda environment?(如何在 conda 環境中安裝 Selenium?)
get the CUDA and CUDNN version on windows with Anaconda installe(使用 Anaconda installe 在 Windows 上獲取 CUDA 和 CUDNN 版本)
How can I download Anaconda for python 3.6(如何下載適用于 python 3.6 的 Anaconda)
Using two different Python Distributions(使用兩個不同的 Python 發行版)
How can I install Anaconda aside an existing pyenv installation on OSX?(除了 OSX 上現有的 pyenv 安裝之外,如何安裝 Anaconda?)
Permanently set Python path for Anaconda within Cygwin(在 Cygwin 中為 Anaconda 永久設置 Python 路徑)
主站蜘蛛池模板: 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 山东聚盛新型材料有限公司-纳米防腐隔热彩铝板和纳米防腐隔热板以及钛锡板、PVDF氟膜板供应商 | 丽陂特官网_手机信号屏蔽器_Wifi信号干扰器厂家_学校考场工厂会议室屏蔽仪 | 带压开孔_带压堵漏_带压封堵-菏泽金升管道工程有限公司 | 压力变送器-上海武锐自动化设备有限公司| 撕碎机_轮胎破碎机_粉碎机_回收生产线厂家_东莞华达机械有限公司 | LINK FASHION 童装·青少年装展| 食安观察网| 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | YJLV22铝芯铠装电缆-MYPTJ矿用高压橡套电缆-天津市电缆总厂 | 密集架|电动密集架|移动密集架|黑龙江档案密集架-大量现货厂家销售 | 山东风淋室_201/304不锈钢风淋室净化设备厂家-盛之源风淋室厂家 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 粒米特测控技术(上海)有限公司-测功机_减速机测试台_电机测试台 | 水篦子|雨篦子|镀锌格栅雨水篦子|不锈钢排水篦子|地下车库水箅子—安平县云航丝网制品厂 | 青岛美佳乐清洁工程有限公司|青岛油烟管道清洗|酒店|企事业单位|学校工厂厨房|青岛油烟管道清洗 插针变压器-家用电器变压器-工业空调变压器-CD型电抗器-余姚市中驰电器有限公司 | 密集架-手摇-智能-移动-价格_内蒙古档案密集架生产厂家 | 好看的韩国漫画_韩漫在线免费阅读-汗汗漫画 | Jaeaiot捷易科技-英伟达AI显卡模组/GPU整机服务器供应商 | 爱佩恒温恒湿测试箱|高低温实验箱|高低温冲击试验箱|冷热冲击试验箱-您身边的模拟环境试验设备技术专家-合作热线:400-6727-800-广东爱佩试验设备有限公司 | 南京兰江泵业有限公司-水解酸化池潜水搅拌机-絮凝反应池搅拌机-好氧区潜水推进器 | 上海恒驭仪器有限公司-实验室平板硫化机-小型平板硫化机-全自动平板硫化机 | 过跨车_过跨电瓶车_过跨转运车_横移电动平车_厂区转运车_无轨转运车 | 氢氧化钾厂家直销批发-济南金昊化工有限公司 | 手术室净化厂家-成都做医院净化工程的公司-四川华锐-15年特殊科室建设经验 | 振动台-振动试验台-振动冲击台-广东剑乔试验设备有限公司 | 东莞海恒试验仪器设备有限公司 | 合肥弱电工程_安徽安防工程_智能化工程公司-合肥雷润 | 高温热泵烘干机,高温烘干热泵,热水设备机组_正旭热泵 | 精雕机-火花机-精雕机 cnc-高速精雕机-电火花机-广东鼎拓机械科技有限公司 | 智能化的检漏仪_气密性测试仪_流量测试仪_流阻阻力测试仪_呼吸管快速检漏仪_连接器防水测试仪_车载镜头测试仪_奥图自动化科技 | 仓储货架_南京货架_钢制托盘_仓储笼_隔离网_环球零件盒_诺力液压车_货架-南京一品仓储设备制造公司 | 昆明化妆培训-纹绣美甲-美容美牙培训-昆明博澜培训学校 | 全钢实验台,实验室工作台厂家-无锡市辰之航装饰材料有限公司 | 上海璟文空运首页_一级航空货运代理公司_机场快递当日达 | 云南丰泰挖掘机修理厂-挖掘机维修,翻新,再制造的大型企业-云南丰泰工程机械维修有限公司 | 新中天检测有限公司青岛分公司-山东|菏泽|济南|潍坊|泰安防雷检测验收 | 洛阳防爆合格证办理-洛阳防爆认证机构-洛阳申请国家防爆合格证-洛阳本安防爆认证代办-洛阳沪南抚防爆电气技术服务有限公司 | 高温高压釜(氢化反应釜)百科 | 新中天检测有限公司青岛分公司-山东|菏泽|济南|潍坊|泰安防雷检测验收 | 砖机托板价格|免烧砖托板|空心砖托板厂家_山东宏升砖机托板厂 | 溶氧传感器-pH传感器|哈美顿(hamilton) |