Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- با سلام...من برنامه زیر رو در تنسور فلو نوشتم:
- import tensorflow as tf
- import numpy as np
- import matplotlib.pyplot as plt
- try:
- from scipy import misc
- except ImportError:
- !pip install scipy
- from scipy import misc
- training_size = 9
- img_size = 20*20*3
- training_data = np.empty(shape=(training_size, img_size))
- import glob
- i = 0
- for filename in glob.glob('D:/Minutia/*.jpg'):
- image = misc.imread(filename)
- training_data[i] = image.reshape(-1)
- i+=1
- print(training_data[0].shape)
- a = [0, 0, 0,1,1,1,2,2,2]
- b = tf.one_hot(a,3)
- sess = tf.Session()
- sess.run(b)
- from __future__ import division, print_function, absolute_import
- import tflearn
- from tflearn.layers.core import input_data, dropout, fully_connected
- from tflearn.layers.conv import conv_2d, max_pool_2d
- from tflearn.layers.normalization import local_response_normalization
- from tflearn.layers.estimator import regression
- network = input_data(shape=[None, 227, 227, 3])
- network = conv_2d(network, 96, 11, strides=4, activation='relu')
- network = max_pool_2d(network, 3, strides=2)
- network = local_response_normalization(network)
- network = conv_2d(network, 256, 5, activation='relu')
- network = max_pool_2d(network, 3, strides=2)
- network = local_response_normalization(network)
- network = conv_2d(network, 384, 3, activation='relu')
- network = conv_2d(network, 384, 3, activation='relu')
- network = conv_2d(network, 256, 3, activation='relu')
- network = max_pool_2d(network, 3, strides=2)
- network = local_response_normalization(network)
- network = fully_connected(network, 4096, activation='tanh')
- network = dropout(network, 0.5)
- network = fully_connected(network, 4096, activation='tanh')
- network = dropout(network, 0.5)
- network = fully_connected(network, 17, activation='softmax')
- network = regression(network, optimizer='momentum',
- loss='categorical_crossentropy',
- learning_rate=0.001)
- model = tflearn.DNN(network, checkpoint_path='model_alexnet',
- max_checkpoints=1, tensorboard_verbose=2)
- model.fit(training_data, b, n_epoch=1000, validation_set=0.1, shuffle=True,
- show_metric=True, batch_size=64, snapshot_step=200,
- snapshot_epoch=False, run_id='alexnet_oxflowers17')
- که هنگام اجرای
- model.fit(training_data, b, n_epoch=1000, validation_set=0.1, shuffle=True,
- show_metric=True, batch_size=64, snapshot_step=200,
- snapshot_epoch=False, run_id='alexnet_oxflowers17')
- با خطای زیر مواجه شدم:
- Exception in thread Thread-8:
- Traceback (most recent call last):
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 670, in _call_cpp_shape_fn_impl
- status)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\contextlib.py", line 66, in __exit__
- next(self.gen)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 469, in raise_exception_on_not_ok_status
- pywrap_tensorflow.TF_GetCode(status))
- tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 1 but is rank 2 for 'strided_slice' (op: 'StridedSlice') with input shapes: [9,3], [1,8], [1,8], [1].
- During handling of the above exception, another exception occurred:
- Traceback (most recent call last):
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\threading.py", line 914, in _bootstrap_inner
- self.run()
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\threading.py", line 862, in run
- self._target(*self._args, **self._kwargs)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tflearn\data_flow.py", line 187, in fill_feed_dict_queue
- data = self.retrieve_data(batch_ids)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tflearn\data_flow.py", line 222, in retrieve_data
- utils.slice_array(self.feed_dict[key], batch_ids)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tflearn\utils.py", line 187, in slice_array
- return X[start]
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\array_ops.py", line 513, in _SliceHelper
- name=name)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\array_ops.py", line 671, in strided_slice
- shrink_axis_mask=shrink_axis_mask)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 3688, in strided_slice
- shrink_axis_mask=shrink_axis_mask, name=name)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 763, in apply_op
- op_def=op_def)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 2397, in create_op
- set_shapes_for_outputs(ret)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1757, in set_shapes_for_outputs
- shapes = shape_func(op)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1707, in call_with_requiring
- return call_cpp_shape_fn(op, require_shape_fn=True)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 610, in call_cpp_shape_fn
- debug_python_shape_fn, require_shape_fn)
- File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 675, in _call_cpp_shape_fn_impl
- raise ValueError(err.message)
- ValueError: Shape must be rank 1 but is rank 2 for 'strided_slice' (op: 'StridedSlice') with input shapes: [9,3], [1,8], [1,8], [1].
Add Comment
Please, Sign In to add comment