TensorFlow(45)
-
remote server 로부터 Tensorboard 사용하는 방법
Tensor flow 같은 딥러닝 프레임워크를 개인 노트북에서 돌리기 어려워서 remote server에 ssh 통신을 통해 작업을 하는 분들이 많을 것이다. 필자도 보통 노트북에 있는 코어나 GPU를 사용하지 않고 remote server에 접속하여 사용한다. Tensor flow를 사용하다 보면 Tensorboard를 많이 사용하는데, 이것이 보통 개인 노트북에서 킬 때는 localhost:6006 이런 식으로 키면 잘 돌아가지만, 원격에서 작업한 것을 개인 노트북에서 킬 때 localhost:6006을 해도 안될 것이다. 그래서 좀 찾아본 몇가지 글에서 답이 있어서 공유하고자 한다. Tensorboard 기본적인 default port는 6006이지만, 저런 원격 서버 같은 경우 여러 명이 공유해서..
2019.12.28 -
[ Tensorflow ] Binary, MutliClass Loss
코딩을 하다 보니 Loss를 사용하는 데 있어서 헷갈리는 부분이 있어서 따로 정리를 하고 싶어 짐! 코드는 주로 사용하는 Tensorflow 1.4 위주로... Tensorflow 2.0 은 추후에... Binary CrossEntropy & Weight Cross Entropy one_hot = (?,1) logits = (?,1) weight = tf.constant( [2.0] ) ## Wegith CrossEntropy WCE = tf.nn.weighted_cross_entropy_with_logits( targets = one_hot , logits = logits , pos_weight = weight) ## CrossEntropy CE = tf.nn.sigmoid_cross_entropy_w..
2019.11.09 -
TensorFlow 유용한 구현 모음 (아직 테스트는 안해봄)
def weight_norm(x, output_dim) : input_dim = int(x.get_shape()[-1]) g = tf.get_variable('g_scalar', shape=[output_dim], dtype=tf.float32, initializer=tf.ones_initializer()) w = tf.get_variable('weight', shape=[input_dim, output_dim], dtype=tf.float32, initializer=he_init) w_init = tf.nn.l2_normalize(w, dim=0) * g # SAME dim=1 return tf.variables_initializer(w_init) weight_init = tf.random_normal..
2019.10.27 -
TensorFlow gpu cuda 설치 공식 문서 (Windows / Ubuntu 16.04 ,18.04)
Ubuntu 16.04 (CUDA 10) # Add NVIDIA package repositories # Add HTTPS support for apt-key sudo apt-get install gnupg-curl wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_10.0.130-1_amd64.deb sudo dpkg -i cuda-repo-ubuntu1604_10.0.130-1_amd64.deb sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x8..
2019.10.03 -
tensorflow에서 Loss 가 nan 발생한 경우 정리 (개인 생각)
여러 가지 경우의 수가 있지만 정리 1. 가중치 초기값을 selu이고, lecun uniform / lecun normal 줬을 때 ====> 더 좋다고 알려진 glorot uniform / glorot normal로 수정함. ---> 실제로 바꾸고 나서 효과를 본 것 같기도 함 2. Loss 부분에 tf.reduce_sum을 했을 때 문제 발생하는 것 같음. ====> 그래서 tf.clip_by_value를 줘서 0 이상으로 주니 에러가 안 생김 3. tf.nn.loss 가 nan 발생하는 경우가 자주 있음 https://data-newbie.tistory.com/270 TensorFlow L2 Normalization 쉽게하기 https://stackoverflow.com/questions/38286..
2019.09.28 -
[ Python ] Tensorflow max norm 적용하기
맥스 노름 규제 주기 각 가중치에 특정 threshold로 제한하는 방식 threshold를 1을 줘서 최대 노름이 1이 되도록 가중치를 clipping 하는 연산 수행 clip_by_value로 줄 수도 있지만, norm으로 주는 것도 좋음. 맥스 노름 규제 같은 경우에는 전체 손실 함수에 규제 손실 항을 추가할 필요 없음 그래도 훈련이 끝나고 clip_weghts를 실행시켜야 하므로 값을 얻어야 함. 그래서 훈련이 끝나고 실행시켜줘야함. def max_norm_regularizer(threshold, axes=1, name="max_norm",collection="max_norm"): def max_norm(weights): clipped = tf.clip_by_norm(weights, clip_no..
2019.09.28 -
[ Python ] TensorFlow Weight L2, L1 Normalization 쉽게하기
https://stackoverflow.com/questions/38286717/tensorflow-regularization-with-l2-loss-how-to-apply-to-all-weights-not-just TensorFlow - regularization with L2 loss, how to apply to all weights, not just last one? I am playing with a ANN which is part of Udacity DeepLearning course. I have an assignment which involves introducing generalization to the network with one hidden ReLU layer using L2 los..
2019.09.24 -
[ Python ] gumbel softmax 알아보기
도움이 되셨다면, 광고 한 번만 눌러주세요. 블로그 관리에 큰 힘이 됩니다 :) 예전에 gumbel softmax 관련 영상을 보고 관련된 자료도 찾아봤자만, 이해가 안 됐고 당시에 코드도 Tensorflow로 많이 없어서 포기했다가, 최근에 다시 봐야 할 것 같아서 여러 코드 구현물을 찾고 내용을 다시 이해해보려고 한다. 일반적으로 DNN을 학습시키는 것은 모델을 구성하고 Loss를 정의한 다음에 gradient에 따라 점진적인 학습을 한다. 그러나 때 때로 이것은 랜덤 구성요소를 규합시키는 아키텍처에서는 쉽지 않다. forwad pass는 더 이상 인풋과 가중치들의 deterministic function이 아니다. 랜덤 구성요소는 샘플링하는 수단으로 stochasticity를 도입한다. 샘플링한 것..
2019.09.14 -
[ Python ] TensorFlow 1.x save & load model & predict
최근에 Flask를 이용해서 모델을 load 하고 예측을 하려고 한다. 예측을 빠르게 하기 위해선 모델을 불러오고 모델의 결괏값만 불러오게 해야 하는데 여기선 모델의 아키텍처와 가중치를 저장을 해서 인풋만 넣어도 예측하게 하는 과정을 해보려고 한다. 일단 모델을 하나 만든다. 여기선 간단하게 binary class를 해본다. 여기서 만들 때 가중 중요하게 생각한 것은 name을 지정해야 합니다! 그래야 나중에 모델만 불러와서 사용할 수 있는 것 같습니다. 만든 후에 각 지정한 이름을 확인하고 싶은 경우 save_file = "./savemodel/.meta" saver = tf.train.import_meta_graph(save_file) saver.restore(sess, tf.train.latest_..
2019.08.17 -
[변수 처리] 011011 같은 값을 multiple label encoding 으로 만들어주기
예를 들어 사과 배 딸기 귤 바나나 1 0 1 1 1 같은 형태가 있을 때 이것을 다음과 같이 쪼개고 싶을 때가 있다. 사과 배 딸기 귤 바나나 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 그럴 때 고민을 하다가 다음과 같이 처리를 해주면 된다! 일단 위치 정보를 찾는다 np.where(train_label.values[0] == 1 )[0] ## array([141, 327, 406, 728]) 지금 141번 327번 406번 728번 쪽에 있다는 것이다. 이걸 하는 방법은 다음과 같이 했다 전체 코드 which = np.where(train_label.values[0] == 1 )[0] mat = np.zeros((4 , 884) ) for idx , row in enume..
2019.07.16 -
tensorflow 논문 구현 코드가 많이 있는 Github 공유
https://github.com/tensorflow/tensor2tensor/blob/master/tensor2tensor/layers/common_layers.py tensorflow/tensor2tensor Library of deep learning models and datasets designed to make deep learning more accessible and accelerate ML research. - tensorflow/tensor2tensor github.com https://towardsdatascience.com/extending-pytorch-with-custom-activation-functions-2d8b065ef2fa Extending PyTorch with Cus..
2019.06.30 -
tf.contrib.learn.DNNRegressor 활용한 모델링하기
이번 편은 Regression 방법으로 하기, 개인적으로 Regression이 훨씬 잘 될 줄 알았는데, 다른 모델과 비교했을 때 그렇게 잘되지는 않았음. boston = datasets.load_boston() X_train, X_test, y_train, y_test = train_test_split( boston.data, boston.target, test_size=0.4, random_state=0) X_train.shape, y_train.shape , X_test.shape, y_test.shape ## ((303, 13), (303,), (203, 13), (203,)) import os import warnings import tensorflow as tf warnings.filterwa..
2019.06.16