dnry / dlopt Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
안녕하세요.
연속해서 문의드립니다.
Chp15의 텐서보드 공부중입니다.
404페이지 실행하여 정상적으로 웹주소를 받았는데
405페이지와 같은 텐서보드 그림은 안 뜨고 연결될 수 없음만 나옵니다.
관련하여 확인 부탁드립니다.
참고로 제 환경은 다음과 같습니다
안녕하세요.
딥러닝을 위한 최적화와 수치해석 독자입니다.
시작하여 열심히 하다 보니 텐서프로부분이 처음 실행 안되어 구글링하니
아마 책이 tf 1.0 버전이고 저는 2.0으로 설치한거 같습니다.
2.0 버전으로 실행하고 싶으면 어떻게 해야 하는지와 책을 어떻게 이용할지 문의드립니다.
예를 들면 session / run 만해도 실행이 안됩니다. ㅠ
안녕하세요? 딥러닝을 위한 최적화 수치해석책을 최근에 구입해
공부중인 학생입니다.
거두절미하고 본론을 말씀드리면,
6장에 visualize 모듈을 사용하려고 하니, 모듈이 없다고 나옵니다.
conda prompt에서 install 명령을 수행하니,
해당 패키지는 아나콘다 홈페이지에서 검색하고, 설치가 불가하며,
아나콘다 홈페이지에 visualize를 검색해보니,
패키지가 여러개 있어서 어떤걸 설치해야 할지 모르겠습니다.
1장 개발환경 설정에 visualize는 없는거 같은데요,
해당모듈이 어떤 패키지를 통해 설치할 수 있는지 답변 부탁드립니다.
책을 계속 쭉 보고 있다보니 질문이 너무 잦아서 죄송하네요...
끊기면 진도 나가기가 어려워 자주 문의드리는 점 우선 양해 부탁드립니다.
다음과 같이 459~460 페이지의 전체 코드를 입력하였는데
에러가 발생하였습니다.
확인을 계속해 보았는데 어느 부분이 문제인지 못 찾겠습니다..
확인 및 조언 부탁드립니다.
(혼자 계속 꼼꼼히 보려고 해도 오탈자는 없어보이는데 찾는게 쉽지 않습니다...)
<입력 코드>
# 전체 코드
#1. 라이브러리 불러오기
import numpy as np
import matplotlib.pylab as plt
#2. MNIST 데이터 불러오기
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
#3. Train, Test 데이터 불러오기
x_train, y_train = mnist.train.images, mnist.train.labels
x_test, y_test = mnist.test.images, mnist.test.labels
#4. 불러온 MNIST 데이터 그림 보기
plt.figure(figsize=(16,8))
for k in range(32):
img = mnist.train.images[k].reshape(28,28)
label = np.argmax(mnist.train.labels[k])
plt.subplot(4,8,1+k)
plt.imshow(img, cmap='gray')
plt.axis('off')
plt.title(label)
plt.show()
#5. 불러온 MNIST 데이터 범위 보기
print("Min : {0}, Max : {1}".format(mnist.train.images[0].min(), mnist.train.images[0].max()))
#6. tensorflow 불러오기
import tensorflow as tf
#7. CNN 모델 구성하기
x = tf.placeholder(tf.float32, [None, 784])
x_img = tf.reshape(x, shape = [1,28,28,1])
conv1 = tf.layers.conv2d(x_img, 32, 3, activation=tf.nn.relu)
conv1 = tf.layers.max_pooling2d(conv1, 2, 2)
conv2 = tf.layers.conv2d(conv1, 64, 3, activation=tf.nn.relu)
conv2 = tf.layers.max_pooling2d(conv2, 2, 2)
conv2 = tf.layers.dropout(conv2, 0.25)
fc1 = tf.contrib.layers.flatten(conv2)
fc1 = tf.layers.dense(fc1, 128, activation=tf.nn.relu)
conv2 = tf.layers.dropout(fc1, 0.5)
y = tf.placeholder(tf.float32, [None, 10])
model = tf.nn.softmax(tf.layers.dense(fc1, 10))
#8. 최적화 문제 세팅하기
loss = tf.reduce_mean(tf.reduce_sum(-y*tf.log(model),1))
train = tf.train.AdamOptimizer().minimize(loss)
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(model,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
#9. Hyper-Parameter 세팅하기
batch_size = 64
MaxEpochs = 4
#10. 학습시작
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
for epoch in range(MaxEpochs):
loss_val = 0.0
for step in range(len(mnist.train.images) // batch_size +1):
x_batch, y_batch = mnist.train.next_batch(batch_size)
batch_loss, _ = sess.run([loss, train], feed_dict={x:x_batch, y:y_batch})
loss_val += batch_loss * len(x_batch)
test_loss, test_acc = sess.run([loss, accuracy], feed_dict={x:mnist.test.images, y:mnist.test.labels})
loss_val /= len(mnist.train.images)
print('Epoch {0} : loss = {1:4.2E}, test_loss = {2:4.2E}, test_acc = {3:4.4f}'.format(epoch, loss_val, test_loss, test_acc))
# 11. Test 데이터에서 정확도 체크하기
acc = sess.run(accuracy, feed_dict=test_feed_dict)
print(acc)
<에러 메시지>
WARNING:tensorflow:From <ipython-input-1-592fe92813d1>:9: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
WARNING:tensorflow:From /Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Please write your own downloading logic.
WARNING:tensorflow:From /Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting MNIST_data/train-images-idx3-ubyte.gz
WARNING:tensorflow:From /Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting MNIST_data/train-labels-idx1-ubyte.gz
WARNING:tensorflow:From /Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:110: dense_to_one_hot (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.one_hot on tensors.
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
WARNING:tensorflow:From /Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
<Figure size 1600x800 with 32 Axes>
Min : 0.0, Max : 0.9960784912109375
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
~/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1277 try:
-> 1278 return fn(*args)
1279 except errors.OpError as e:
~/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
1262 return self._call_tf_sessionrun(
-> 1263 options, feed_dict, fetch_list, target_list, run_metadata)
1264
~/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
1349 self._session, options, feed_dict, fetch_list, target_list,
-> 1350 run_metadata)
1351
InvalidArgumentError: Input to reshape is a tensor with 50176 values, but the requested shape has 784
[[Node: Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_Placeholder_0_0, Reshape/shape)]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-1-592fe92813d1> in <module>()
68 for step in range(len(mnist.train.images) // batch_size +1):
69 x_batch, y_batch = mnist.train.next_batch(batch_size)
---> 70 batch_loss, _ = sess.run([loss, train], feed_dict={x:x_batch, y:y_batch})
71 loss_val += batch_loss * len(x_batch)
72 test_loss, test_acc = sess.run([loss, accuracy], feed_dict={x:mnist.test.images, y:mnist.test.labels})
~/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
875 try:
876 result = self._run(None, fetches, feed_dict, options_ptr,
--> 877 run_metadata_ptr)
878 if run_metadata:
879 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
~/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1098 if final_fetches or final_targets or (handle and feed_dict_tensor):
1099 results = self._do_run(handle, final_targets, final_fetches,
-> 1100 feed_dict_tensor, options, run_metadata)
1101 else:
1102 results = []
~/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1270 if handle is None:
1271 return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1272 run_metadata)
1273 else:
1274 return self._do_call(_prun_fn, handle, feeds, fetches)
~/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1289 except KeyError:
1290 pass
-> 1291 raise type(e)(node_def, op, message)
1292
1293 def _extend_graph(self):
InvalidArgumentError: Input to reshape is a tensor with 50176 values, but the requested shape has 784
[[Node: Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_Placeholder_0_0, Reshape/shape)]]
Caused by op 'Reshape', defined at:
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/ipykernel/kernelapp.py", line 499, in start
self.io_loop.start()
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tornado/platform/asyncio.py", line 132, in start
self.asyncio_loop.run_forever()
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/asyncio/base_events.py", line 421, in run_forever
self._run_once()
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/asyncio/base_events.py", line 1425, in _run_once
handle._run()
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/asyncio/events.py", line 127, in _run
self._callback(*self._args)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tornado/platform/asyncio.py", line 122, in _handle_events
handler_func(fileobj, events)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tornado/stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tornado/stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 233, in dispatch_shell
handler(stream, idents, msg)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/ipykernel/ipkernel.py", line 208, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/ipykernel/zmqshell.py", line 537, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2662, in run_cell
raw_cell, store_history, silent, shell_futures)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2785, in _run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2901, in run_ast_nodes
if self.run_code(code, result):
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-592fe92813d1>", line 35, in <module>
x_img = tf.reshape(x, shape = [1,28,28,1])
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 6199, in reshape
"Reshape", tensor=tensor, shape=shape, name=name)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
return func(*args, **kwargs)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 3155, in create_op
op_def=op_def)
File "/Users/jeongbiyong/anaconda3/envs/mnist-classification/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1717, in __init__
self._traceback = tf_stack.extract_stack()
InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 50176 values, but the requested shape has 784
[[Node: Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_Placeholder_0_0, Reshape/shape)]]
안녕하십니까.
오류 글 등록하고 기다리는 동안에 나머지 먼저 진행하여 다행히(?) 에러 없이 잘 마쳤습니다.
책 한권에 있는 내용 다 실행해보았습니다만 아직도 100% 이해 및 응용이 안 되는거 같아
작가님들께 죄송한 생각만 듭니다.
그래도 본 도서를 공부하면서 실습적인 부분과 이론적인 부분이 매치되는 것을
일부 확인하여 이해도가 높아진 부분도 있어 감사하게 생각하고 있습니다.
이제는 여기서 배운 내용 기반으로
텐서플로 2.x으로도 학습하여 더 실용적으로 사용할 수 있도록 하려합니다.
마지막으로 감사의 인사 드리려 이슈는 아니지만 이곳에 글을 남깁니다.
초보적인 실수로 많은 질문드려 번거롭게 해드린점 양해 부탁드리고
날이 많이 더운데 건강 유의하시며 하시는 일 잘 되시길 바라겠습니다.
감사합니다.
186페이지의 MSE 식은 N분의1, 187페이지 손실함수 코드는 N분의 0.5인데 0.5는 왜 곱해져있는건가요? 인터넷에 MSE 를 찾아보면 N대신 데이터의 자유도로 나눈다.. 또 다른 자료에서는 그냥 1/2로 되어있는데 이론적 배경을 몰라 어떤것이 맞는지 혼동됩니다.. 조언 부탁드리겠습니다.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.