'Deep Learning'에 해당되는 글 593건

  1. 2016.12.30 Deep Learning Lectures at the University of Oxford by Nando de Freitas
  2. 2016.12.30 Popular HN Deep Learning Stroies
  3. 2016.12.30 tensorflow와 openAI의 gym을 활용하여 강화학습 알고리즘들을 설명하고, 구현해놓은 블로그
  4. 2016.12.30 Introduction to deep learning in python and Matlab
  5. 2016.12.27 인공지능: 변화와 능력개발 Taegyun Jeon
  6. 2016.12.27 인공지능, 기계학습 그리고 딥러닝 6 views Jinwon Lee
  7. 2016.12.26 Electronic health records could be used for the prediction of the future of patient.
  8. 2016.12.23 윈도우에서 python으로 작업시 생긴 문제 질문. 페이스북 ai korea
  9. 2016.12.23 Install Torch, with help from NVIDIA.
  10. 2016.12.22 Theano Tutorials by Ian Goodfellow
  11. 2016.12.20 자신의 기술적 경험이나 지식을 책으로 출간하고 싶어 하는 분들이 많이 있습니다. 이 글에서는 딥러닝의 공부를 시작으로 해서 에스프레소북이라는 전자책 출판
  12. 2016.12.20 Machine Learning with TensorFlow
  13. 2016.12.15 Learning Reinforcement Learning (With Code, Exercises and Solutions)
  14. 2016.12.15 deep-learning-resources
  15. 2016.12.07 cuda gpu compute capability viersion check
  16. 2016.11.30 텐서플로우 0.12.0 RC0 윈도우 버전에서 웹 리소스(HTML, JS) 파일이 없어 텐서보드가 빈화면으로 출력되는 문제 해결
  17. 2016.11.28 Free Deep Learning Books
  18. 2016.11.28 Image Classification and Segmentation with Tensorflow and TF-Slim
  19. 2016.11.28 Keras Tutorial: The Ultimate Beginner’s Guide to Deep Learning in Python
  20. 2016.11.26 Tensorflow and deeplearning without at Ph.D
  21. 2016.11.26 caffe installation ref sites
  22. 2016.11.15 TensorFlow Tutorial 한국어 슬라이드 및 코드
  23. 2016.11.11 Keras Tutorials
  24. 2016.10.31 GTX1070+6700K 설치경험 1
  25. 2016.10.22 Tensorflow v0.10 installed from scratch on Ubuntu 16.04, CUDA 8.0RC+Patch, cuDNN v5.1 with a 1080GTX
  26. 2016.10.22 Ubuntu 16.04에 Tensorflow 설치하기
  27. 2016.10.22 텐서플로우 0.10 + 우분투 16.04 + CUDA 8.0 + 파이썬 3.5 설치
  28. 2016.10.19 Cuda 7.5 download (cuda_7.5.18_linux.run)
  29. 2016.10.19 Where is usr/local?
  30. 2016.10.18 Ubuntu 16.04 LTS 기반 TensorFlow 개발 환경 셋업 (with GPU) 1
http://artificialbrain.xyz/deep-learning-lectures-at-the-university-of-oxford-by-nando-de-freitas/


Posted by uniqueone
,
Popular HN Deep Learning Stroies

Recently, I've seen many stories discussing Deep Learning on HN. Thus, I decided to compile them on a github repo. Hope this helps!

Practical Deep Learning for Coders
Google's Free Deep Learning Course
Free “Deep Learning” Textbook by Goodfellow and Bengio Now Finished
Microsoft releases CNTK, its open source deep learning toolkit, on GitHub
Grokking Deep Learning
Open Sourcing a Deep Learning Solution for Detecting NSFW Images
How a Japanese cucumber farmer is using deep learning and TensorFlow
Deep Learning Papers Reading Roadmap
How Google Translate squeezes deep learning onto a phone
Intel will add deep-learning instructions to its processors
Facebook open-sources deep-learning modules
A Guide to Deep Learning
Deep learning
Major advancements in Deep Learning in 2016
Setting Up a Deep Learning Machine from Scratch
How to Get a Job In Deep Learning
Deep Learning Enables You to Hide Screen When Your Boss Is Approaching
Some of the most important deep learning papers
The Truth About Deep Learning
The Difference Between AI, Machine Learning, and Deep Learning
AI, Deep Learning, and Machine Learning: A Primer [video]
Infrastructure for Deep Learning
Miles Deep – Open Source Porn Video Classifier/Editor with Deep Learning
How to Start Learning Deep Learning
Large Scale Deep Learning – Jeff Dean [pdf]
Deep Learning: An MIT Press Book in Preparation
A 'Brief' History of Neural Nets and Deep Learning
Deep Learning is Easy - Learn Something Harder
Wide and Deep Learning: Better Together with TensorFlow
Radeon Instinct – Optimized Machine and Deep Learning
Paddle: Baidu's open source deep learning framework
Image Completion with Deep Learning in TensorFlow
What is the difference between deep learning and usual machine learning?
Deep Learning with Spark and TensorFlow
Neural Enhance – Super Resolution for images using deep learning
‘Deep learning’ technique enables robot mastery of skills via trial and error
Tensorflow and Deep Learning, Without a PhD, Martin Gorner, Google [video]
Top Deep Learning Projects
Posted by uniqueone
,
안녕하세요.

tensorflow와 openAI의 gym을 활용하여 강화학습 알고리즘들을 설명하고, 구현해놓은 블로그가 있어서 소개드립니다.

https://medium.com/@awjuliani/latest

강화학습 외에도 AI전반에 대해 다루고 계신 분이신데,
내용 및 코드에 대한 설명이 친절하게 잘 되어 있네요.

강화학습 쪽 목차는 다음과 같습니다.

Part 0 — Q-Learning Agents
Part 1 — Two-Armed Bandit
Part 1.5 — Contextual Bandits
Part 2 — Policy-Based Agents
Part 3 — Model-Based RL
Part 4 — Deep Q-Networks and Beyond
Part 5 — Visualizing an Agent’s Thoughts and Actions
Part 6 — Partial Observability and Deep Recurrent Q-Networks
Part 7 — Action-Selection Strategies for Exploration
Part 8 — Asynchronous Actor-Critic Agents (A3C)

Part 4만 잠시 봤는데, double DQN까지도 다루셨더군요.
Posted by uniqueone
,
https://www.slideshare.net/mobile/imryki/introduction-to-deep-learning-in-python-and-matlab
Posted by uniqueone
,
https://www.slideshare.net/mobile/TaegyunJeon1/ss-70432543
Posted by uniqueone
,
https://www.slideshare.net/mobile/JinwonLee9/ss-70446412
Posted by uniqueone
,
http://www.nature.com/articles/srep26094
Posted by uniqueone
,
안녕하세요 cs231n stanford assignment를 해보려고 하는데, 윈도우에서 하려고 하니 여러 문제가 생기네요; 아나콘다를 이용해서 하면 아무 문제가 없어야한다고 하는데 주피터노트북에서 첫 셀의 import가 나올 때마다 문제가 생깁니다. python 2로 kernel을 설치했음에도 문제가 생깁니다. reddit에서도 비슷한 내용이 나오는데 어떤 식으로 해결했는지 자세히 나와있거나 해결책이 있는 글을 찾기가 어렵더군요.. 혹시 미리 해보신 선배님들은 이런 문제를 어찌 해결하셨는지 묻고 싶습니다. 직접 코딩을 해보면서 공부한 걸 좀 더 solidify하고 싶은 마음에 코딩을 좀 해봐야겠다 했는데 환경설정부터 막히는군요; 도와주세요
assignment1 knn 문서이고, 에러 메시지는 다음과 같습니다. numpy에서 처음에 문제가 생기기에 패키지를 따로 install해줬더니 넘어갔건만 scipy는 설치도 잘 안되는군요. 이 모든게 conda를 쓰면 그럴 필요가 없다는데 어떤식으로 할 수 있는 것인지 나와있는 글이나 자료를 찾지 못하겠어서 진도가 안나갑니다.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-6d53d297f0cc> in <module>()
      3 import random
      4 import numpy as np
----> 5 from cs231n.data_utils import load_CIFAR10
      6 import matplotlib.pyplot as plt
      7

D:\DaumCloud\[3] Study\[0] cs231n CNN for visual recognition - stanford\assignment1\cs231n\data_utils.py in <module>()
      2 import numpy as np
      3 import os
----> 4 from scipy.misc import imread
      5
      6 def load_CIFAR_batch(filename):

ImportError: No module named scipy.misc



댓글을 쭉 읽어보신 분은 아시겠지만 Kyung Mo Kweon 님께서 말씀해주신대로 제가 anaconda를 python 3.5 버전으로 깔았기에 생기는 문제였습니다. 가상환경을 2.7 버전으로 설치해주고나니 모든 암이 없어졌습니다ㅋㅋ 이어서 생기는 문제는 dataset을 다운 받아야하는데 bash (.sh) 파일이라서 실행이 안되므로 문제가 생기는데 어짜피 bash 파일을 열어서보면 링크가 있으므로 직접 링크를 쳐서 들어가서 다운을 받으면 bash 파일을 실행하는 것과 다름이 없습니다. 도움 주신 Kyung Mo Kweon님 다시 한 번 감사드립니다.
Posted by uniqueone
,
http://www.nvidia.com/object/torch-library.html?ncid=so-twi-th-220
Posted by uniqueone
,
https://www.facebook.com/groups/DeepLearnng/permalink/1886782538222062/

https://drive.google.com/file/d/0B64011x02sIkdDB5MmdnRnNTbWc/edit
Posted by uniqueone
,
자신의 기술적 경험이나 지식을 책으로 출간하고 싶어 하는 분들이 많이 있습니다. 이 글에서는 딥러닝의 공부를 시작으로 해서 에스프레소북이라는 전자책 출판 서비스를 통해 어떻게 출판까지 하게 되었는지에 대한 간단한 소감을 소개하고 있습니다.

딥러닝과 에스프레소북 그리고 이것저것들 | Popit
http://www.popit.kr/%EB%94%A5%EB%9F%AC%EB%8B%9D%EA%B3%BC-%EC%97%90%EC%8A%A4%ED%94%84%EB%A0%88%EC%86%8C%EB%B6%81-%EA%B7%B8%EB%A6%AC%EA%B3%A0-%EC%9D%B4%EA%B2%83%EC%A0%80%EA%B2%83%EB%93%A4/
Posted by uniqueone
,

 

https://github.com/BinRoot/TensorFlow-Book?utm_content=buffer3f3de&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer

 

 

 

Machine Learning with TensorFlow

This is the official code repository for Machine Learning with TensorFlow.

:warning: Warning: The book will be released in a month or two, so this repo is a pre-release of the entire code. I will be heavily updating this repo in the coming weeks. Stay tuned, and follow along! :)

Get started with machine learning using TensorFlow, Google's latest and greatest machine learning library.

Summary

Chapter 2 - TensorFlow Basics

  • Concept 1: Defining tensors
  • Concept 2: Evaluating ops
  • Concept 3: Interactive session
  • Concept 4: Session loggings
  • Concept 5: Variables
  • Concept 6: Saving variables
  • Concept 7: Loading variables
  • Concept 8: TensorBoard

Chapter 3 - Regression

  • Concept 1: Linear regression
  • Concept 2: Polynomial regression
  • Concept 3: Regularization

Chapter 4 - Classification

  • Concept 1: Linear regression for classification
  • Concept 2: Logistic regression
  • Concept 3: 2D Logistic regression
  • Concept 4: Softmax classification

Chapter 5 - Clustering

  • Concept 1: Clustering
  • Concept 2: Segmentation
  • Concept 3: Self-organizing map

Chapter 6 - Hidden markov models

  • Concept 1: Forward algorithm
  • Concept 2: Viterbi decode

Chapter 7 - Autoencoders

  • Concept 1: Autoencoder
  • Concept 2: Applying an autoencoder to images
  • Concept 3: Denoising autoencoder

Chapter 8 - Reinforcement learning

  • Concept 1: Reinforcement learning

Chapter 9 - Convolutional Neural Networks

  • Concept 1: Using CIFAR-10 dataset
  • Concept 2: Convolutions
  • Concept 3: Convolutional neural network

Chapter 10 - Recurrent Neural Network

  • Concept 1: Loading timeseries data
  • Concept 2: Recurrent neural networks
  • Concept 3: Applying RNN to real-world data for timeseries prediction
Posted by uniqueone
,
https://www.opendatascience.com/blog/learning-reinforcement-learning-with-code-exercises-and-solutions/?utm_source=Open+Data+Science+Newsletter&utm_campaign=63677c26f2-EMAIL_CAMPAIGN_2016_12_13&utm_medium=email&utm_term=0_2ea92bb125-63677c26f2-245860601



Open Data Science
Toggle navigation
Learning Reinforcement Learning (With Code, Exercises and Solutions)


By Denny Britz, Deep Learning Specialist - Google Brain | 12/14/2016
Tags: Algorithms

Skip all the talk and go directly to the Github Repo with code and exercises.

WHY STUDY REINFORCEMENT LEARNING

Reinforcement Learning is one of the fields I’m most excited about. Over the past few years amazing results like learning to play Atari Games from raw pixels and Mastering the Game of Go have gotten a lot of attention, but RL is also widely used in Robotics, Image Processing and Natural Language Processing.

Combining Reinforcement Learning and Deep Learning techniques works extremely well. Both fields heavily influence each other. On the Reinforcement Learning side Deep Neural Networks are used as function approximators to learn good representations, e.g. to process Atari game images or to understand the board state of Go. In the other direction, RL techniques are making their way into supervised problems usually tackled by Deep Learning. For example, RL techniques are used to implement attention mechanisms in image processing, or to optimize long-term rewards in conversational interfaces and neural translation systems. Finally, as Reinforcement Learning is concerned with making optimal decisions it has some extremely interesting parallels to human Psychology and Neuroscience (and many other fields).

With lots of open problems and opportunities for fundamental research I think we’ll be seeing multiple Reinforcement Learning breakthroughs in the coming years. And what could be more fun than teaching machines to play Starcraft and Doom?

HOW TO STUDY REINFORCEMENT LEARNING

There are many excellent Reinforcement Learning resources out there. Two I recommend the most are:

David Silver’s Reinforcement Learning Course
Richard Sutton’s & Andrew Barto’s Reinforcement Learning: An Introduction (2nd Edition) book.
The latter is still work in progress but it’s ~80% complete. The course is based on the book so the two work quite well together. In fact, these two cover almost everything you need to know to understand most of the recent research papers. The prerequisites are basic Math and some knowledge of Machine Learning.

That covers the theory. But what about practical resources? What about actually implementing the algorithms that are covered in the book/course? That’s where this post and the Github repository comes in. I’ve tried to implement most of the standard Reinforcement Algorithms using Python, OpenAI Gym and Tensorflow. I separated them into chapters (with brief summaries) and exercises and solutions so that you can use them to supplement the theoretical material above. All of this is in the Github repository.

Some of the more time-intensive algorithms are still work in progress, so feel free to contribute. I’ll update this post as I implement them.

TABLE OF CONTENTS

Introduction to RL problems, OpenAI gym
MDPs and Bellman Equations
Dynamic Programming: Model-Based RL, Policy Iteration and Value Iteration
Monte Carlo Model-Free Prediction & Control
Temporal Difference Model-Free Prediction & Control
Function Approximation
Deep Q Learning (WIP)
Policy Gradient Methods (WIP)
Learning and Planning (WIP)
Exploration and Exploitation (WIP)
LIST OF IMPLEMENTED ALGORITHMS

Dynamic Programming Policy Evaluation
Dynamic Programming Policy Iteration
Dynamic Programming Value Iteration
Monte Carlo Prediction
Monte Carlo Control with Epsilon-Greedy Policies
Monte Carlo Off-Policy Control with Importance Sampling
SARSA (On Policy TD Learning)
Q-Learning (Off Policy TD Learning)
Q-Learning with Linear Function Approximation
Deep Q-Learning for Atari Games
Double Deep-Q Learning for Atari Games
Deep Q-Learning with Prioritized Experience Replay (WIP)
Policy Gradient: REINFORCE with Baseline
Policy Gradient: Actor Critic with Baseline
Policy Gradient: Actor Critic with Baseline for Continuous Action Spaces
Deterministic Policy Gradients for Continuous Action Spaces (WIP)
Deep Deterministic Policy Gradients (DDPG) (WIP)
Asynchronous Advantage Actor Critic (A3C) (WIP)
Originally posted at www.wildml.com/

WHAT IS OPEN DATA SCIENCE?

Username *

Email *

Password *

Repeat Password *
Get Newsletter & Full Access
 
LATEST POSTS
Scikit-learn Tutorial: Statistical-Learning for Scientific Data Processing
12/14/2016

Learning Reinforcement Learning (With Code, Exercises and Solutions)
12/14/2016

Visualizing the Relationship Between Infant Mortality Rates & Resource Availability
12/14/2016

 
POPULAR POSTS
Riding on Large Data with Scikit-learn
   9997 views

R or Python for data science?
   9841 views

huh Understanding Convolutional Neural Networks for NLP
   9252 views

RELATED POSTS
Introducing Dask distributed #1
09/13/2016

An Introduction to Contextual Bandits
09/06/2016

Jester Dataset: What make’s You laugh?
08/09/2016

Topnotch Theano Tutorial
02/05/2016

Single-Layer Neural Networks and Gradient Descent
09/10/2016

Ad Hoc Distributed Random Forests
09/17/2016

R-BLOGS
New Course: Data Visualization in R
Posted 14 December 2016 | 6:59 pm
R Jobs for R users – 17 jobs from around the world (2016-12-14)
Posted 14 December 2016 | 6:57 pm
One Page R: A Survival Guide to Data Science with R
Posted 14 December 2016 | 5:44 pm
Visualizing taxi trips between NYC neighborhoods with Spark and Microsoft R Server
Posted 14 December 2016 | 5:40 pm
Hierarchical Clustering exercises (beginner)
Posted 14 December 2016 | 5:00 pm
TAGS
Artificial Intelligence
Cyber Security
Analytics
Sports Analytics
Notebooks
Open Source
ipython
Anomaly Detection
Data Journalism
Computer Vision
Data Science Careers
Julia
ODSC London 2016
Data Science Jobs
Pandas
Open Data Science
Tutorial
Interview
Natural Language Processing
Politics
statistics
Meetup
NLP
Data Science for Good
Jupyter
Spark
Bayes
Data Mining
AI
Algorithms
Data analysis
IoT
Predictive Analytics
Intro
BDF 2015
Deep Learning
Scikit-learn
Open Data
Data Visualization
Neural Networks
Big Data
Speaker Talk
R
ODSC East 2016
ODSC West 2015
Speaker Slides
Python
Data Science
Machine Learning
ODSC East 2015
Copyright © 2016 Open Data Science. All rights reserved.
Privacy-policy
Code of conduct
FOLLOW US:
Posted by uniqueone
,
https://github.com/chasingbob/deep-learning-resources/blob/master/README.md

A Collection of resources I have found useful on my journey finding my way through the world of Deep Learning.

Courses

Stanford CS231n Convolutional Neural Networks for Visual Recognition

Coursera: Neural Networks for Machine Learning

Even though Deep Learning is a small but important subset of Machine Learning, it is still important to get a wider knowledge and understanding of Machine Learning and no course will give you a better understanding than the excellent course by Andrew Ng.

Coursera: Machine Learning

Tutorials

A Beginner's Guide To Understanding Convolutional Neural Networks

An Intuitive Explanation of Convolutional Neural Networks

Gradient Descent Optimisation Algorithms

Animations done by AlecRadford

An Overview

Understanding LSTM Networks

Keras is my favorite framework for Deep Learning and is underneath compatible with both Theano and Tensorflow.

The Keras Blog - Building powerful image classification models using very little data
A Few Useful Things to Know about Machine Learning ~Pedro Domingos

How convolutional neural networks see the world ~Francois Chollet

Youtube

Introduction to Deep Learning with Python

Books & e-Books

Neural Networks and Deep Learning

Deep Learning Book - some call this book the Deep Learning bible

Machine Learning Yearning - Technical Strategy for AI Engineers, in the Era of Deep Learning ~Andrew Ng

Getting Philosophical

What is the next likely breakthrough in Deep Learning

Looking at The major advancements in Deep Learning in 2016 gives us a peek into the future of deep learing. A big portion of the effort went into Generative Models, let us see if that is the case in 2017.

Do machines actually beat doctors?

Competitions

Kaggle is the place to be for Data Scientists and Deep Learning experts at the moment - but you don't have to be an expert to feel the adrenalin of a $120000 competition

Kaggle competitions perfect for deep learning:

Digit Recognizer

Dogs vs Cats

The Nature Conservancy Fisheries Monitoring

State Farm Distracted Driver Detection

Tools of the Trade

Python

Python Official

Python Programming Tutorials

MatplotLib

Deep Learning is far from being an exact science and a lot of what you do is based on getting a feel for the underlying mechanics, visualising the moving parts makes it easier to understand and Matplotlib is the go-to library for visualisation

Matplotlib official

Matplotlib tutorial

NumPy

NumPy is a fast optimized package for scientific computing, and is also the underlying library a lot of Machine Learning frameworks are build on top of. Becoming a NumPy ninja is an important step to mastery.

NumPy official

100 NumPy exercises

Datasets

20 Weird & Wonderful Datasets for Machine Learning

Enron Email Dataset
Posted by uniqueone
,

"Please note that each additional compute capability significantly increases your build time and binary size."

--> check at https://developer.nvidia.com/cuda-gpus


Posted by uniqueone
,

Cheehun Won 받는 사람 TensorFlow KR

 

 

텐서플로우 0.12.0 RC0 윈도우 버전에서 웹 리소스(HTML, JS) 파일이 없어 텐서보드가 빈화면으로 출력되는 문제가 발생하여 (PIP 설치 시에, Python 3.5, Anaconda)

소스를 받아서 필요한 웹리소스를 묶어 봤습니다. 첫 페이지에 모두 로딩 되는 것은 확인 했는데, 이게 필요한 모든 리소스를 묶었는지는 검증을 못 했습니다. 필요하신분께 도움이 되면 좋겠네요.

압축 파일 주소는 https://www.dropbox.com/s/hxekoifmbyvrl33/tensorboard.zip…...
이고,

압축풀 경로는 아나콘다 기준으로
Anaconda3\Lib\site-packages\tensorflow\tensorboard
폴더입니다.

감사합니다.

Posted by uniqueone
,

http://jorditorres.org/free-deep-learning-textbooks/

 

 

There are not many books on Deep Learning at the moment because it is such a young area of study. However there are new freely online version available of 3 books that cover beginner, intermediate and advanced levels:

 

  1. Advanced level:Deep Learning” written by top deep learning scientists Ian GoodfellowYoshua Bengio and Aaron Courville. The book includes coverage of all of the main algorithms in the field and can be used as a reference book by those who have experience in the field.
  2. Intermediate level:Neural Networks and Deep Learning” written by Michael Nielsen. The book is a good place to start for those who already have experience in Machine Learning and want to delve into Neural Networks.
  3. Beginner level: “FIRST CONTACT WITH TENSORFLOW, get started with Deep Learning programming” written by Jordi Torres. The book is oriented to engineers with only some basic understanding of Machine Learning who want to expand their wisdom in the exciting world of Deep Learning with a hands-on approach that uses TensorFlow.

Good luck!

Posted by uniqueone
,

http://warmspringwinds.github.io/tensorflow/tf-slim/2016/10/30/image-classification-and-segmentation-using-tensorflow-and-tf-slim/

 

 

 

A post showing how to perform Image Classification and Image Segmentation with a recently released TF-Slim library and pretrained models.


Inroduction

In this post I want to show an example of application of Tensorflow and a recently released library slim for Image Classification, Image Annotation and Segmentation. In the post I focus on slim, cover a small theoretical part and show possible applications.

I have tried other libraries before like Caffe, Matconvnet, Theano and Torch. All of them have their pros and cons, but I always wanted a library in Python that is flexible, has good support and has a lot of pretrained models. Recently, a new library called slim was released along with a set of standart pretrained models like ResNet, VGG, Inception-ResNet-v2 (new winner of ILSVRC) and others. This library along with models are supported by Google, which makes it even better. There was a need for a library like this because Tensorflow itself is a very low-level and any implementation can become highly complicated. It requires writing a lot of boilerplate code. Reading other people’s code was also complicated. slim is a very clean and lightweight wrapper around Tensorflow with pretrained models.

This post assumes a prior knowledge of Tensorflow and Convolutional Neural Networks. Tensorflow has a nice tutorials on both of these. You can find them here.

The blog post is created using jupyter notebook. After each chunk of a code you can see the result of its evaluation. You can also get the notebook file from here. The content of the blog post is partially borrowed from slim walkthough notebook.

Setup

To be able to run the code, you will need to have Tensorflow installed. I have used r0.11. You will need to have tensorflow/models repository cloned. To clone it, simply run:

git clone https://github.com/tensorflow/models

I am also using scikit-image library and numpy for this tutorial plus other dependencies. One of the ways to install them is to download Anaconda software package for python.

First, we specify tensorflow to use the first GPU only. Be careful, by default it will use all available memory. Second, we need to add the cloned repository to the path, so that python is able to see it.

import sys
import os

os.environ["CUDA_VISIBLE_DEVICES"] = '0'
sys.path.append("/home/dpakhom1/workspace/models/slim")

Now, let’s download the VGG-16 model which we will use for classification of images and segmentation. You can also use networks that will consume less memory(for example, AlexNet). For more models look here.

from datasets import dataset_utils
import tensorflow as tf

url = "http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz"

# Specify where you want to download the model to
checkpoints_dir = '/home/dpakhom1/checkpoints'

if not tf.gfile.Exists(checkpoints_dir):
    tf.gfile.MakeDirs(checkpoints_dir)

dataset_utils.download_and_uncompress_tarball(url, checkpoints_dir)
>> Downloading vgg_16_2016_08_28.tar.gz 100.0%
Successfully downloaded vgg_16_2016_08_28.tar.gz 513324920 bytes.

Image Classification

The model that we have just downloaded was trained to be able to classify images into 1000 classes. The set of classes is very diverse. In our blog post we will use the pretrained model to classify, annotate and segment images into these 1000 classes.

Below you can see an example of Image Classification. We preprocess the input image by resizing it while preserving the aspect ratio and crop the central part. The size of the crop is equal to the size of images that the network was trained on.

%matplotlib inline

from matplotlib import pyplot as plt

import numpy as np
import os
import tensorflow as tf
import urllib2

from datasets import imagenet
from nets import vgg
from preprocessing import vgg_preprocessing

checkpoints_dir = '/home/dpakhom1/checkpoints'

slim = tf.contrib.slim

# We need default size of image for a particular network.
# The network was trained on images of that size -- so we
# resize input image later in the code.
image_size = vgg.vgg_16.default_image_size


with tf.Graph().as_default():
    
    url = ("https://upload.wikimedia.org/wikipedia/commons/d/d9/"
           "First_Student_IC_school_bus_202076.jpg")
    
    # Open specified url and load image as a string
    image_string = urllib2.urlopen(url).read()
    
    # Decode string into matrix with intensity values
    image = tf.image.decode_jpeg(image_string, channels=3)
    
    # Resize the input image, preserving the aspect ratio
    # and make a central crop of the resulted image.
    # The crop will be of the size of the default image size of
    # the network.
    processed_image = vgg_preprocessing.preprocess_image(image,
                                                         image_size,
                                                         image_size,
                                                         is_training=False)
    
    # Networks accept images in batches.
    # The first dimension usually represents the batch size.
    # In our case the batch size is one.
    processed_images  = tf.expand_dims(processed_image, 0)
    
    # Create the model, use the default arg scope to configure
    # the batch norm parameters. arg_scope is a very conveniet
    # feature of slim library -- you can define default
    # parameters for layers -- like stride, padding etc.
    with slim.arg_scope(vgg.vgg_arg_scope()):
        logits, _ = vgg.vgg_16(processed_images,
                               num_classes=1000,
                               is_training=False)
    
    # In order to get probabilities we apply softmax on the output.
    probabilities = tf.nn.softmax(logits)
    
    # Create a function that reads the network weights
    # from the checkpoint file that you downloaded.
    # We will run it in session later.
    init_fn = slim.assign_from_checkpoint_fn(
        os.path.join(checkpoints_dir, 'vgg_16.ckpt'),
        slim.get_model_variables('vgg_16'))
    
    with tf.Session() as sess:
        
        # Load weights
        init_fn(sess)
        
        # We want to get predictions, image as numpy matrix
        # and resized and cropped piece that is actually
        # being fed to the network.
        np_image, network_input, probabilities = sess.run([image,
                                                           processed_image,
                                                           probabilities])
        probabilities = probabilities[0, 0:]
        sorted_inds = [i[0] for i in sorted(enumerate(-probabilities),
                                            key=lambda x:x[1])]
    
    # Show the downloaded image
    plt.figure()
    plt.imshow(np_image.astype(np.uint8))
    plt.suptitle("Downloaded image", fontsize=14, fontweight='bold')
    plt.axis('off')
    plt.show()
    
    # Show the image that is actually being fed to the network
    # The image was resized while preserving aspect ratio and then
    # cropped. After that, the mean pixel value was subtracted from
    # each pixel of that crop. We normalize the image to be between [-1, 1]
    # to show the image.
    plt.imshow( network_input / (network_input.max() - network_input.min()) )
    plt.suptitle("Resized, Cropped and Mean-Centered input to network",
                 fontsize=14, fontweight='bold')
    plt.axis('off')
    plt.show()

    names = imagenet.create_readable_names_for_imagenet_labels()
    for i in range(5):
        index = sorted_inds[i]
        # Now we print the top-5 predictions that the network gives us with
        # corresponding probabilities. Pay attention that the index with
        # class names is shifted by 1 -- this is because some networks
        # were trained on 1000 classes and others on 1001. VGG-16 was trained
        # on 1000 classes.
        print('Probability %0.2f => [%s]' % (probabilities[index], names[index+1]))
        
    res = slim.get_model_variables()

png

png

Probability 1.00 => [school bus]
Probability 0.00 => [minibus]
Probability 0.00 => [passenger car, coach, carriage]
Probability 0.00 => [trolleybus, trolley coach, trackless trolley]
Probability 0.00 => [cab, hack, taxi, taxicab]

Image Annotation and Segmentation

As you can see from the previous example, only a certain part of the original image is being processed by the network. This is good only for cases when we want to get a single prediction for an image.

Sometimes we want to get more information from an image. For example, it would be great to know about all the objects that are present in the image. For example, network would tell us that it found a school bus, other cars and building. Using this information, we can create a search engine that will be able to give us all images that has a particular object in them. This can be seen as a simple case of Image Annotation.

But what if we also want to get spatial information about the objects locations. Can the network tell us that it sees a bus in the center of the image and building on the top-right corner? That way we can create a more specific queries for a search engine: “Give me all images where the school bus is located in the middle AND flower pot in the top left corner”.

There are cases when we need to classify each pixel of the image, also know as the task of Segmentation. Imagine, that we have a huge dataset with pictures and we want to blur faces of people there, so that we don’t have to get their permission to publish these pictures. For example, you can see people’s faces being blured in Google Street View. But we only need to blur faces and not other content that might be important. Segmentation can help us in this case. We can get pixels that belong to faces and blur only them.

Below we will see a simple example of Segmentation. For the simplicity, the segmentation will be of a smaller size than the original image. We can do segmentation using an existing Convolutional Neural Network by applying it in a Fully Convolutional manner. This is done by casting the Fully Connected Layers of a network into Convolutional – this way we can input image of any size and get segmentation of lower resolution due to max-pooling layers that are used in network. To get the Segmentation of the same size as an input, deconvolutional layers can be used. You can read more about this in the paper fully convolutional networks for semantic segmentation by Long et al. We won’t consider deconvolutional layers in this example. Example below shows how to get segmentation of lower resolution than the input. Deconvolutional layers can be seen as a way to perform interpolation. Interpolation can be different (quadratic, qubic and other) but network can learn a specific interpolation that performs well under a certain task.

from preprocessing import vgg_preprocessing

# Load the mean pixel values and the function
# that performs the subtraction
from preprocessing.vgg_preprocessing import (_mean_image_subtraction,
                                            _R_MEAN, _G_MEAN, _B_MEAN)

# Function to nicely print segmentation results with
# colorbar showing class names
def discrete_matshow(data, labels_names=[], title=""):
    #get discrete colormap
    cmap = plt.get_cmap('Paired', np.max(data)-np.min(data)+1)
    # set limits .5 outside true range
    mat = plt.matshow(data,
                      cmap=cmap,
                      vmin = np.min(data)-.5,
                      vmax = np.max(data)+.5)
    #tell the colorbar to tick at integers
    cax = plt.colorbar(mat,
                       ticks=np.arange(np.min(data),np.max(data)+1))
    
    # The names to be printed aside the colorbar
    if labels_names:
        cax.ax.set_yticklabels(labels_names)
    
    if title:
        plt.suptitle(title, fontsize=14, fontweight='bold')


with tf.Graph().as_default():
    
    url = ("https://upload.wikimedia.org/wikipedia/commons/d/d9/"
           "First_Student_IC_school_bus_202076.jpg")
    
    image_string = urllib2.urlopen(url).read()
    image = tf.image.decode_jpeg(image_string, channels=3)
    
    # Convert image to float32 before subtracting the
    # mean pixel value
    image_float = tf.to_float(image, name='ToFloat')
    
    # Subtract the mean pixel value from each pixel
    processed_image = _mean_image_subtraction(image_float,
                                              [_R_MEAN, _G_MEAN, _B_MEAN])

    input_image = tf.expand_dims(processed_image, 0)
    
    with slim.arg_scope(vgg.vgg_arg_scope()):
        
        # spatial_squeeze option enables to use network in a fully
        # convolutional manner
        logits, _ = vgg.vgg_16(input_image,
                               num_classes=1000,
                               is_training=False,
                               spatial_squeeze=False)
    
    # For each pixel we get predictions for each class
    # out of 1000. We need to pick the one with the highest
    # probability. To be more precise, these are not probabilities,
    # because we didn't apply softmax. But if we pick a class
    # with the highest value it will be equivalent to picking
    # the highest value after applying softmax
    pred = tf.argmax(logits, dimension=3)
    
    init_fn = slim.assign_from_checkpoint_fn(
        os.path.join(checkpoints_dir, 'vgg_16.ckpt'),
        slim.get_model_variables('vgg_16'))
    
    with tf.Session() as sess:
        init_fn(sess)
        segmentation, np_image = sess.run([pred, image])

# Remove the first empty dimension
segmentation = np.squeeze(segmentation)

# Let's get unique predicted classes (from 0 to 1000) and
# relable the original predictions so that classes are
# numerated starting from zero
unique_classes, relabeled_image = np.unique(segmentation,
                                            return_inverse=True)

segmentation_size = segmentation.shape

relabeled_image = relabeled_image.reshape(segmentation_size)

labels_names = []

for index, current_class_number in enumerate(unique_classes):

    labels_names.append(str(index) + ' ' + names[current_class_number+1])

discrete_matshow(data=relabeled_image, labels_names=labels_names, title="Segmentation")

png

png

The segmentation that was obtained shows that network was able to find the school bus, traffic sign in the left-top corner that can’t be clearly seen in the image. It was able to locate windows at the top-left corner and even made a hypothesis that it is a library (we don’t know if that is true). It also made a certain number of not so correct predictions. Those are usually caused by the fact that the network can only see a part of image when it is centered at a pixel. The characteristic of a network that represents it is called receptive field. Receptive field of the network that we use in this blog is 404 pixels. So when network can only see a part of the school bus, it confuses it with taxi or pickup truck. You can see that in the bottom-left corner of segmentation results.

As we can see above, we got a simple segmentation for our image. It is not very precise because the network was originally trained to perform classification and not segmentation. If we want to get better results, we will have to train it ourselves. Anyways, the results that we got are suitable for image annotation and very approximate segmentation.

Performing Segmentation using Convolutional Neural Networks can be seen as performing classification at different parts of an input image. We center network at a particular pixel, make prediction and assign label to that pixel. This way we add spatial information to our classification and get segmentation.

Conclusion and Discussion

In this blog post we covered slim library by performing Image Classification and Segmentation. The post also explains a certain amount of theory behind both tasks.

In my opinion, slim along with pretrained models can be a very powerful tool while remaining very flexible and you can always intermix Tensorflow with it. It is relatively new, therefore, it lacks documentation and sometimes you have to read the source code. It has support from Google and is currently in an active development.

Posted by uniqueone
,

https://elitedatascience.com/keras-tutorial-deep-learning-in-python

 

 

 

In this step-by-step Keras tutorial, you’ll learn how to build a convolutional neural network in Python!

In fact, we’ll be training a classifier for handwritten digits that boasts over 99% accuracy on the famous MNIST dataset.

Before we begin, we should note that this guide is geared toward beginners who are interested in applied deep learning.

Our goal is to introduce you to one of the most popular and powerful libraries for building neural networks in Python. That means we’ll brush over much of the theory and math, but we’ll also point you to great resources for learning those.

Keras Tutorial

Before we start...

Recommended Prerequisites

The recommended prerequisites for this guide are:

To move quickly, we'll assume you have this background.

Why Keras?

Keras is our recommended library for deep learning in Python, especially for beginners. Its minimalistic, modular approach makes it a breeze to get deep neural networks up and running. You can read more about it here:

WTF is Deep Learning?

Deep learning refers to neural networks with multiple hidden layers that can learn increasingly abstract representations of the input data. This is obviously an oversimplification, but it's a practical definition for us right now.

For example, deep learning has led to major advances in computer vision. We're now able to classify images, find objects in them, and even label them with captions. To do so, deep neural networks with many hidden layers can sequentially learn more complex features from the raw input image:

  • The first hidden layers might only learn local edge patterns.
  • Then, each subsequent layer (or filter) learns more complex representations.
  • Finally, the last layer can classify the image as a cat or kangaroo.

These types of deep neural networks are called Convolutional Neural Networks.

WTF are Convolutional Neural Networks?

In a nutshell, Convolutional Neural Networks (CNN's) are multi-layer neural networks (sometimes up to 17 or more layers) that assume the input data to be images.

Typical CNN Architecture

Typical CNN Architecture

By making this requirement, CNN's can drastically reduce the number of parameters that need to be tuned. Therefore, CNN's can efficiently handle the high dimensionality of raw images.

Their underlying mechanics are beyond the scope of this tutorial, but you can read more about them here.

What this tutorial is not:

This is not a complete course on deep learning. Instead, this tutorial is meant to get you from zero to your first Convolutional Neural Network with as little headache as possible!

If you're interested in mastering the theory behind deep learning, we recommend this great course from Stanford:

A quick tip before we begin:

We tried to make this tutorial as streamlined as possible, which means we won't go into too much detail for any one topic. It's helpful to have the Keras documentation open beside you, in case you want to learn more about a function or module.

Keras Tutorial Contents

Here are the steps for building your first CNN using Keras:

  1. Set up your environment.
  2. Install Keras.
  3. Import libraries and modules.
  4. Load image data from MNIST.
  5. Preprocess input data for Keras.
  6. Preprocess class labels for Keras.
  7. Define model architecture.
  8. Compile model.
  9. Fit model on training data.
  10. Evaluate model on test data.

Step 1: Set up your environment.

First, hang up a motivational poster:

Motivational poster

Probably useless.

Next, make sure you have the following installed on your computer:

  • Python 2.7+ (Python 3 is fine too, but Python 2.7 is still more popular for data science overall)
  • SciPy with NumPy
  • Matplotlib (Optional, recommended for exploratory analysis)
  • Theano* (Installation instructions)

We strongly recommend installing Python, NumPy, SciPy, and matplotlib through the Anaconda Distribution. It comes with all of those packages.

*note: TensorFlow is also supported (as an alternative to Theano), but we stick with Theano to keep it simple. The main difference is that you'll need to reshape the data slightly differently before feeding it to your network.

You can check to see if you've installed everything correctly:

Go to your command line program (Terminal on a Mac) and type in:

You'll see the Python interpreter:

Next, you can import your libraries and print their versions:

 

Step 2: Install Keras.

It wouldn't be a Keras tutorial if we didn't cover how to install Keras.

The good news is that if you used Anaconda, then you'll already have a nice package management system called pip installed.

You can confirm you have it installed by typing  $ pip in your command line. It should output a list of commands and options. If you don't have pip, you can install it here.

Once you have pip, installing Keras is easy as pie:

You can confirm it's installed correctly:

Oops... looks like that Keras version is outdated. Upgrading the version is easy:

Perfect, now let's start a new Python file and name it keras_cnn_example.py.

Step 3: Import libraries and modules.

Let's start by importing numpy and setting a seed for the computer's pseudorandom number generator. This allows us to reproduce the results from our script:

Next, we'll import the Sequential model type from Keras. This is simply a linear stack of neural network layers, and it's perfect for the type of feed-forward CNN we're building in this tutorial.

Next, let's import the "core" layers from Keras. These are the layers that are used in almost any neural network:

Then, we'll import the CNN layers from Keras. These are the convolutional layers that will help us efficiently train on image data:

Finally, we'll import some utilities. This will help us transform our data later:

Now we have everything we need to build our neural network architecture.

Step 4: Load image data from MNIST.

MNIST is a great dataset for getting started with deep learning and computer vision. It's a big enough challenge to warrant neural networks, but it's manageable on a single computer. We discuss it more in our post: 6 Fun Machine Learning Projects for Beginners.

The Keras library conveniently includes it already. We can load it like so:

We can look at the shape of the dataset:

Great, so it appears that we have 60,000 samples in our training set, and the images are 28 pixels x 28 pixels each. We can confirm this by plotting the first sample in matplotlib:

And here's the image output:

MNIST Digit

In general, when working with computer vision, it's helpful to visually plot the data before doing any algorithm work. It's a quick sanity check that can prevent easily avoidable mistakes (such as misinterpreting the data dimensions).

Step 5: Preprocess input data for Keras.

When using the Theano backend, you must explicitly declare a dimension for the depth of the input image. For example, a full-color image with all 3 RGB channels will have a depth of 3.

Our MNIST images only have a depth of 1, but we must explicitly declare that.

In other words, we want to transform our dataset from having shape (n, width, height) to (n, depth, width, height).

Here's how we can do that easily:

To confirm, we can print X_train's dimensions again:

The final preprocessing step for the input data is to convert our data type to float32 and normalize our data values to the range [0, 1].

Now, our input data are ready for model training.

Step 6: Preprocess class labels for Keras.

Next, let's take a look at the shape of our class label data:

Hmm... that may be problematic. We should have 10 different classes, one for each digit, but it looks like we only have a 1-dimensional array. Let's take a look at the labels for the first 10 training samples:

And there's the problem. The y_train and y_test data are not split into 10 distinct class labels, but rather are represented as a single array with the class values.

We can fix this easily:

Now we can take another look:

There we go... much better!

Step 7:  Define model architecture.

Now we're ready to define our model architecture. In actual R&D work, researchers will spend a considerable amount of time studying model architectures.

To keep this tutorial moving along, we're not going to discuss the theory or math here. This alone is a rich and meaty field, and we recommend the CS231n class mentioned earlier for those who want to learn more.

Plus, when you're just starting out, you can just replicate proven architectures from academic papers or use existing examples. Here's a list of example implementations in Keras.

Let's start by declaring a sequential model format:

Next, we declare the input layer:

The input shape parameter should be the shape of 1 sample. In this case, it's the same (1, 28, 28) that corresponds to  the (depth, width, height) of each digit image.

But what do the first 3 parameters represent? They correspond to the number of convolution filters to use, the number of rows in each convolution kernel, and the number of columns in each convolution kernel, respectively.

*Note: The step size is (1,1) by default, and it can be tuned using the 'subsample' parameter.

We can confirm this by printing the shape of the current model output:

Next, we can simply add more layers to our model like we're building legos:

Again, we won't go into the theory too much, but it's important to highlight the Dropout layer we just added. This is a method for regularizing our model in order to prevent overfitting. You can read more about it here.

MaxPooling2D is a way to reduce the number of parameters in our model by sliding a 2x2 pooling filter across the previous layer and taking the max of the 4 values in the 2x2 filter.

So far, for model parameters, we've added two Convolution layers. To complete our model architecture, let's add a fully connected layer and then the output layer:

For Dense layers, the first parameter is the output size of the layer. Keras automatically handles the connections between layers.

Note that the final layer has an output size of 10, corresponding to the 10 classes of digits.

Also note that the weights from the Convolution layers must be flattened (made 1-dimensional) before passing them to the fully connected Dense layer.

Here's how the entire model architecture looks together:

Now all we need to do is define the loss function and the optimizer, and then we'll be ready to train it.

Step 8: Compile model.

Now we're in the home stretch! The hard part is already over.

We just need to compile the model and we'll be ready to train it. When we compile the model, we declare the loss function and the optimizer (SGD, Adam, etc.).

Keras has a variety of loss functions and out-of-the-box optimizers to choose from.

Step 9: Fit model on training data.

To fit the model, all we have to do is declare the batch size and number of epochs to train for, then pass in our training data.

Easy, huh?

You can also use a variety of callbacks to set early-stopping rules, save model weights along the way, or log the history of each training epoch.

Step 10: Evaluate model on test data.

Finally, we can evaluate our model on the test data:

Congratulations... you've made it to the end of this Keras tutorial!

We've just completed a whirlwind tour of Keras's core functionality, but we've only really scratched the surface. Hopefully you've gained the foundation to further explore all that Keras has to offer.

For continued learning, we recommend studying other example models in Keras and Stanford's computer vision class.

The complete code, from start to finish.

Here's all the code in one place, in a single script.

Enjoyed the tutorial?

Sign up for our newsletter for more content like this. You’ll also get instant access to a free PDF guide: Supercharge Your Data Science Career: 88 Free, Hand-Picked Resources Every Data Scientist Should Have.

Posted by uniqueone
,

텐서플로우 관련 좋은 강의 자료가 있어 공유합니다.

Tensorflow and deeplearning without at Ph.D

동영상 강의 : https://youtu.be/vq2nnJ4g6N0
강의 슬라이드 : https://docs.google.com/presentation/d/1TVixw6ItiZ8igjp6U17tcgoFrLSaHWQmMOwjlgQY9co/pub?slide=id.p
GitHub : https://github.com/martin-gorner/tensorflow-mnist-tutorial

Posted by uniqueone
,

For installation follow instruction on this link, I have personally installed caffe from these instructions. https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide

Try this - http://www.pittnuts.com/2016/07/geforce-gtx-1080-cuda-8-0-ubuntu-16-04-caffe/

Posted by uniqueone
,

안녕하세요 ㅎㅎ TensorFlow KR에는 글을 처음 써보네요!

제가 듣는 대학원 수업에서 발표한 TensorFlow Tutorial 슬라이드와 소스코드 공유합니다 ㅎㅎ

내용은 거의 "텐서플로 첫걸음" 책을 요약한 것입니다 ㅎㅎ 소스 코드도 거의 책의 예제 코드에서 가져왔구요.

...

슬라이드의 특징은:
- MNIST CNN 예제 코드를 그림으로 이쁘게 그림!
- TensorFlow의 MNIST CNN 예제 코드와 동일한 NN을 TFLearn를 사용하여 구현해봄!

이렇게 두 가지 정도입니다 ㅎㅎ

누군가에게 도움이 되었으면 좋겠습니다. 감사합니다.

SlideShare:
http://www.slideshare.net/JunK…/tensorflow-tutorial-68885890

Jupyter Notebook source code:
https://github.com/uosdmlab/tensorflow-tutorial

Posted by uniqueone
,

Keras Tutorials

Deep Learning 2016. 11. 11. 09:08

https://github.com/fchollet/keras/tree/master/examples

 

https://github.com/tgjeon/Keras-Tutorials

 

https://blog.keras.io/

Posted by uniqueone
,

facebook / TensorFlow KR에서..

 

 

저는 GTX1070+6700K였는데 이렇게 해결했습니다.

1. 별도 HDD를 준비해서 우분투만 설치(UFEI설치X, 멀티부팅 사용 X)


2. 1070GPU를 아예 메인보드에서 뽑아버리고 CPU내장그래픽으로 우분투 16.02LTS를 설치한 후, NVIDIA 드라이버 설치(무한로그인 방지)

3. 컴을 끄고 1070설치후 CUDA8.0+CUDNN5.1 설치진행

(CUDA가 패치되어 우분투 16.02에 기본 설치된 GCC5.2로 빌드가능, GCC4.8로 설치하면 에러발생)

아래 깃허브 링크를 위주로 나머지 사이트의 설치방법들 참조하세요,

https://github.com/.../gtx1080.../blob/master/README.md

http://m.blog.naver.com/kjpark79/220781100554

https://www.google.co.kr/.../install-gpu-tensorflow.../amp/

제 경험을 적어보면 아래와 같습니다
1. 링크에는 CROSSTOOL파일을 열어 빌드경로룰 수정하라고 되어있는데 저는 CROSSTOOL.tpl 파일이더군요

2. CUDNN은 아래와 같이 설치후에 파일을 카피+권한설정해보시길

$ sudo tar -xzvf cudnn-8.0-linux-x64-v5.1.tgz
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

3. ./configure 실행시 설치된 경로나 드라이버 버전을 시스템기본값(엔터)으로 넘기지 말고 일일히 적어보세요 , 특히 gpu compatibility 어쩌고 부분에서 1060은 1070/1080과 넣어줘야할 값이 다릅니다

기타 anaconda나 pyENV는 설치하면 경로에러가 나서 그냥 파이썬2.7로 깡통으로 설치했습니다

저도 하도 설치가 안되서 (빌드부분 에러) 텐서플로우 HW구성, 설치해주는 대행업체를 하나 차려볼까 고민해봤을 정도입니다. 건투를 빕니다

Posted by uniqueone
,

https://marcnu.github.io/2016-08-17/Tensorflow-v0.10-installed-from-scratch-Ubuntu-16.04-CUDA8.0RC-cuDNN5.1-1080GTX/

Tensorflow v0.pdf


This post is not fit to me, however, it shows some guide.


Tensorflow v0.10 installed from scratch on Ubuntu 16.04, CUDA 8.0RC+Patch, cuDNN v5.1 with a 1080GTX

While Tensorflow has a great documentation, you have quite a lot of details that are not obvious, especially the part about setting up Nvidia libraries and installing Bazel as you need to read external install guides. There is also a CROSSTOOL change to make to fix an include directory issue. So here is a guide, explaining everything from scratch in a single page.

1. Installing Nvidia drivers

The first step is to get the latest Nvidia driver. While you can use apt-get to install the driver and CUDA, this causes a lot of issues with automatic updates and you need to purge everything to reinstall a new version. It is simpler to do everything manually.

Go to Nvidia’s download website and download the latest version of the driver, here for Linux 64-bit. In my case, NVIDIA-Linux-x86_64-367.35.run.

As drivers for graphic devices are running at a low level, you must exit the GUI with sudo service lightdm stop and set the RunLevel to 3 with the program init.

Then, move to the directory where you downloaded the .run file and run it. You will be asked to confirm several things, the pre-install of something failure, no 32-bit libraries and more. Just continue to the end. Once it is done, reboot.

sudo service lightdm stop
sudo init 3
sudo sh NVIDIA-Linux-x86_64-367.35.run
sudo reboot
Login loop issue after updates

Due to the manual installation, it seems that when you do Ubuntu updates, they may install the apt-get version of the driver. This causes a failure when you start the computer and login, you will get a black screen and go back to the login screen.

The solution is to enter the terminal with CTRL+ALT+F1 and reinstall the driver just like before. Note that you can get back to the GUI with Alt+F7 when you are in the terminal.

2. Installing CUDA

Install the Toolkit

It’s now time for CUDA. Go to the Nvidia CUDA website and create an account if you don’t already have one and log in (I think this is only required for RC versions of CUDA, which is the case currently for CUDA 8.0RC, an account is also required to download cuDNN).

Choose Linux > x86_64 > Ubuntu > 16.04 > runfile (local) and download the base installer and the patch. Ubuntu 16.04 uses GCC 5.4.0 as default C compiler, which caused an issue with CUDA 8.0RC, this is fixed with the patch.

The installer has 3 parts, a Nvidia driver, CUDA Toolkit and CUDA code samples. The Nvidia driver is usually outdated, that’s why we installed it before, say no when asked if you want to install the driver (in Nvidia’s install guide, they tell us to enter RunLevel 3, but this isn’t necessary if we don’t install the driver). Then, let everything as default, install the code samples to check your CUDA installation. To avoid an error about GCC 5.4.0, add --override. Then, once the installation is over, run the patch.

sudo sh cuda_8.0.27_linux.run --override
sudo sh cuda_8.0.27.1_linux.run

Update paths in .bashrc

The next part is to update CUDA_HOME, PATH and LD_LIBRARY_PATH. Move to your home folder and update .bashrc then reload .bashrc with the command source. For those who are not Linux experts, .bashrc is a file with user parameters that is launched when you login, you must reload it or restart the session for the changes to be active.

cd /home/username/
gedit .bashrc

At the bottom of the file, add the following lines and save:

export CUDA_HOME=/usr/local/cuda-8.0
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

You can then reload .bashrc and check that the paths have been properly modified.

source ~/.bashrc
echo $CUDA_HOME
echo $PATH
echo $LD_LIBRARY_PATH

(Optional) Check that CUDA is working

Then, you can check is CUDA is working by checking the version of nvcc the CUDA compiler and also by moving to the sample directory and compiling bandwidthTest.

nvcc --version
cd NVIDIA_CUDA-8.0_Samples/1_Utilities/bandwidthTest/
make
./bandwidthTest

You should get an output that looks like this:

[CUDA Bandwidth Test] - Starting… Running on…

Device 0: GeForce GTX 1080 Quick Mode

Host to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 12038.9

Device to Host Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 12832.1

Device to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 231046.9

Result = PASS

NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.

You can now move to cuDNN!

3. Installing cuDNN

Go to the Nvidia cuDNN website, login and download Download cuDNN v5.1 (August 10, 2016), for CUDA 8.0 RC > cuDNN v5.1 Library for Linux. Unzip the .tgz file and copy the files to the cuda-8.0 folder. Note that some of the .so files are links to the “real” .so file, by copying it, we duplicate the file, that way, when building Tensorflow from source, any cuDNN version will give libcudnn.so.5.1.5.

tar xvzf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda
sudo cp include/cudnn.h /usr/local/cuda-8.0/include/
sudo cp lib64/* /usr/local/cuda-8.0/lib64/

That’s it. As you see, it is quite easy to add or remove cuDNN and replace it by another version of the library.

4. Installing Tensorflow

It’s now time to install Tensorflow from source as the official binaries are only for CUDA 7.5. We will install it for Python2.7.

Install dependencies

First, install some general dependancies.

sudo apt-get install python-pip python-numpy swig python-dev python-wheel

Install Bazel

Then install Bazel, a build tool from Google.

First, you need to download and install JDK 8.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

It’s now time to get Bazel.

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install bazel
sudo apt-get upgrade bazel

Install Tensorflow itself

First, you must get the code from Github. You can either take the most recent master branch (lots of new commits) or the latest release branch (should be more stable, but still updated every few days). Here, we get branch r0.10.

git clone -b r0.10 https://github.com/tensorflow/tensorflow
cd tensorflow
Important: fix CROSSTOOL file

Edit the text file tensorflow/third_party/gpus/crosstool/CROSSTOOL and add cxx_builtin_include_directory: "/usr/local/cuda-8.0/include" as below.

  cxx_builtin_include_directory: "/usr/lib/gcc/"
  cxx_builtin_include_directory: "/usr/local/include"
  cxx_builtin_include_directory: "/usr/include"
  cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"
  tool_path { name: "gcov" path: "/usr/bin/gcov" }

If you don’t do this, you will get an error that looks like this:

ERROR: /home/marcnu/Documents/tensorflow/tensorflow/contrib/rnn/BUILD:46:1: undeclared inclusion(s) in rule ‘//tensorflow/contrib/rnn:python/ops/_lstm_ops_gpu’:
this rule is missing dependency declarations for the following files included by ‘tensorflow/contrib/rnn/kernels/lstm_ops_gpu.cu.cc’:
‘/usr/local/cuda-8.0/include/cuda_runtime.h’
‘/usr/local/cuda-8.0/include/host_config.h’

‘/usr/local/cuda-8.0/include/curand_discrete2.h’.
nvcc warning : option ‘–relaxed-constexpr’ has been deprecated and replaced by option ‘–expt-relaxed-constexpr’.
nvcc warning : option ‘–relaxed-constexpr’ has been deprecated and replaced by option ‘–expt-relaxed-constexpr’.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use –verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 203.657s, Critical Path: 162.10s

You can now run the configure script. If you have only cuda 8.0, then leaving everything as default should be fine. I just provided the compute capability of my GPU, in my case 6.1.

./configure

Please specify the location of python. [Default is /usr/bin/python]:
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N
No Google Cloud Platform support will be enabled for TensorFlow
Found possible Python library paths:
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
Please input the desired Python library path to use. Default is [/usr/local/lib/python2.7/dist-packages]

/usr/local/lib/python2.7/dist-packages
Do you wish to build TensorFlow with GPU support? [y/N] y
GPU support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]:
Please specify the location where CUDA toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify the Cudnn version you want to use. [Leave empty to use system default]:
Please specify the location where cuDNN library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
libcudnn.so resolves to libcudnn.5
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: “3.5,5.2”]: 6.1
Setting up Cuda include
Setting up Cuda lib64
Setting up Cuda bin
Setting up Cuda nvvm
Setting up CUPTI include
Setting up CUPTI lib64
Configuration finished

You can then run Bazel. The build will take quite a lot of time, 900s on my PC. Then, create the pip package and install it with pip. The name of the pip package may be different depending of Tensorflow’s version.

bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/tensorflow-0.10.0-py2-none-any.whl

That’s it, Tensorflow is installed!

(Optional) Check that Tensorflow is working

You can create a test.py file with the following code and run it to check that everything is working and that the GPU is recognised.

import tensorflow as tf

hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
# Hello, TensorFlow!
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))
# 42
python test.py

I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so.8.0 locally
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_init.cc:118] Found device 0 with properties:
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.797
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 7.52GiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:138] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_init.cc:148] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:870] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
Hello, TensorFlow!
42

You can now start having fun.

Written on August 17, 2016


Posted by uniqueone
,

http://blog.naver.com/kjpark79/220781100554


When I follow the http://pythonkim.tistory.com/71 & https://marcnu.github.io/2016-08-17/Tensorflow-v0.10-installed-from-scratch-Ubuntu-16.04-CUDA8.0RC-cuDNN5.1-1080GTX/, I got the below after < bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package>

"The specified --crosstool_top '@local_config_cuda//crosstool:crosstool' is not a valid cc_toolchain_suite rule. ..."


However, I follow the instruction of http://blog.naver.com/kjpark79/220781100554, I succeed.



ubuntu 14.04 에서는 tensorflow가 잘 됐는데 ubuntu 16.04에서는 MNIST 예제에서 에러가 나더군요. (misaligned address error) CIFAR10, Imagenet 등 다른 예제는 잘됩니다.

검색을 해보니 cuda toolkit 8.0과 cudnn 5를 설치하고 tensorflow를 source로 설치해서 성공했다는 사람이 있어서 해봤습니다. 삽질을 좀 하긴 했지만 설치하고 나니까 MNIST 예제 잘 돌아갑니다. ㅎㅎ

참고로 제 장비는 레노버 Y700 (NVIDIA GTX 960M 탑재) 입니다.


GCC 4.8 설치

ubuntu 16.04에는  gcc 5가 설치되어 있는데 cuda toolkit은 gcc 5를 지원하지 않습니다. 따라서 gcc 4.8을 이용해야 합니다. gcc 4.8을 이용하려면 아래와 같이 하면 됩니다.


sudo apt-get install gcc-4.8

sudo apt-get install g++-4.8

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50 --slave /usr/bin/g++ g++ /usr/bin/g++-5

sudo update-alternatives --config gcc


위와 같이 실행하면 gcc 선택 화면이 나오는데 gcc 4.8에 해당하는 숫자를 선택하면 됩니다. 저의 경우에는 1번이었습니다.

선택후 gcc -v를 실행해보고 버전이 4.8인지 확인하세요.


CUDA Toolkit, cuDNN 설치

NVIDIA 홈페이지에서 cuda toolkit 8.0과 cudnn 5을 다운받으세요.

cuda_8.0.27_linux.run

cudnn-8.0-linux-x64-v5.0-ga.tgz


cudnn의 압축을 풉니다. 압축을 풀면 cuda 디렉토리가 생성됩니다.

tar -zxf cudnn-8.0-linux-x64-v5.0-ga.tgz

 

cuda toolkit을 설치합니다.

sudo ./cuda_8.0.27_linux.run


cuda toolkit이 설치된 디렉토리에 cudnn 파일들을 복사합니다.

sudo cp cuda/include/cudnn.h /usr/local/cuda/include/

sudo cp -a cuda/lib64/* /usr/local/cuda/lib64/

 

라이브러리 path를 추가하기 위해 .bashrc에 아래 내용을 추가합니다.

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64

export CUDA_HOME=/usr/local/cuda


.bashrc에 추가한 내용을 적용합니다.

source ~/.bashrc


Tensorflow 설치

tensorflow를 소스로 설치하는 방법은 홈페이지에 자세히 나와 있기 때문에 여기서는 간략하게 정리했습니다.


tensorflow 소스를 git을 이용해 가져옵니다.

git clone https://github.com/tensorflow/tensorflow


bazel을 설치합니다. bazel은 tensorflow을 빌드하기 위한 툴입니다.

http://bazel.io/docs/install.html


tensorflow 디렉토리로 이동한후 configure를 실행해 환경 설정을 합니다. 아래와 같이 cuda toolkit과 cudnn 버전을 지정해 줍니다.

./configure

...

Do you wish to build TensorFlow with GPU support? [y/N] y

Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0

Please specify the Cudnn version you want to use. [Leave empty to use system default]: 5

...

 

환경 설정이 끝났으면 bazel을 이용해 빌드합니다.

bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer

 

아래와 같은 에러가 발생하면

ERROR: /home/thomas/Downloads/tensorflow/tensorflow/core/kernels/BUILD:1518:1: undeclared inclusion(s) in rule '//tensorflow/core/kernels:depth_space_ops_gpu':

this rule is missing dependency declarations for the following files included by 'tensorflow/core/kernels/spacetodepth_op_gpu.cu.cc':

설정 파일에 include 디렉토리를 추가해 줍니다. vi로 파일을 열고

vi third_party/gpus/crosstool/CROSSTOOL

cxx_builtin_include_directory: "/usr/include" 아래에 아래 내용을 추가하세요.

cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"

 

빌드가 끝났으면 정상적으로 빌드되었는지 확인합니다. 에러없이 잘 실행되면 성공입니다.

bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu


혹시 libcuda.so.1이 없다는 에러가 나오면 그래픽 카드 드라이버가 367인지 확인하세요. 361로 바꾸면 libcuda.so.1이 다시 생깁니다. (바꾸고 재부팅 한번 해주세요)

 

Python 패키지 제작

python에서 사용하려면 패키지를 만들고 pip로 설치해줘야 합니다.

bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

sudo pip install /tmp/tensorflow_pkg/tensorflow-0.10.0rc0-py2-none-any.whl

 

이제 tensorflow 안에 있는 MNIST 예제를 실행해 봅니다.

cd tensorflow/models/image/mnist

python convolutional.py


GPU 잘 잡고 에러 안뜨면 성공입니다. 짝짝짝


만약 init를 못한다는 에러가 나면 아래와 같이 실행한 후 다시 해보세요.

sudo ldconfig /usr/local/cuda/lib64

sudo python convolutional.py


이렇게 한번 하고 나면 다음부터 잘됩니다.


Posted by uniqueone
,

http://pythonkim.tistory.com/71

문제점.pdf


I follow this post, however, I got an error after < bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package>

"The specified --crosstool_top '@local_config_cuda//crosstool:crosstool' is not a valid cc_toolchain_suite rule. ..."

However, this provide some guidance.


Then I follow the http://blog.naver.com/kjpark79/220781100554, and I succeed.




이번 글의 수명이 길지는 않을 것으로 보인다. 텐서플로우는 RC 버전이고, 그래픽 카드 또한 최신이고, 우분투 16.04도 방금 나온 최신 버전이고, 파이썬도 최신 버전이고. 검증하지 않은 것들이 모일 수 있기 때문에 설치 과정에서 수많은 시행착오를 거칠 수밖에 없었다. 최신이어서 참고할 사이트도 많이 없다.


컴퓨터 사양


문제점

1. 지포스 10 시리즈는 PASCAL 방식으로 제작되었다고 한다. 그래서인지 CUDA 7.5와 연동하면 정확도가 떨어지는 문제점이 있었다. 90%의 정확도가 아니라 10%의 정확도로 나와서 경악을 금치 못했다. 속도는 무지 빨랐다.

2. 텐서플로우 0.10과 CUDA 7.5 연동이 잘 되지 않았다. 처음에는 괜찮았던 기억이 있는데, 어느 순간부터는 충돌이 발생하면서 설치할 수 없었다. CUDA 8.0 설치를 포기해야겠다고 생각하면서 하위 버전 설치에 꽤나 주력했었다.

3. CUDA 8.0을 사용하려면 텐서플로우를 바이너리 버전이 아니라 소스코드 버전으로 설치해야 한다. 현재 시점에서는 텐서플로우 0.10에 대한 링크가 없어서 바이너리 버전 설치는 불가능했다. 당연히 0.9 버전을 설치하기 위해서도 많이 애를 썼었다. 소스코드 버전 설치는 컴파일부터 진행하기 때문에 해야 할 게 무척 많아진다.


공통 사항

1. 터미널(콘솔)

단축키 : ctrl + alt + t 또는 ctrl + alt + f1
처음에 터미널 창을 열면 항상 ~ 폴더에서 시작한다. ~ 폴더는 사용자의 홈 폴더를 말하고, 어디에 있건 "cd ~" 명령을 통해 항상 홈 폴더로 이동할 수 있다.

모든 설치는 터미널에서 진행되기 때문에 그래픽 화면이 전혀 사용되지 않는다. 화면 캡쳐할 것이 없다는 뜻이다. 입력하기가 번거롭기 때문에 본문에 있는 명령을 붙여 넣는 것이 쉬울 것이다. 터미널에서는 [ctrl+c, ctrl+v] 단축키가 동작하지 않으므로, 마우스 오른쪽 버튼 메뉴를 사용해야 한다.

[ctrl + alt + f1]은 그래픽 모드로부터 완전히 벗어난 형태의 터미널을 생성한다. 모니터 전체를 터미널이 덮는 모드를 말한다. 이와 같은 전체 터미널 모드는 엔비디아 드라이버를 설치할 때, 딱 한 번만 사용하고, 나머지는 모두 [ctrl + alt + t]를 사용한다.


2. 명령줄 자동완성

파일 이름을 입력할 때, TAB키를 누르면 일치하는 파일 이름을 자동으로 입력해 준다. 파일 이름을 여러 번 입력하기 때문에 기억하면 매우 편리하다. 간혹 동작하지 않을 때도 있는데, 잘못된 것이 아니라 리눅스의 환경 문제이므로, 그런 경우에는 차분하게 파일 이름을 모두 입력해야 한다.


3. 무한 로그인 에러 해결 방법

[ctrl + alt + f1] 단축키를 사용해서 터미널로 이동해서 다시 엔비디아 드라이버를 설치하면 된다. 무한 로그인 에러는 엔비디아 드라이버와의 충돌 과정에서 발생하기 때문에 다시 설치하면 사라진다.

이 에러는 상상을 초월할 정도의 유명한 에러인데, 별의별 방법으로 해결을 하려고 노력했지만 끝내 하지 못했었다. 이 방법을 알고 있었다면, 우분투 설치 횟수를 25회 정도로 막을 수도 있었다. 생각할수록 화가 난다.

그래픽 화면으로 넘어갈 때는 [alt + f7] 단축키. 다만 그 전에 아래 명령을 사용해서 그래픽 모드를 활성화시켜야 한다.
$ sudo service lightdm start


4. 텍스트 파일 편집

경로 등을 저장하기 위해 텍스트 파일을 편집하게 되는데, 이 때 gedit 프로그램을 사용한다. 파일을 열거나 저장할 때 아래와 같은 경고가 뜨는데, 설치와는 전혀 상관없다. 터미널에서 그래픽에 접근하는 과정에서 표시되는 경고일 뿐이다.

(gedit:27848): IBUS-WARNING **: The owner of /home/python-kim/.config/ibus/bus is not root!
(gedit:27848): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files

** (gedit:27848): WARNING **: Set document metadata failed: metadata::gedit-spell-enabled 속성 설정은 지원하지 않습니다
** (gedit:27848): WARNING **: Set document metadata failed: metadata::gedit-encoding 속성 설정은 지원하지 않습니다
** (gedit:27848): WARNING **: Set document metadata failed: metadata::gedit-position 속성 설정은 지원하지 않습니다


참고 사이트

1. 성공 사이트

https://marcnu.github.io
https://marcnu.github.io/2016-08-17/Tensorflow-v0.10-installed-from-scratch-Ubuntu-16.04-CUDA8.0RC-cuDNN5.1-1080GTX

순서대로 정리가 너무 잘 되어 있는 외국 사이트. 텐서플로우KR에 누가 올려놓은 자료인데.. 일단 내 컴퓨터와는 궁합이 너무 잘 맞았다.


2. 실패 사이트

http://textminingonline.com/dive-into-tensorflow-part-iii-gtx-1080-ubuntu16-04-cuda8-0-cudnn5-0-tensorflow

이 사이트의 내용에 대해서는 매번 실패를 했지만, CROSSTOOL.tlp 파일을 수정하는 부분만 있으면 성공할 거라고 생각한다. 이 방식은 그래픽 모드에서 전혀 벗어나지 않기 때문에 설치된다고 하면 이 방식이 훨씬 낫다. 설치 명령과 함께 에러 메시지도 표시하기 때문에 안심하고 진행할 수 있는 장점도 있다.


엔비디아 다운로드

헷갈리지 않게 미리 다운로드 받아서 설치 가능한 상태로 만들어 놓고 시작한다. 순서가 너무 많아서 헷갈린다. 윈도우와 똑같이 다운로드한 파일은 다운로드 폴더에 저장된다. 다운로드한 파일을 모두 홈 폴더로 복사하자. 나 같은 리눅스 초보는 홈 폴더에서 작업하는 것이 좋다. 리눅스 공부는 설치가 끝난 다음에 하도록 하자. 파일 복사는 윈도우와 동일한 탐색기를 사용하면 된다.


1. 드라이버 다운로드 (버전 367.44)

자신의 그래픽 카드에 맞는 드라이버를 다운로드 받아야 한다. 현재 버전은 367.44이고, Linux 64-bit 버전이어야 한다. 64비트 버전이 보이지 않으면, Operatiing System 항목에서 [Show all Operating Systems] 메뉴를 선택한다. 쉽게 실행할 수 있도록 실행 모드를 추가한다. 이제 실행 파일처럼 더블클릭으로 실행할 수 있는 상태가 된다.

$ chmod +x NVIDIA-Linux-x86_64-367.44.run


2. CUDA 다운로드 (버전 8.0RC) 회원 가입 필수

그림에 나와 있는 것처럼 정확하게 우분투16.04, 64비트 버전을 선택한다. 파일을 다운로드 받아서 설치하는 runfile(local)까지 선택한다. 이 파일의 확장자는 run이다. 현재 시점에서는 우분투에 기본 설치되는 gcc 5.4에 대한 패치 파일이 별도로 존재한다. 이 파일까지 함께 받는다. 파일 2개에 대해 한 번에 실행 권한을 준다.

$ chmod +x cuda_8.0.27_linux.run  cuda_8.0.27.1_linux.run


3. cuDNN 다운로드 (버전 5.1 Library for Linux) 회원 가입 필수

다운로드한 파일의 압축을 풀고, 외부 모듈이 실행할 수 있도록 이동하고 접근 권한을 바꾼다. 압축을 풀면 현재 폴더에 cuda 폴더를 생성하고 그 안에 파일을 넣어 둔다. 여기서는 CUDA 8.0을 사용하기 때문에 목표 폴더 이름에 cuda-8.0이 들어간다.


엔비디아 설치

1. 드라이버 설치

윈도우와 같은 그래픽 환경에서 이 글을 볼 것이다. 그렇다면 [ctrl + alt + f1]을 눌러서 터미널로 이동한다. 그래픽 화면을 종료하고 그래픽 카드를 구동하는 드라이버를 설치한다. 드라이버가 설치되면, 게임도 할 수 있고, 동영상도 볼 수 있고, 그래픽 카드를 사용하는 대부분의 것들을 할 수 있게 된다. 내 경우는 모니터 2대를 연결해서 사용할 수 있게 되었다. 드라이버 설치가 끝나면, 컴퓨터를 껐다가 켠다. (리부팅)

지금 보는 화면은 그래픽 화면이기 때문에 터미널 모드로 들어가면, 지금 보는 설명을 볼 수 없다. 외워도 좋고, 안 되면 종이에 써놓고 터미널로 입장하자.

드라이버 설치할 때 여러 번 엔터 키를 눌러야 한다. accept나 yes와 같은 긍정적인 것들만 선택하도록 한다. 6~7번 정도 필요하다.

$ sudo service lightdm stop
$ sudo init 3
$ sudo ./NVIDIA-Linux-x86_64-367.44.run
$ sudo reboot


드라이버 파일에 실행 권한을 주지 않았다면, 아래 명령을 통해서 run 파일을 구동할 수 있다. 다만 파일 이름을 자동으로 완성할 수 없기 때문에 직접 입력해야 한다.

$ sudo sh NVIDIA-Linux-x86_64-367.44.run


2. CUDA 메인 설치

컴퓨터가 새로 켜졌다. 터미널 모드로 입장해야 하니까, [ctrl + alt + t] 단축키를 누른다. 패치 파일을 포함한 2개 파일을 순서대로 모두 설치한다. 메인 파일에만 --override 옵션이 붙는다. gcc 5.3까지만 인정하기 때문에 이걸 무시하기 위해 추가하는 것이 override 옵션이다. 이걸 수정하기 위한 파일이 패치 파일이다.

$ sudo ./cuda_8.0.27_linux.run --override

드라이버 설치와 마찬가지로 실행 권한을 주지 않았다면, 아래 명령을 사용한다.

$ sudo sh cuda_8.0.27_linux.run --override

아래에 빨간 글자처럼 입력한다. '엔터'라고 되어 있는 항목은 default 값을 사용한다는 뜻이다. 가장 중요한 항목은 두 번째에 있는 361.77 드라이버 설치 문항이다. yes라고 입력하면, 앞에서 설치한 최신 버전을 덮어 쓴다. sample은 설치하지 않아도 되지만, CUDA가 설치되었는지 sample을 통해 확인할 수 있기 때문에 설치하는 것이 좋다.


# ----------------------------- 설치 내용 --------------------------------- #

Do you accept the previously read EULA? accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.77? (y)es/(n)o/(q)uit: n
Install the CUDA 8.0 Toolkit? (y)es/(n)o/(q)uit: y
Enter Toolkit Location [ default is /usr/local/cuda-8.0 ]: 엔터
Do you want to install a symbolic link at /usr/local/cuda? (y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples? (y)es/(n)o/(q)uit: y
Enter CUDA Samples Location [ default is /home/python-kim ]: 엔터

Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libGLU.so.
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/python-kim ...
Copying samples to /home/python-kim/NVIDIA_CUDA-8.0_Samples now...

Finished copying samples.

============ Summary ============

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Installed in /home/python-kim, but missing recommended libraries

Summary에서 Driver는 설치되지 않은 것을 볼 수 있다. Toolkit은 설치되었지만, Samples는 설치되지 않은 항목이 있다. 361.77 드라이버를 설치할 때, OpenGL 라이브러리 설치를 물어보는데, 우리는 설치하지 않았기 때문에 OpenGL 샘플도 설치하지 않았다는 뜻이다. OpenGL은 우분투에서 그래픽 카드와 충돌나기로 유명하다. 우리는 자연스럽게 설치를 피했다.


3. CUDA 패치 설치

우분투에 기본으로 설치된 gcc 5.4 버전을 위한 패치 파일을 실행시킨다. override 옵션은 필요 없다. 설치가 너무 간단해서 신경써서 입력할 항목이 없다.

$ sudo ./cuda_8.0.27.1_linux.run


드라이버 설치와 마찬가지로 실행 권한을 주지 않았다면, 아래 명령을 사용한다.

$ sudo sh cuda_8.0.27.1_linux.run


# ----------------------------- 설치 내용 --------------------------------- #

Do you accept the previously read EULA?
accept/decline/quit: accept

Enter CUDA Toolkit installation directory
[ default is /usr/local/cuda-8.0 ]: 엔터

Installation complete!
Installation directory: /usr/local/cuda-8.0


4. 환경 구성

라이브러리와 CUDA를 사용할 수 있도록 경로를 추가한다. 먼저 환경 파일을 연다.

$ sudo gedit ~/.bashrc


아래 내용은 .bashrc 파일의 마지막에 추가한다.

export CUDA_HOME=/usr/local/cuda-8.0
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}


추가한 내용을 즉각 반영한다.

$ source ~/.bashrc


5. 드라이버 및 CUDA 설치 확인

$ nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Wed_May__4_21:01:56_CDT_2016
Cuda compilation tools, release 8.0, V8.0.26


$ nvidia-smi

터미널에서는 깔끔하게 출력이 되는데, html 파일에서는 깨진다. 감안하고 보자.

Tue Aug 30 19:59:47 2016
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.44         Driver Version: 367.44        |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 106...  Off  | 0000:01:00.0      On |        N/A |
| 33%   33C    P8    10W / 130W |    257MiB /  6064MiB |   0%   Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:             GPU Memory |
|  GPU  PID  Type  Process name     Usage |
|=============================================================================|
|   0   2733   G   /usr/lib/xorg/Xorg       227MiB |
|   0   3461   G   compiz      28MiB |
+-----------------------------------------------------------------------------+


6. CUDA 샘플 구동

현재 폴더(사용자 홈)에 샘플 폴더가 설치되고, 이름은 NVIDIA_CUDA-8.0_Samples. 이 폴더 안에 들어가면 여러 개의 폴더가 보이는데, 모두 CUDA로 확인할 수 있는 샘플들이다. 샘플을 구동하는 규칙은 모두 같다. 해당 폴더로 이동해서 make 명령을 입력하고, 생성된 실행 파일을 실행시킨다.

$ cd NVIDIA_CUDA-8.0_Samples/1_Utilities/bandwidthTest/
$ make

"/usr/local/cuda-8.0"/bin/nvcc -ccbin g++ -I../../common/inc  -m64    -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o bandwidthTest.o -c bandwidthTest.cu
"/usr/local/cuda-8.0"/bin/nvcc -ccbin g++   -m64      -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o bandwidthTest bandwidthTest.o
mkdir -p ../../bin/x86_64/linux/release
cp bandwidthTest ../../bin/x86_64/linux/release

$ ./bandwidthTest 

[CUDA Bandwidth Test] - Starting...
Running on...

 Device 0: GeForce GTX 1060 6GB
 Quick Mode

 Host to Device Bandwidth, 1 Device(s)
 PINNED Memory Transfers
   Transfer Size (Bytes)    Bandwidth(MB/s)
   33554432            12542.1

 Device to Host Bandwidth, 1 Device(s)
 PINNED Memory Transfers
   Transfer Size (Bytes)    Bandwidth(MB/s)
   33554432            12322.1

 Device to Device Bandwidth, 1 Device(s)
 PINNED Memory Transfers
   Transfer Size (Bytes)    Bandwidth(MB/s)
   33554432            141467.7

Result = PASS

NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.


7. cuDNN 설치

이건 설치할 게 없다. 다운로드한 파일을 압축을 풀어서 복사해서 붙여넣기만 하면 된다. 앞에서 CUDA 샘플을 구동하기 위해 샘플 폴더로 이동했기 때문에 홈 폴더로 이동하는 것까지 포함한다.

$ cd ~
$ tar xvzf cudnn-8.0-linux-x64-v5.1.tgz
$ sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include/
$ sudo cp cuda/lib64/* /usr/local/cuda-8.0/lib64/


텐서플로우 설치

1. 파이썬 환경 구축

우분투 16.04에는 파이썬 2.7과 3.5가 모두 설치되어 있다. 최신 버전을 무조건 좋아하기 때문에 여기서는 3.5 버전을 중심으로 얘기한다. 일단 텐서플로우 설치에 사용할 파이썬 도구를 설치한다. 혹시라도 이번 명령이 동작하지 않으면, 바로 아래 있는 [자바 JDK 설치]를 먼저 진행하기 바란다.컴퓨터를 껐다 켜게 되면, 설치 중인 정보가 날아가서 이번 명령이 실패할 수도 있다. 이때, [자바 JDK 설치]가 정보를 복구해줄 수도 있다.


파이썬 3.5
$ sudo apt-get install python3-pip python3-numpy swig python3-dev python3-wheel

파이썬 2.7
$ sudo apt-get install python-pip python-numpy swig python-dev python-wheel


2. 자바 JDK 설치

텐서플로우를 빌드하기 위해 JDK를 먼저 설치해야 한다. Bazel에서 필요로 한다. 이 부분은 파이썬 버전과 상관이 없다.

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer


3. Bazel 설치

Bazel은 구글 내에서 사용하는 프로젝트를 빌드하기 위한 범용 도구이다. 여기서는 텐서플로우를 빌드하기 위해 사용한다. 이번 명령이 좀 길기는 하지만, 복사해서 붙여넣기할 거니까 빠지지 않도록 조심한다. 리눅스 명령에 익숙하면 분리할 수도 있는데, 좀 해봤는데.. 잘 안됐다. 나중에 고민하도록 하자.

$ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
$ curl https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add -
$ sudo apt-get update && sudo apt-get install bazel
$ sudo apt-get upgrade bazel


4. 텐서플로우 소스코드 다운로드

git을 설치한다. 혹시 설치되어 있다면, 당연히 건너뛰어도 된다.

$ sudo apt install git


텐서플로우 소스코드 저장소 구축

$ git clone -b r0.10 https://github.com/tensorflow/tensorflow


5. CROSSTOOL 파일 수정

이 부분이 가장 중요하게 생각된다. 실제로 이전에 시도한 수없이 많은 방법 중에서 이 부분을 제외하면 그다지 다를 것이 없었다. 그런데, 동작하지 않았다. 수정할 파일은 홈 폴더의 "tensorflow/third_party/gpus/crosstool" 폴더에 있는 CROSSTOOL.tpl 파일이다.


파일 열기
$ sudo gedit ~/tensorflow/third_party/gpus/crosstool/CROSSTOOL.tpl


추가할 내용
cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"


추가할 위치(내 경우엔 67행)
cxx_builtin_include_directory: "/usr/lib/gcc/"
cxx_builtin_include_directory: "/usr/local/include"
cxx_builtin_include_directory: "/usr/include"
cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"    <----- 여기 추가
tool_path { name: "gcov" path: "/usr/bin/gcov" }


6. Bazel 환경 구축

먼저 tensorflow 폴더로 이동한 다음에 configure 파일을 실행시킨다. 역시 빨간색으로 처리된 부분을 정확하게 입력하도록 한다. 파이썬 3.5를 사용하기 때문에 첫 번째 항목에서 python3이라고 했다. 2.7을 사용한다면 아무 것도 입력하지 않으면 된다. 구글 플랫폼의 두 번째 항목은 필요없기 때문에 No라고 입력했다.

마지막의 그래픽 카드 버전이 가장 여려운데, 기본은 3.5와 5.2의 두 가지다. 1060의 경우 6.1로 입력해야 하는데, 다음 주소를 통해 그래픽 카드의 버전 숫자를 찾을 수 있다. (그래픽 카드 버전 숫자 찾기로 이동)


$cd ~/tensorflow
$ ./configure
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with GPU support? [y/N] y
GPU support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: 엔터
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 엔터
Please specify the location where CUDA  toolkit is installed. Refer to README.md for more details.
[Default is /usr/local/cuda]: usr/local/cuda-8.0
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 엔터
Please specify the location where cuDNN  library is installed. Refer to README.md for more details.
[Default is /usr/local/cuda-8.0]: 엔터
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 6.1

...

INFO: All external dependencies fetched successfully.
Configuration finished


7. 텐서플로우 설치

bazel을 사용해서 텐서플로우를 빌드한다. 빌드한 결과물은 /tmp/tensor_pkg 폴더에 들어간다.

$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg


앞에서 사용한 결과물을 pip 명령을 통해 설치한다. 버전2와 버전3에서 파일 이름이 다른데, 중요하지 않다. 중요한 것은 /tmp/tensorflow_pkg 폴더에 있는 파일을 사용해야 한다는 점이다. 이름을 외울 필요는 없다. tensor까지 입력하고 tab 키를 누르면 자동 완성된다. 파일이 1개밖에 없다.


파이썬 3.5
$ pip3 install /tmp/tensorflow_pkg/tensorflow-0.10.0rc0-py3-none-any.whl

파이썬 2.7
$ pip install /tmp/tensorflow_pkg/tensorflow-0.10.0rc0-py2-none-any.whl


8. 텐서플로우 사용

아쉽지만, 우분투를 재시동해야 한다. 내 경우는 그랬다. 조금만 참자.
컴퓨터가 새로 켜졌다면 터미널에 아래와 같이 입력해 보자.


파이썬 3.5
$ python3 -c 'import tensorflow'

파이썬 2.7
$ python -c 'import tensorflow'


출력 결과는 아래와 같이 나와야 한다. 만약 아무 것도 출력되지 않았다면, 실패한 것이다. 이 시점에서 정말 많은 눈물을 흘려야 했다. 나타나지 않았다면, 우분투를 다시 설치하는 것부터 시작하면 된다. 윈도우는 그대로 둬도 된다.

I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally


잘 됐다면 진짜 코드로 확인을 해야 한다. mnist 예제를 돌려 보자.


파이썬 3.5
$ python3 tensorflow/tensorflow/models/image/mnist/convolutional.py

파이썬 2.7
$ python tensorflow/tensorflow/models/image/mnist/convolutional.py


놀랍게도 1시간 걸리던 예제가 불과 1분만에 해결됐다. 에러는 0.8*, 정확도 99.2%의 훌륭한 결과를 보여줬다.

I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties:
name: GeForce GTX 1060 6GB
major: 6 minor: 1 memoryClockRate (GHz) 1.759
pciBusID 0000:01:00.0
Total memory: 5.92GiB
Free memory: 5.55GiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:838] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0)
Initialized!
Step 0 (epoch 0.00), 19.7 ms
Minibatch loss: 12.054, learning rate: 0.010000
Minibatch error: 90.6%
Validation error: 84.6%
...
...
Step 8400 (epoch 9.77), 7.2 ms
Minibatch loss: 1.596, learning rate: 0.006302
Minibatch error: 0.0%
Validation error: 0.8%
Step 8500 (epoch 9.89), 7.2 ms
Minibatch loss: 1.603, learning rate: 0.006302
Minibatch error: 0.0%
Validation error: 0.8%
Test error: 0.8%


Posted by uniqueone
,

http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_linux.run




from this site

https://devtalk.nvidia.com/default/topic/932554/-ubuntu-16-04-install-cuda-7-5/

Posted by uniqueone
,

http://askubuntu.com/questions/303290/where-is-usr-local



I ran the following code in a terminal:

python -c "                 
import sys
sys.path = sys.path[1:]
import django
print(django.__path__)"

This returns the following path:

['/usr/local/lib/python2.7/dist-packages/django']

but I simply cannot find usr/local (from the GUI). Where should it be?

I'm not sure what other information would help, please let me know!

shareimprove this question


2  
/usr/local is a location. – psusi Jun 2 '13 at 21:56
    
@psusi I'm pretty sure OP knows it's a location, but apparently he's not familiar with nautilus, which starts you in your home folder, and you need to go up form it to the root directory – Serg Apr 16 '15 at 20:21
up vote 0 down vote accepted

type

sudo cd /usr/local/lib/python2.7/dist-packages

in to terminal. That should take you to the folder

The usr folder is part of the file system, it is accessed from the root of your file system

shareimprove this answer

    
Sorry, I meant is there a way to access it from the GUI? – Colton Jun 2 '13 at 20:37
1  
Type sudo nautilus in to teminal, this gives you access to root folders – SimplySimon Jun 2 '13 at 20:48
    
Alright I got it, thanks. – Colton Jun 2 '13 at 20:52
    
My pleasure. Glad to be of assistance. :D – SimplySimon Jun 2 '13 at 21:04
    
You do not need to sudo to cd to /usr/local though you would not be able to edit the files. You do need root privileges for editing but the files are visible as a reugular user. – haziz Feb 1 '14 at 14:55
cd /usr/local

will get you there

You do need root privileges to edit files there, in which case you can invoke sudo, be very cautious about meddling with files however in the /usr directory and in the root directory / in general.

BTW don't be afraid of the command line! A useful introduction to the CLI is available here.

shareimprove this answer

Where should it be? By default when you open the file manager you run around your home directory(/home/username), same as in windows C:\Users\Username . Notice how /usr/local starts with backslash ? There's root directory from which you can access other directories; the image to keep in mind is the root directory is where root starts, and everything else is branching form it

How to access the folder you need:

Method #1 : press CtrlL in the file manager ( which is called nautilus, by the way) and type /usr/local into the address bar or / .

Method#2: Pressing repeatedly AltArrow Up buttown in file manager will get you to root directory (which is like C:\ folder in windows), and navigate graphically to whatever folder you need from there.

Method #3: Press AltF2 to open "Run command" dialogue and type nautilus /usr/local

Posted by uniqueone
,

http://luke77.tistory.com/44


기반 시스템 정보:


System memory: 8G

Processor: Intel core i5-2500K 3.3GHz x 4

Graphics: Geforce GTX 970/PCIe/SSE2

OS type: Ubuntu 64-bit (영문)



본 내용은 예람님의 블로그 내용(Refer)을 참고하여 작성되었음.


기타 참고 사이트


http://bit.ly/2aIcOXw

http://bit.ly/2aTDiVc

http://bit.ly/2a93SNg

http://bit.ly/2ar2ilL

http://bit.ly/2adltyT

http://bit.ly/2aTCJeg

http://bit.ly/2a930rD

http://bit.ly/2alSU8q






0. 그래픽 카드 드라이버 설정 (작업 편의성을 위함, 이미 설치되어 있다면 Skip 해도 됨)


1) 터미널을 실행시키고, Ubutu 에  GPU Drivers PPA를 추가하고 소프트웨어 소스를 업데이트 함


sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update


2) System settings 을 실행시키고, System 카테고리의 Software & Updates 를 실행함. Additional Drivers 탭에서 최신 바이너리 드라이버 항목을 선택하고 "Apply Changes" 선택. 해당 드라이버가 자동으로 다운로드되고 설치됨. 시스템을 리부팅하면 설치 완료.








1. Anaconda 설치


1) https://www.continuum.io/downloads 에서 Anaconda for Linux Python 2.7 Linux 64-bit 버전 다운로드 함.



2) 터미널에서 다운로드 받은 폴더로 이동하고, 다음을 입력하여 Anaconda를 설치함


bash Anaconda2-4.1.1-Linux-x86_64.sh 


(버전명은 다를 수 있으므로 다운로드 받은 파일에서 확인할 것)


중간 중간에 나오는 질문에는 모두 "yes" 한다.


home으로 나와서 (cd ~ 입력) gedit .bashrc 입력. 맨 하단에 Anaconda path 가 다음의 형태로 잘 적용되어 있는지 확인함.


# added by Anaconda2 4.1.1 installer
export PATH="/home/사용자명/anaconda2/bin:$PATH"



Terminal 을 종료하고 재실행 후 python 을 입력. 다음과 같은 형태의 문구가 보이고, import matplotlib 를 입력했을 때 에러가 없다면 성공.











2. CUDA Toolkit 설치


공식 TensorFlow 설치 페이지를 보면, 현재까지는 Cuda Toolkit 7.5와 cuDNN v4 를 반드시 설치하여야 함.



1) https://developer.nvidia.com/cuda-downloads 에 접속하여 Linux 용 runfile(local) 파일 다운로드.





2) cuda 7.5와 호환되는 gcc 컴파일러 설치


sudo apt-get install gcc-4.9 g++-4.9


3) 추가 패키지 설치


sudo apt-get install nvidia-modprobe freeglut3-dev libx11-dev libxmu-dev libxi-dev libglu1-mesa-dev


4) 다운로드 받은 폴더로 이동하여, 런파일을 이용한 CUDA 설치


-EULA 동의 : accept

-You are attempting to install on an unsupported configuration. Do you with to continue? : yes

-Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 352.39 ? no (이미 설치했음)

-Install the CUDA 7.5 Toolkit? yes

-Enter Toolkit Location : Enter (default)

-Do you want to install a symbolic link at /usr/local/cuda ? yes

-Install the CUDA 7.5 Samples? no

-Enter CUDA Samples Location : Enter (default)


sudo sh cuda_7.5.18_linux.run --override


5) cd ~ 입력 후 홈으로 이동. gedit .bashrc 입력/실행. 맨 마지막 줄에 다음을 입력 후 저장


export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export CUDA_HOME=/usr/local/cuda









3. CUDNN 설치


1) https://developer.nvidia.com/cudnn 접속. Download 버튼을 통해 설치 (NVIDIA 가입 필요)

2) 다운로드 받은 파일을 우클릭하여 압축을 품. CUDA 폴더가 생성됨.

3) 다음을 입력하여 관리자 권한으로 탐색기 실행. usr/local/cuda 로 진입

sudo nautilus

4) CUDA/include 폴더 내에 들어있는 파일을 usr/local/cuda/include 에 복사

5) CUDA/lib64 폴더 내에 들어 있는 파일을 usr/local/cuda/lib64 에 복사

6) 다음 명령어 수행 (CUDNN을 전체 사용자가 사용)


sudo chmod a+r /usr/local/cuda/lib64/libcudnn*









4. TesnsorFlow 설치


1) Bazel 컴파일러 설치 (from Google)


- 자바 설치

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

- 압축 프로그램 for Bazel 설치

sudo apt-get install pkg-config zip g++ zlib1g-dev unzip


- Bazel 다운로드 (현재 버전 0.3.1) : https://github.com/bazelbuild/bazel/releases



- 다운로드 받은 폴더에서 하기의 내용을 입력하고 Bazel 설치

chmod +x bazel-0.3.1-installer-linux-x86_64.sh
./bazel-0.3.1-installer-linux-x86_64.sh --user

- cd ~ 으로 홈으로 이동. gedit .bashrc 를 입력/실행하고 맨 하단에 다음을 입력 및 저장

export PATH="$PATH:$HOME/bin"



2) numpy 설치

sudo apt-get install python-numpy swig python-dev


3) TensorFlow 다운로드 및 설치



- Git 설치

sudo apt-get install git

- TensorFlow 소스 다운로드

git clone --recurse-submodules https://github.com/tensorflow/tensorflow

- TensorFlow 설정. tensorflow 폴더 진입 및 configure 설정

cd ~/tensorflow
./configure

Please specify the location of python. - Enter (default)

Do you with to build TensorFlow with Google Cloud Platform support? N

(난 Hadoop도 설치할거냐고 해서 y를 누름)

Do you wish to build TensorFlow with GPU support? y

Please specify which gcc should be used by nvcc as the host complier. : /usr/bin/gcc-4.8 (4.8이 아니고 4.9임)

Please specify the Cuda SDK version you want to use: 7.5 (난 8.0)

Please specify the location where CUDA 7.5 toolkit is installed. Refer to README.md for more details. : Enter (default)

Please specify the Cudnn version you want to use. : 4 (난 5)

Please specify the location where cuDNN 4.0 library is installed. Refer to README.md for more details. : Enter (default)

Please note that each additional compute capability significantly increases your build time and binary size. : 3.5






- TensorFlow 소스 컴파일 (상기 tensorflow 폴더에서)


bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

- 컴파일 중 에러 발생 시 확인 사항


  컴파일러 호환 문제라면 gcc 4.8 설치 (예. #error -- unsupported GNU version! gcc versions later than 4.9 are not supported!)

sudo apt-get install gcc-4.8 g++-4.8


  기타 여러 에러 발생시, 홈폴더 이동하여, tensorflow/third_party/gpus/crosstool/ 내 CROSSTOOL 파일에서,


  * cxx_builtin_include_directory: "/usr/local/cuda-7.5/include" (cxx_builtin_ 등이 있는 부분에 모두 삽입)

 

 * cxx_flag: "-std=c++11" 하단에  (두 군데 존재) 삽입

 

     cxx_flag: "-D_FORCE_INLINES"
     cxx_flag: "-D_MWAITXINTRIN_H_INCLUDED"




- TensorFlow 설치 패키지 생성

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg


- 패키지 확인: tmp/tensorflow_pkg 내 tensorflow-0.9.0-py2-none-any.whl 파일이 있는지 확인 (버전명은 상이할 수 있음)



- Anaconda에 TensorFlow 설치 (버전명은 상이할 수 있음)


pip install /tmp/tensorflow_pkg/tensorflow-0.9.0-py2-none-any.whl



- Tensorflow 설치 확인: 하기의 소스코드를 실행하여 결과 확인 (터미널 실행 후 python 입력)


python

import matplotlib
import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))


- 다음과 같이 출력되면 성공. CUDA 관련 library들이 제대로 로딩되고, GPU가 제대로 인식되면 됨




- 만일 modprobe: ERROR: could not insert 'nvidia_xxx_uvm': Invalid argument 와 같은 에러와 함께 GPU 인식이 되지 않는다면 그래픽 드라이버 호환의 문제일 가능성이 높음.




이 경우 필자의 경우엔, nvidia cuda toolkit 을 설치하고 해당되는 에러의 그래픽 드라이버 버전으로 재설치 하였음.



Toolkit 설치

sudo apt install nvidia-cuda-toolkit

드라이버 재설치

sudo apt-get purge nvidia*
sudo killall nvidia-persistenced (없다고 나오면 그냥 skip)
sudo apt-get update
sudo apt-get install nvidia-358 nvidia-prime
sudo reboot










5. IDE 설치 (여기서는 PyCharm 설치)


1) PyCharm 다운로드 (https://www.jetbrains.com/pycharm/download/#section=linux)


- Community 의 경우 무료

- Professional 의 경우, 학생이라면 1년간 무료 이용 가능


2) 다운로드 받은 폴더로 가서 압축을 품. Pycharm 디렉토리를 적당한 위치에 복사 (여기서는 Home에 복사)


3) cd pycharm-2016.2/bin 이동 (폴더명은 상이할 수 있음)


4) gedit pycharm64.vmoptions 으로 해당 파일을 메모장에 열고, Xmx750m 을 부분을 수정한다. 최대 메모리를 설정하는 것으로 여기서는 4096m 으로 수정 (4GB)





5) bash pycharm.sh 를 입력하여 설치 및 실행





6) PyCharm 아이콘을 우클릭하여, lock from launcher를 클릭하여 런처에 고정함.



7) 터미널을 열고 다음을 입력함 (경로는 상이할 수 있으니 확인할 것)


sudo ldconfig /usr/local/cuda/lib64


8) Pycharm 종료 후 다시 실행시키고 프로젝트 생성 후 다음의 코드를 통해 실행 여부 확인


- 처음 실행시, Updating indicies, Updating python interpreter 작업으로 첫 코딩 가능 시간까지 시간이 걸림.


- GPU Test (다음의 코드 입력 후 실행시키면 반드시 하기 스크린 샷과 같은 결과가 도출되어야 함) : Google TensorFlow 관련 내용 참고(링크)


import tensorflow as tf

# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print sess.run(c)

- 결과





- 최종적으로 Linear regression 예제가 GPU 연산으로 제대로 돌아가는 지 확인한다. (관련 소스 링크)




Posted by uniqueone
,