python - Invalid argument: Cannot parse tensor from proto: dtype: DT_FLOAT -
i'm attempting run convolutional neural network on data-set of images have. each image numpy array dimensions 300, 300, 1. i'm using date versions of tensorflow , keras. x_train has dimensions 195850, 300, 300, 1. x_test has dimensions 48850, 300, 300, 1. y_train vector of 195850 elements, turned 1 hot vector using to_categorical function.
here code :
from keras.models import sequential keras.layers import lstm, maxpooling2d, convolution2d keras.layers import activation, dropout, flatten, dense keras import applications, backend k keras.utils.np_utils import to_categorical import pickle import numpy np import tensorflow tf k.set_image_dim_ordering('tf') nb_train_samples = 195850 nb_validation_samples = 48850 x_train = pickle.load(open(r'c:\users\...\documents\github\asl_data\x_train.pkl', 'rb')) #x_train = np.moveaxis(np.array(x_train), 0, -1) y_train = pickle.load(open(r'c:\users\...\documents\github\asl_data\y_train.pkl', 'rb')) #y_train = np.moveaxis(np.array(y_train), 0, -1) x_test = pickle.load(open(r'c:\users\...\documents\github\asl_data\x_test.pkl', 'rb')) #x_test = np.moveaxis(np.array(x_test), 0, -1) y_test = pickle.load(open(r'c:\users\\documents\github\asl_data\y_test.pkl', 'rb')) #y_test = np.moveaxis(np.array(y_test), 0, -1) print('x_train shape: ', np.array(x_train).shape) print('y_train shape: ', np.array(y_train).shape) epochs = 50 batch_size = 50 nb_batches = nb_train_samples // batch_size input_shape = (300, 300) print ('before model') model = sequential() model.add(convolution2d(filters=64, kernel_size=(3,3), data_format="channels_last", input_shape=(300, 300, 1,))) model.add(activation('relu')) model.add(convolution2d(64, (3, 3), input_shape=(300, 300, 1))) model.add(activation('relu')) model.add(dropout(0.25)) model.add(convolution2d(128, (3, 3), input_shape=(300, 300, 1))) model.add(activation('relu')) model.add(dropout(0.25)) model.add(flatten()) model.add(dense(256)) model.add(activation('relu')) model.add(dropout(0.5)) model.add(dense(696)) model.add(activation('softmax')) print ('before model compile') model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy']) print ('after model') e in range(0, epochs): in range(0, nb_batches): start= * batch_size end = start + batch_size channel = np.ones(1) x_train = np.array(x_train[start:end][:][:]) x_train = x_train.reshape(batch_size, 300, 300, 1) x_test = np.array(x_test[start:end][:][:]) x_test = x_test.reshape(batch_size, 300, 300, 1) y_train = np.array(y_train[start:end][:]) y_test = np.array(y_test[start:end][:]) print('y_train shape: ', np.array(y_train).shape) y_train = to_categorical(y_train, num_classes=696) y_test = to_categorical(y_test, num_classes=696) print('y_train shape: ', np.array(y_train).shape) model.train_on_batch(x_train, y_train) model.test_on_batch(x_test, y_test)
as can see, using train_on_batch function, although don't think should origin of errors, :
traceback (most recent call last): file "c:\users\...\documents\github\asl_data\train2.py", line 86, in <module> model.train_on_batch(x_train, y_train) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\models.py", line 955, in train_on_batch class_weight=class_weight) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\engine\training.py", line 1762, in train_on_batch outputs = self.train_function(ins) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 2270, in __call__ session = get_session() file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 167, in get_session _initialize_variables() file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 341, in _initialize_variables sess.run(tf.variables_initializer(uninitialized_variables)) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\tensorflow\python\client\session.py", line 895, in run run_metadata_ptr) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\tensorflow\python\client\session.py", line 1124, in _run feed_dict_tensor, options, run_metadata) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\tensorflow\python\client\session.py", line 1321, in _do_run options, run_metadata) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\tensorflow\python\client\session.py", line 1340, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.invalidargumenterror: cannot parse tensor proto: dtype: dt_float tensor_shape { dim { size: 11063808 } dim { size: 256 } } float_val: 0 [[node: training/rmsprop/const_6 = const[dtype=dt_float, value=tensor<type: float shape: [11063808,256] values: [0 0 0]...>, _device="/job:localhost/replica:0/task:0/gpu:0"]()]] caused op 'training/rmsprop/const_6', defined at: file "c:\users\...\documents\github\asl_data\train2.py", line 86, in <module> model.train_on_batch(x_train, y_train) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\models.py", line 955, in train_on_batch class_weight=class_weight) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\engine\training.py", line 1761, in train_on_batch self._make_train_function() file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\engine\training.py", line 960, in _make_train_function loss=self.total_loss) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\legacy\interfaces.py", line 87, in wrapper return func(*args, **kwargs) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\optimizers.py", line 226, in get_updates accumulators = [k.zeros(k.int_shape(p), dtype=k.dtype(p)) p in params] file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\optimizers.py", line 226, in <listcomp> accumulators = [k.zeros(k.int_shape(p), dtype=k.dtype(p)) p in params] file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 625, in zeros return variable(tf.constant_initializer(0., dtype=tf_dtype)(shape), file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\tensorflow\python\ops\init_ops.py", line 203, in __call__ verify_shape=verify_shape) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\tensorflow\python\framework\constant_op.py", line 106, in constant attrs={"value": tensor_value, "dtype": dtype_value}, name=name).outputs[0] file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2630, in create_op original_op=self._default_original_op, op_def=op_def) file "c:\users\...\appdata\local\programs\python\python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1204, in __init__ self._traceback = self._graph._extract_stack() # pylint: disable=protected-access invalidargumenterror (see above traceback): cannot parse tensor proto: dtype: dt_float tensor_shape { dim { size: 11063808 } dim { size: 256 } } float_val: 0 [[node: training/rmsprop/const_6 = const[dtype=dt_float, value=tensor<type: float shape: [11063808,256] values: [0 0 0]...>, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
i'm stuck here appreciated,
thanks
Comments
Post a Comment