'Deep Learning/TensorFlow'에 해당되는 글 23건

  1. 2023.09.07 tensorflow/keras에 입력영상채널개수를 3채널이 아닌 다른 채널수(예: 6개)로 입력시켜주는 방법
  2. 2022.08.19 ImageDataGenerator는 데이터셋 이미지개수를 증가시키진 않고 매 epoch마다 원본을 변환을 할 뿐이라서 개수는 같다 Does ImageDataGenerator add more images to my dataset?
  3. 2021.04.14 failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
  4. 2020.03.18 역시 #TFDevSummitKR 키노트에 소개될 만큼 TensorFlow KR 그룹의 저력을 느낄 수 있었습니다. 이 자리를 빌어 하루만에 조회
  5. 2019.11.30 안녕하십니까? 저는 기계공학(열유체공학)전공자입니다. 기계설계에 있어 데이터 및 인공신경망을 적용하고자 합니다. 텐서플로를 활용하여, DNN을 이용하여 기계의 성능예측 주제로 SCI 논..
  6. 2019.10.01 예전에 keras모델(SavedModel)을 tflite 모델로 변환시키는 과정에서 bn(batch normalization)이 전부 빠져서 알아보니 tflite는 bn을 지원하지 않는다는 글을 본적이 있었습니다.혹시 아직도 tflite는 bn을 지..
  7. 2018.02.22 deploy a CNN that could understand 10 signs or hand gestures.
  8. 2017.07.26 Quick complete Tensorflow tutorial to understand and run Alexnet, VGG, Inceptionv3, Resnet and squeezeNet networks
  9. 2017.07.05 LSTM을 이용한 감정 분석 w/ Tensorflow. 텍스트파일에서 감정상태 분류
  10. 2017.04.11 Python TensorFlow Tutorial – Build a Neural Network
  11. 2017.03.24 Time Series Forecasting with Python 7-Day Mini-Course
  12. 2017.03.21 TensorFlow: training on my own image
  13. 2017.03.18 Simple Reinforcement Learning with Tensorflow Part 0: Q-Learning with Tables and Neural Networks
  14. 2017.01.19 sequence-to-sequence 모델인 "Pointer Networks 구현
  15. 2017.01.18 Implementation of Grad CAM in tensorflow
  16. 2017.01.09 딥러닝을 이용한 숫자 이미지 인식 #1/2-학습
  17. 2017.01.05 YouTube에서 'Installing CPU and GPU TensorFlow on Windows' 보기
  18. 2017.01.05 YouTube에서 'how to natively install tensorflow on windows' 보기
  19. 2016.12.20 Machine Learning with TensorFlow
  20. 2016.11.28 Image Classification and Segmentation with Tensorflow and TF-Slim
  21. 2016.11.26 Tensorflow and deeplearning without at Ph.D
  22. 2016.11.15 TensorFlow Tutorial 한국어 슬라이드 및 코드
  23. 2016.10.06 텐서플로우 시작하기

vgg = vgg16.VGG16(include_top=False, weights='imagenet', input_shape=(224, 224, 3))
단일 컬러영상(3채널)을 입력시킬 때는 보통 위와 같이 vgg16아키텍처를 불러오고 이미지넷 웨이트도 복사해온다. 

아래 코드는 3채널이 아닌 영상의 아키텍처를 불러올 때 사용한다. 

vgg = vgg16.VGG16(include_top=False, weights=None, input_shape=(224, 224, 6))

위 코드는 vgg16의 아키텍처의 입력영상의 채널수가 6일 경우이다. 이렇게 하면 에러가 나지 않고 아키텍처가 생성된다. weights=None이라고 입력해주는 게 중요하다. 이 옵션을 넣지 않으면 에러가 발생한다. 대신 weights=None을 설정하면 imagenet에서 학습된 웨이트는 복사되지 않는다. 아래의 레이어 정보를 보면 입력영상의 채널이 6개이다. 0번 레이어만 shape이 (채널수가) 다르고 나머지 레이어는 원래 vgg16과 같은 shape의 레이어들이다.

 

 

 

 
 
 
 
Posted by uniqueone
,

https://stackoverflow.com/questions/51748514/does-imagedatagenerator-add-more-images-to-my-dataset

 

Does ImageDataGenerator add more images to my dataset?

I'm trying to do image classification with the Inception V3 model. Does ImageDataGenerator from Keras create new images which are added onto my dataset? If I have 1000 images, will using this funct...

stackoverflow.com

 

Does ImageDataGenerator add more images to my dataset?

I'm trying to do image classification with the Inception V3 model. Does ImageDataGenerator from Keras create new images which are added onto my dataset? If I have 1000 images, will using this function double it to 2000 images which are used for training? Is there a way to know how many images were created and now fed into the model?

 

Short answer: 1) All the original images are just transformed (i.e. rotation, zooming, etc.) every epoch and then used for training, and 2) [Therefore] the number of images in each epoch is equal to the number of original images you have.

Posted by uniqueone
,

윈도우 10에 텐서플로우 2.x버전에서 gpu로 실행 시

failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED 에러 날 때는 

 

import tensorflow as tf
config = tf.compat.v1.ConfigProto(gpu_options = tf.compat.v1.GPUOptions(per_process_gpu_memory_fraction=0.8)
#device_count = {'GPU': 1}
)
config.gpu_options.allow_growth = True
session = tf.compat.v1.Session(config=config)
tf.compat.v1.keras.backend.set_session(session)

를 코드 상단에 추가해주자.

github.com/tensorflow/tensorflow/issues/35887#issuecomment-679329549

 

 

 

 

 

Posted by uniqueone
,

역시 #TFDevSummitKR 키노트에 소개될 만큼 TensorFlow KR 그룹의 저력을 느낄 수 있었습니다. 이 자리를 빌어 하루만에 조회수가 1천회가 넘고, 1백회 이상 공유가 된 것에 대해 감사드립니다. 아울러 여러분들이 스터디 혹은 연구 하는데 도움이 되었으면 합니다.

어제 1부에 이어서 2부에서는 구글의 책임성 있는(Responsible) AI와 텐서플로우 교육 및 새로운 텐서플로우 개발자 인증, 개발자 커뮤니티 활동, 특히 박해선님과 같은 한국 분들이 키노트에 소개되어 "주모!"를 부르지 않을 수 없었습니다. 그외에도 유투브 플레이리스트에 올라와 있는 테크 세션들에 대해 어떤 내용이 발표 되는지 요약했습니다.

그럼 재택근무(WFH) 하시는 분들이 많으실텐데 맛있는 점심들 하시고 COVID19 예방 잘 하세요!

[#TFDevSummitKR](https://www.facebook.com/hashtag/tfdevsummitkr?source=feed_text&epa=HASHTAG&__xts__%5B0%5D=68.ARBejebBJFqAKlP15BF3BuJaqxNvi36oA2Xcwqbg_Cu5EYlpxCCLqpkjriTI-6oYkCmfpyTKFdneEbOZjtghMgw9w1hMfnQdlTjjI23nSI136Xf4cTA1DrXkAAaJX5UoFFMZJ3QialNjSgCwcwNHA8mAsdPW41vdnmDemqrUmIXvVyWAgCauLIObq0udnMnO-QCbo5qwISJ507HL3qfIxx-3jgFfnxBAE0BUTgULX2HTNaWsxjOijg6qgZ-6TfaF-QzI3aHKerbyHnMtgx2GSLRjUgr1k_cDx3cbgfIjR-2r8BZ8Nt6pHUbAlRUmIo-XTjl2XCE&__tn__=%2ANK-R-R)

[https://brunch.co.kr/@synabreu/54](https://l.facebook.com/l.php?u=https%3A%2F%2Fbrunch.co.kr%2F%40synabreu%2F54%3Ffbclid%3DIwAR3oP16PUIpRQV0s865wiy_NwawINHVcScSC4BxYsxl3n8JXBcHMeP18B84&h=AT2soJ-cH94a3l4MHALpnHX7n4z5C3RkNZqED4xhJ8UwvrkkS6npSXT_AkqOWTHqBrMOVGnlFLclwbUrMIpBjGRyCIZLOxG0gxWjqZMKw_s58uHU-TUHxETVAe-iljhWwZBzbkMiNEY2ge824k8Y3KSsxuhkKOJyGegaeo_WFPqp6lVD2XxxxDgDIvC4CtkvTvcdOFTSjIgwhrMz-yG_9JZftMtJW3JIZA6OxpvvXLU5egEQzrYoQJbricy6qrS66nW2bqYpL6Ne9GAfoQS39QYmmYP6dHe1zsSD9pXY6jJIKw2rQ6dbtm1H8fl4qg1pQc_gaTEbnY9PvRfQzp4a2DSTEOd9PqxGT07UhHi6ceFLPNL_CMuIcQkiZvUKqyvPFO8NhM5jQ5IrPM8OGGMI0Js1nSzfAk5Ux8CEIlkF4iEZm0P5OVk7gMbSNiLkaXa248IQj--EM8UsJCqlNjzx2iaFBXao_a-ed7Y4ulJfr02LwMuFygLgEzRF0JLQ_TlhbstzPlvOR_kNnYhkE4lpLbT2UWei8v06k0-8P1MUwB1h7J9xTUzTbNjJmLCLQlFewI7r25uD5rC6VSvBxYMN68xN7Ftm2hhuIvuEsxdoLoyWZFHcXg)

Posted by uniqueone
,
안녕하십니까?

저는 기계공학(열유체공학)전공자입니다.

기계설계에 있어 데이터 및 인공신경망을 적용하고자 합니다. 텐서플로를 활용하여, DNN을 이용하여 기계의 성능예측 주제로  SCI 논문을 게재한바가 있습니다.

그런데, 제가 인공신경망이 주전공이 아니다보니 원서보다는 국내 번역서를 보고 적용하는 경우가 많습니다. 그런데, 최근 텐서플로2.0이 되면서 기존에 보유하고있던 텐서플로 서적의 코드가 전혀 먹히지가 않았습니다. 따라서, 최근 텐서플로 2.0 국내번역서를 찾아보고 있습니다만, 검색되는 것이 이 도서밖에 없네요...

이 도서가 괜찮은지 여쭤보고싶고, 텐서플로2.0 국내도서로 출간계획이라던지 추천도서가 있으면 추천부탁드립니다.

감사합니다.









https://www.facebook.com/groups/TensorFlowKR/permalink/1051135725227485/?sfnsn=mo
Posted by uniqueone
,

https://www.facebook.com/groups/TensorFlowKR/permalink/997343660606692/

안녕하세요 TF-KR 여러분

이번에는 tflite 및 모바일 딥러닝 관련 질문입니다.

예전에 keras모델(SavedModel)을 tflite 모델로 변환시키는 과정에서 bn(batch normalization)이 전부 빠져서 알아보니 tflite는 bn을 지원하지 않는다는 글을 본적이 있었습니다.

혹시 아직도 tflite는 bn을 지원하지 않는건가요?

그러면 혹시 bn이 포함되어 있는 tensorflow 모델을 안드로이드 혹은 IOS 에서 구동할 수 있는 방법은 없는건가요?

추론시간이 빠르지 않아도 괜찮아서(뭐.. 10초 기다려도 괜찮습니다 ㅠㅠ) 한번 구동하셔 보고 싶어서 자료를 찾는데 보이질 않아 질문합니다.

 

이승현 tflite에서 batchnorm을 지원하지 않는 것은 제가 사용해보지 않아서 정확하지 않지만
convolutional layer와 batch normalization의 parameter를 합쳐서 하나의 layer로 만들 수 있기 때문인 것 같습니다.

 

 

Posted by uniqueone
,
https://m.facebook.com/groups/17450909269?view=permalink&id=10155709404754270

After studying for 3 long days I was finally able to understand and deploy a CNN that could understand 10 signs or hand gestures. The model is very simple and it consists of 2 hidden layers and looks very much like the model used in the Tensorflow's website for the MNIST dataset. I hope you will like my work. All suggestions and criticisms are very welcome. Here is the source code https://github.com/EvilPort2/Sign-Language.

I am facing a problem which I have mentioned in the "Recognizing gesture" section of the README. Plz help me if you can. I really need it.
Posted by uniqueone
,

Quick complete Tensorflow tutorial to understand and run Alexnet, VGG, Inceptionv3, Resnet and squeezeNet networks – CV-Tricks.com
http://cv-tricks.com/tensorflow-tutorial/understanding-alexnet-resnet-squeezenetand-running-on-tensorflow/
Posted by uniqueone
,

https://www.facebook.com/nextobe1/posts/341026106333391

 

LSTM을 이용한 감정 분석 w/ Tensorflow
O'Reilly의 서버에서 미리 빌드된 환경에서 이 코드를 셀 단위로 실행하거나 자신의 컴퓨터에서 이 파일을 실행할 수 있습니다. 또한 사전 에 Pre-Trained LSTM.ipynb로 자신 만의 텍스트를 입력하고 훈련된 네트워크의 출력을 볼 수 있습니다.

깃허브
https://github.com/adeshpande3/LSTM-Sentiment-Analysis

Posted by uniqueone
,
http://adventuresinmachinelearning.com/python-tensorflow-tutorial/

 

 

Google’s TensorFlow has been a hot topic in deep learning recently.  The open source software, designed to allow efficient computation of data flow graphs, is especially suited to deep learning tasks.  It is designed to be executed on single or multiple CPUs and GPUs, making it a good option for complex deep learning tasks.  In it’s most recent incarnation – version 1.0 – it can even be run on certain mobile operating systems.

This introductory tutorial to TensorFlow will give an overview of some of the basic concepts of TensorFlow in Python.  These will be a good stepping stone to building more complex deep learning networks, such as Convolution Neural Networks and Recurrent Neural Networks, in the package.  We’ll be creating a simple three-layer neural network to classify the MNIST dataset.  This tutorial assumes that you are familiar with the basics of neural networks, which you can get up to scratch with in the neural networks tutorial if required.  To install TensorFlow, follow the instructions here. First, let’s have a look at the main ideas of TensorFlow.

1.0 TensorFlow graphs

TensorFlow is based on graph based computation – “what on earth is that?”, you might say.  It’s an alternative way of conceptualising mathematical calculations.  Consider the following expression a=(b+c)(c+2) .  We can break this function down into the following components:

d=b+ce=c+2a=dc

 

Now we can represent these operations graphically as:

TensorFlow tutorial - simple computational graph
Simple computational graph

This may seem like a silly example – but notice a powerful idea in expressing the equation this way: two of the computations (d=b+c and e=c+2 ) can be performed in parallel.  By splitting up these calculations across CPUs or GPUs, this can give us significant gains in computational times.  These gains are a must for big data applications and deep learning – especially for complicated neural network architectures such as Convolutional Neural Networks (CNNs) and Recurrent Neural Networks (RNNs).  The idea behind TensorFlow is to ability to create these computational graphs in code and allow significant performance improvements via parallel operations and other efficiency gains.

We can look at a similar graph in TensorFlow below, which shows the computational graph of a three-layer neural network.

TensorFlow tutorial - data flow graph
TensorFlow data flow graph

The animated data flows between different nodes in the graph are tensors which are multi-dimensional data arrays.  For instance, the input data tensor may be 5000 x 64 x 1, which represents a 64 node input layer with 5000 training samples.  After the input layer there is a hidden layer with rectified linear units as the activation function.  There is a final output layer (called a “logit layer” in the above graph) which uses cross entropy as a cost/loss function.  At each point we see the relevant tensors flowing to the “Gradients” block which finally flow to the Stochastic Gradient Descent optimiser which performs the back-propagation and gradient descent.

Here we can see how computational graphs can be used to represent the calculations in neural networks, and this, of course, is what TensorFlow excels at.  Let’s see how to perform some basic mathematical operations in TensorFlow to get a feel for how it all works.

2.0 A Simple TensorFlow example

Let’s first make TensorFlow perform our little example calculation above – a=(b+c)(c+2) .  First we need to introduce ourselves to TensorFlow variables and constants.  Let’s declare some then I’ll explain the syntax:

import tensorflow as tf

# first, create a TensorFlow constant
const = tf.constant(2.0, name="const")
    
# create TensorFlow variables
b = tf.Variable(2.0, name='b')
c = tf.Variable(1.0, name='c')

As can be observed above, TensorFlow constants can be declared using the tf.constant function, and variables with the tf.Variable function.  The first element in both is the value to be assigned the constant / variable when it is initialised.  The second is an optional name string which can be used to label the constant / variable – this is handy for when you want to do visualisations (as will be discussed briefly later).  TensorFlow will infer the type of the constant / variable from the initialised value, but it can also be set explicitly using the optional dtype argument.  TensorFlow has many of its own types like tf.float32, tf.int32 etc. – see them all here.

It’s important to note that, as the Python code runs through these commands, the variables haven’t actually been declared as they would have been if you just had a standard Python declaration (i.e. b = 2.0).  Instead, all the constants, variables, operations and the computational graph are only created when the initialisation commands are run.

Next, we create the TensorFlow operations:

# now create some operations
d = tf.add(b, c, name='d')
e = tf.add(c, const, name='e')
a = tf.multiply(d, e, name='a')

TensorFlow has a wealth of operations available to perform all sorts of interactions between variables, some of which we’ll get to later in the tutorial.  The operations above are pretty obvious, and they instantiate the operations b+c , c+2.0 and de .

The next step is to setup an object to initialise the variables and the graph structure:

# setup the variable initialisation
init_op = tf.global_variables_initializer()

Ok, so now we are all set to go.  To run the operations between the variables, we need to start a TensorFlow session – tf.Session.  The TensorFlow session is an object where all operations are run.  Using the with Python syntax, we can run the graph with the following code:

# start the session
with tf.Session() as sess:
    # initialise the variables
    sess.run(init_op)
    # compute the output of the graph
    a_out = sess.run(a)
    print("Variable a is {}".format(a_out))

The first command within the with block is the initialisation, which is run with the, well, run command.  Next we want to figure out what the variable a should be.  All we have to do is run the operation which calculates a i.e. a = tf.multiply(d, e, name=’a’).  Note that a is an operation, not a variable and therefore it can be run.  We do just that with the sess.run(a) command and assign the output to a_out, the value of which we then print out.

Note something cool – we defined operations d and e which need to be calculated before we can figure out what a is.  However, we don’t have to explicitly run those operations, as TensorFlow knows what other operations and variables the operation a depends on, and therefore runs the necessary operations on its own.  It does this through its data flow graph which shows it all the required dependencies. Using the TensorBoard functionality, we can see the graph that TensorFlow created in this little program:

TensorFlow tutorial - simple graph
Simple TensorFlow graph

Now that’s obviously a trivial example – what if we had an array of b values that we wanted to calculate the value of a over?

2.1 The TensorFlow placeholder

Let’s also say that we didn’t know what the value of the array b would be during the declaration phase of the TensorFlow problem (i.e. before the with tf.Session() as sess) stage.  In this case, TensorFlow requires us to declare the basic structure of the data by using the tf.placeholder variable declaration.  Let’s use it for b:

# create TensorFlow variables
b = tf.placeholder(tf.float32, [None, 1], name='b')

Because we aren’t providing an initialisation in this declaration, we need to tell TensorFlow what data type each element within the tensor is going to be.  In this case, we want to use tf.float32.  The second argument is the shape of the data that will be “injected” into this variable.  In this case, we want to use a (? x 1) sized array – because we are being cagey about how much data we are supplying to this variable (hence the “?”), the placeholder is willing to accept a None argument in the size declaration.  Now we can inject as much 1-dimensional data that we want into the b variable.

The only other change we need to make to our program is in the sess.run(a,…) command:

a_out = sess.run(a, feed_dict={b: np.arange(0, 10)[:, np.newaxis]})

Note that we have added the feed_dict argument to the sess.run(a,…) command.  Here we remove the mystery and specify exactly what the variable b is to be – a one-dimensional range from 0 to 10.  As suggested by the argument name, feed_dict, the input to be supplied is a Python dictionary, with each key being the name of the placeholder that we are filling.

When we run the program again this time we get:

Variable a is [[  3.]
 [  6.]
 [  9.]
 [ 12.]
 [ 15.]
 [ 18.]
 [ 21.]
 [ 24.]
 [ 27.]
 [ 30.]]

Notice how TensorFlow adapts naturally from a scalar output (i.e. a singular output when a=9.0) to a tensor (i.e. an array/matrix)?  This is based on its understanding of how the data will flow through the graph.

Now we are ready to build a basic MNIST predicting neural network.

3.0 A Neural Network Example

Now we’ll go through an example in TensorFlow of creating a simple three layer neural network.  In future articles, we’ll show how to build more complicated neural network structures such as convolution neural networks and recurrent neural networks.  For this example though, we’ll keep it simple.  If you need to scrub up on your neural network basics, check out my popular tutorial on the subject.  In this example, we’ll be using the MNIST dataset (and its associated loader) that the TensorFlow package provides.  This MNIST dataset is a set of 28×28 pixel grayscale images which represent hand-written digits.  It has 55,000 training rows, 10,000 testing rows and 5,000 validation rows.

We can load the data by running:

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

The one_hot=True argument specifies that instead of the labels associated with each image being the digit itself i.e. “4”, it is a vector with “one hot” node and all the other nodes being zero i.e. [0, 0, 0, 0, 1, 0, 0, 0, 0, 0].  This lets us easily feed it into the output layer of our neural network.

3.1 Setting things up

Next, we can set-up the placeholder variables for the training data (and some training parameters):

# Python optimisation variables
learning_rate = 0.5
epochs = 10
batch_size = 100

# declare the training data placeholders
# input x - for 28 x 28 pixels = 784
x = tf.placeholder(tf.float32, [None, 784])
# now declare the output data placeholder - 10 digits
y = tf.placeholder(tf.float32, [None, 10])

Notice the x input layer is 784 nodes corresponding to the 28 x 28 (=784) pixels, and the y output layer is 10 nodes corresponding to the 10 possible digits.  Again, the size of x is (? x 784), where the ? stands for an as yet unspecified number of samples to be input – this is the function of the placeholder variable.

Now we need to setup the weight and bias variables for the three layer neural network.  There are always L-1 number of weights/bias tensors, where L is the number of layers.  So in this case, we need to setup two tensors for each:

# now declare the weights connecting the input to the hidden layer
W1 = tf.Variable(tf.random_normal([784, 300], stddev=0.03), name='W1')
b1 = tf.Variable(tf.random_normal([300]), name='b1')
# and the weights connecting the hidden layer to the output layer
W2 = tf.Variable(tf.random_normal([300, 10], stddev=0.03), name='W2')
b2 = tf.Variable(tf.random_normal([10]), name='b2')

Ok, so let’s unpack the above code a little.  First, we declare some variables for W1 and b1, the weights and bias for the connections between the input and hidden layer.  This neural network will have 300 nodes in the hidden layer, so the size of the weight tensor W1 is [784, 300].  We initialise the values of the weights using a random normal distribution with a mean of zero and a standard deviation of 0.03.  TensorFlow has a replicated version of the numpy random normal function, which allows you to create a matrix of a given size populated with random samples drawn from a given distribution.  Likewise, we create W2 and b2 variables to connect the hidden layer to the output layer of the neural network.

Next, we have to setup node inputs and activation functions of the hidden layer nodes:

# calculate the output of the hidden layer
hidden_out = tf.add(tf.matmul(x, W1), b1)
hidden_out = tf.nn.relu(hidden_out)

In the first line, we execute the standard matrix multiplication of the weights (W1) by the input vector x and we add the bias b1.  The matrix multiplication is executed using the tf.matmul operation.  Next, we finalise the hidden_out operation by applying a rectified linear unit activation function to the matrix multiplication plus bias.  Note that TensorFlow has a rectified linear unit activation already setup for us, tf.nn.relu.

This is to execute the following equations, as detailed in the neural networks tutorial:

z(l+1)=W(l)x+b(l)h(l+1)=f(z(l+1))

 

Now, let’s setup the output layer, y_:

# now calculate the hidden layer output - in this case, let's use a softmax activated
# output layer
y_ = tf.nn.softmax(tf.add(tf.matmul(hidden_out, W2), b2))

Again we perform the weight multiplication with the output from the hidden layer (hidden_out) and add the bias, b2.  In this case, we are going to use a softmax activation for the output layer – we can use the included TensorFlow softmax function tf.nn.softmax.

We also have to include a cost or loss function for the optimisation / backpropagation to work on. Here we’ll use the cross entropy cost function, represented by:

J=1mi=1mj=1nyj(i)log(yj_(i))+(1yj(i))log(1yj_(i))

 

Where yj(i) is the ith training label for output node j, yj_(i) is the ith predicted label for output node j, m is the number of training / batch samples and n is the number .  There are two operations occurring in the above equation.  The first is the summation of the logarithmic products and additions across all the output nodes.  The second is taking a mean of this summation across all the training samples.  We can implement this cross entropy cost function in TensorFlow with the following code:

y_clipped = tf.clip_by_value(y_, 1e-10, 0.9999999)
cross_entropy = -tf.reduce_mean(tf.reduce_sum(y * tf.log(y_clipped)
                         + (1 - y) * tf.log(1 - y_clipped), axis=1))

Some explanation is required.  The first line is an operation converting the output y_ to a clipped version, limited between 1e-10 to 0.999999.  This is to make sure that we never get a case were we have a log(0) operation occurring during training – this would return NaN and break the training process.  The second line is the cross entropy calculation.

To perform this calculation, first we use TensorFlow’s tf.reduce_sum function – this function basically takes the sum of a given axis of the tensor you supply.  In this case, the tensor that is supplied is the element-wise cross-entropy calculation for a single node and training sample i.e.: yj(i)log(yj_(i))+(1yj(i))log(1yj_(i)) .  Remember that y and y_clipped in the above calculation are (m x 10) tensors – therefore we need to perform the first sum over the second axis.  This is specified using the axis=1 argument, where “1” actually refers to the second axis when we have a zero-based indices system like Python.

After this operation, we have an (m x 1) tensor.  To take the mean of this tensor and complete our cross entropy cost calculation (i.e. execute this part 1mi=1m ), we use TensorFlow’s tf.reduce_mean function.  This function simply takes the mean of whatever tensor you provide it.  So now we have a cost function that we can use in the training process.

Let’s setup the optimiser in TensorFlow:

# add an optimiser
optimiser = tf.train.GradientDescentOptimizer(learning_rate=learning_rate).minimize(cross_entropy)

Here we are just using the gradient descent optimiser provided by TensorFlow.  We initialize it with a learning rate, then specify what we want it to do – i.e. minimise the cross entropy cost operation we created.  This function will then perform the gradient descent (for more details on gradient descent see here and here) and the backpropagation for you.  How easy is that?  TensorFlow has a library of popular neural network training optimisers, see here.

Finally, before we move on to the main show, were we actually run the operations, let’s setup the variable initialisation operation and an operation to measure the accuracy of our predictions:

# finally setup the initialisation operator
init_op = tf.global_variables_initializer()

# define an accuracy assessment operation
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

The correct prediction operation correct_prediction makes use of the TensorFlow tf.equal function which returns True or False depending on whether to arguments supplied to it are equal.  The tf.argmax function is the same as the numpy argmax function, which returns the index of the maximum value in a vector / tensor.  Therefore, the correct_prediction operation returns a tensor of size (m x 1) of True and False values designating whether the neural network has correctly predicted the digit.  We then want to calculate the mean accuracy from this tensor – first we have to cast the type of the correct_prediction operation from a Boolean to a TensorFlow float in order to perform the reduce_mean operation.  Once we’ve done that, we now have an accuracy operation ready to assess the performance of our neural network.

3.2 Setting up the training

We now have everything we need to setup the training process of our neural network.  I’m going to show the full code below, then talk through it:

 # start the session
 with tf.Session() as sess:
    # initialise the variables
    sess.run(init_op)
    total_batch = int(len(mnist.train.labels) / batch_size)
    for epoch in range(epochs):
         avg_cost = 0
         for i in range(total_batch):
             batch_x, batch_y = mnist.train.next_batch(batch_size=batch_size)
              _, c = sess.run([optimiser, cross_entropy], 
                          feed_dict={x: batch_x, y: batch_y})
             avg_cost += c / total_batch
         print("Epoch:", (epoch + 1), "cost =", "{:.3f}".format(avg_cost))
    print(sess.run(accuracy, feed_dict={x: mnist.test.images, y: mnist.test.labels}))

Stepping through the lines above, the first couple relate to setting up the with statement and running the initialisation operation.  The third line relates to our mini-batch training scheme that we are going to run for this neural network.  If you want to know about mini-batch gradient descent, check out this post.  In the third line, we are calculating the number of batches to run through in each training epoch.  After that, we loop through each training epoch and initialise an avg_cost variable to keep track of the average cross entropy cost for each epoch.  The next line is where we extract a randomised batch of samples, batch_x and batch_y, from the MNIST training dataset.  The TensorFlow provided MNIST dataset has a handy utility function, next_batch, that makes it easy to extract batches of data for training.

The following line is where we run two operations.  Notice that sess.run is capable of taking a list of operations to run as its first argument.  In this case, supplying [optimiser, cross_entropy] as the list means that both these operations will be performed.  As such, we get two outputs, which we have assigned to the variables _ and c.  We don’t really care too much about the output from the optimiser operation but we want to know the output from the cross_entropy operation – which we have assigned to the variable c.  Note, we run the optimiser (and cross_entropy) operation on the batch samples.  In the following line, we use c to calculate the average cost for the epoch.

Finally, we print out our progress in the average cost, and after the training is complete, we run the accuracy operation to print out the accuracy of our trained network on the test set.  Running this program produces the following output:

Epoch: 1 cost = 0.586
Epoch: 2 cost = 0.213
Epoch: 3 cost = 0.150
Epoch: 4 cost = 0.113
Epoch: 5 cost = 0.094
Epoch: 6 cost = 0.073
Epoch: 7 cost = 0.058
Epoch: 8 cost = 0.045
Epoch: 9 cost = 0.036
Epoch: 10 cost = 0.027

Training complete!
0.9787

There we go – approximately 98% accuracy on the test set, not bad.  We could do a number of things to improve the model, such as regularisation (see this tips and tricks post), but here we are just interested in exploring TensorFlow.  You can also use TensorBoard visualisation to look at things like the increase in accuracy over the epochs:

TensorFlow tutorial - TensorBoard accuracy plot
TensorBoard plot of the increase in accuracy over 10 epochs

In a future article, I’ll introduce you to TensorBoard visualisation, which is a really nice feature of TensorFlow.  For now, I hope this tutorial was instructive and helps get you going on the TensorFlow journey – in future articles I’ll show you how to build more complex neural networks such as convolution neural networks and recurrent neural networks. So stay tuned.

Have fun!

 

 

Posted by uniqueone
,
Posted by uniqueone
,

TensorFlow: training on my own image - Stack Overflow
http://stackoverflow.com/questions/37340129/tensorflow-training-on-my-own-image
Posted by uniqueone
,

Simple Reinforcement Learning with Tensorflow Part 0: Q-Learning with Tables and Neural Networks
https://medium.com/emergent-future/simple-reinforcement-learning-with-tensorflow-part-0-q-learning-with-tables-and-neural-networks-d195264329d0#.3i736uw1y
Posted by uniqueone
,
입력 값에서 답을 찾아내는 sequence-to-sequence 모델인 "Pointer Networks" https://arxiv.org/abs/1506.03134 를 TensorFlow로 구현했습니다.

https://github.com/devsisters/pointer-network-tensorflow

논문은 랜덤한 점들을 모두 한번씩만 방문하고 출발 도시로 돌아오는 최단 거리를 찾는 Travelling Salesman Problem(TSP)처럼 입력 값에서 정해진 순서로 답을 찾아야 하는 문제를 풀 수 있는 모델을 제안했습니다.

2015년 6월에 arxiv에 올라온 논문이지만 굉장히 유용한 모델 중 하나라 생각되어 구현하게 되었습니다. 이번에는 I/O 시간을 최소화 하기 위해서 멀티스레드로 데이터 큐를 따로 두어 TensorFlow graph의 실행이 I/O에 방해받지 않도록 구현했습니다.

===

그리고 제가 현재 학사 병특 중인 데브시스터즈에서 함께 일할 머신러닝 리서쳐를 찾고 있습니다 :)

저희 회사에서는 강화학습, Computer vision, NLP 등 자신이 풀고자 하는 문제를 자유롭게 정하고 논문 세미나와 코드 구현을 통해서 팀의 역량을 키워나가고 있습니다. 관심이 있으신 분들은 언제든지 연락주세요!

지원 방법 : http://www.devsisters.com/jobs
채용 문의 : career@devsisters.com

저희 팀의 외부 발표자료 및 오픈소스 프로젝트를 공유합니다.

- 딥러닝과 강화 학습으로 나보다 잘하는 쿠키런 AI 구현하기 http://www.slideshare.net/carpedm20/ai-67616630
- 텐서플로우 설치도 했고 튜토리얼도 봤고 기초 예제도 짜봤다면 http://www.slideshare.net/carpedm20/ss-63116251
- 지적 대화를 위한 깊고 넓은 딥러닝 http://www.slideshare.net/carpedm20/pycon-korea-2016
- 강화 학습 기초 http://www.slideshare.net/carpedm20/reinforcement-learning-an-introduction-64037079

- 애플의 Simulated+Unsupervised (S+U) learning 구현 https://github.com/carpedm20/simulated-unsupervised-tensorflow
- Neural Combinatorial Optimization 구현 https://github.com/devsisters/neural-combinatorial-rl-tensorflow
- Deep Q-network 구현 https://github.com/devsisters/DQN-tensorflow
Posted by uniqueone
,
grad-cam.tensorflow

Implementation of Grad CAM in tensorflow

Gradient class activation maps are a visualization technique for deep learning networks.
https://github.com/Ankush96/grad-cam.tensorflow

also:

Grad-CAM implementation in Keras
https://github.com/jacobgil/keras-grad-cam

Grad-CAM: Gradient-weighted Class Activation Mapping
https://github.com/ramprs/grad-cam (torch)
Posted by uniqueone
,
http://bcho.tistory.com/m/1156
Posted by uniqueone
,

https://youtu.be/r7-WPbx8VuY
Posted by uniqueone
,

https://youtu.be/BtDgICVvkHE
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
,

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
,

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

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
,

안녕하세요 ㅎㅎ 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
,
https://tensorflowkorea.gitbooks.io/tensorflow-kr/content/g3doc/get_started/

 

 

 

텐서플로우를 실제로 작동시켜 봅시다!

시작하기 전에 앞으로 무엇을 배울지 힌트를 얻기위해 파이썬 API로 된 텐서플로우 코드를 잠깐 보겠습니다.

이 코드는 2차원 샘플 데이터를 사용하여 분포에 맞는 직선을 찾는(역주: 회귀분석) 간단한 파이썬 프로그램입니다.

 

import tensorflow as tf
import numpy as np

# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3

# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but Tensorflow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# Before starting, initialize the variables.  We will 'run' this first.
init = tf.initialize_all_variables()

# Launch the graph.
sess = tf.Session()
sess.run(init)

# Fit the line.
for step in range(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(W), sess.run(b))

# Learns best fit is W: [0.1], b: [0.3]

코드의 앞 부분은 데이터 플로우 그래프를 만들고 있습니다. 텐서플로우는 세션이 만들어져서 run 함수가 호출되기 전까지 어떤 것도 실제로 실행하지 않습니다.

좀 더 흥미를 돋우기 위해 전형적인 머신러닝 모델이 텐서플로우에서 어떻게 구현되는지 살펴보시면 좋습니다. 뉴럴 네트워크 분야에서 가장 전형적인 문제는 MNIST 손글씨 숫자를 분류하는 것입니다. 우리는 여기서 두가지 버전의 설명 즉 하나는 머신러닝 초보자를 위한 것과 하나는 전문가를 위한 버전을 제공합니다. 만약 다른 소프트웨어 패키지로 MNIST 모델을 여러번 훈련시킨 적이 있다면 붉은 알약을 선택하세요. 만약 MNIST에 대해 들어본 적이 없다면 푸른 알약을 선택하면 됩니다. 초보자와 전문가 사이의 어디라면 푸른색 말고 붉은 알약을 선택하시면 됩니다.

MNIST for machine learning beginners tutorialDeep MNIST for machine learning experts tutorial

Images licensed CC BY-SA 4.0; original by W. Carter

바로 텐서플로우를 설치하고 배우고 싶다면 이 내용은 넘어가고 다음으로 진행해도 됩니다. 텐서플로우 기능을 설명하는 기술적인 튜토리얼에서 MNIST 예제를 또 사용하므로 다시 볼 수 있습니다.

Posted by uniqueone
,