>source

나는 깊은 학습을 배우고 모델에 맞게 싶을 때, 나는 Tensorflow, Keras & 파이썬 모델을 빌드합니다 문제는 TensorFlow로 가져오고 데이터를 호출하고 필요한 변수에 저장하고 변수 중 하나를 테스트 한 다음 모델을 만드는 데 필요한 경우 발생했습니다.

이와 같이 오류가 발생합니다

내 code

import tensorflow as tf
mnist= tf.keras.datasets.mnist
(x_train,y_train),(x_test,y_test)= mnist.load_data()
x_train[2]
x_train,x_test= x_train/255.0,x_test/255
model= tf.keras.Sequential([
    tf.keras.layers.Flatten(input_shape=(28,28)),
    tf.keras.layers.Dense(512, activation= tf.nn.relu),
    tf.keras.layers.Dropout(0,2),
    tf.keras.layers.Dense(10, activation= tf.nn.softmax)
])
model.compile(optimizer= 'adam',loss= 'sparse_categorical_crossentropy' ,metrics= ['accuracy'])
model.fit(x= x_train, y= y_train, epochs= 5 )

이것은 오류입니다 : -

>     Reloaded modules: tmpwxhtmgyc
>     Epoch 1/5
>     Traceback (most recent call last):
>>       File "D:\pythonproject\mlcode\ex1\untitled2.py", line 21, in <module>>         model.fit(x= x_train, y= y_train, epochs= 5 )
>>       File "C:\Users\-\anaconda3\lib\site-packages\keras\engine\training.py", line 1184,
> in fit
>         tmp_logs= self.train_function(iterator)
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py",
> line 885, in __call__
>         result= self._call(*args, **kwds)
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py",
> line 933, in _call
>         self._initialize(args, kwds, add_initializers_to=initializers)
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py",
> line 759, in _initialize
>         self._stateful_fn._get_concrete_function_internal_garbage_collected(
> # pylint: disable=protected-access
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\eager\function.py",
> line 3066, in _get_concrete_function_internal_garbage_collected
>         graph_function, _= self._maybe_define_function(args, kwargs)
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\eager\function.py",
> line 3463, in _maybe_define_function
>         graph_function= self._create_graph_function(args, kwargs)
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\eager\function.py",
> line 3298, in _create_graph_function
>         func_graph_module.func_graph_from_py_func(
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\framework\func_graph.py",
> line 1007, in func_graph_from_py_func
>         func_outputs= python_func(*func_args, **func_kwargs)
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py",
> line 668, in wrapped_fn
>         out= weak_wrapped_fn().__wrapped__(*args, **kwds)
>>       File "C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\framework\func_graph.py",
> line 994, in wrapper
>         raise e.ag_error_metadata.to_exception(e)
>>     TypeError: in user code:
>>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\training.py:853
> train_function  *
>             return step_function(self, iterator)
>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\training.py:842
> step_function  **
>             outputs= model.distribute_strategy.run(run_step, args=(data,))
>         C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:1286
> run
>             return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
>         C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2849
> call_for_each_replica
>             return self._call_for_each_replica(fn, args, kwargs)
>         C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:3632
> _call_for_each_replica
>             return fn(*args, **kwargs)
>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\training.py:835 run_step
> **
>             outputs= model.train_step(data)
>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\training.py:787
> train_step
>             y_pred= self(x, training=True)
>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\base_layer.py:1037
> __call__
>             outputs= call_fn(inputs, *args, **kwargs)
>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\sequential.py:369 call
>             return super(Sequential, self).call(inputs, training=training, mask=mask)
>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\functional.py:414 call
>             return self._run_internal_graph(
>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\functional.py:550
> _run_internal_graph
>             outputs= node.layer(*args, **kwargs)
>         C:\Users\-\anaconda3\lib\site-packages\keras\engine\base_layer.py:1037
> __call__
>             outputs= call_fn(inputs, *args, **kwargs)
>         C:\Users\-\anaconda3\lib\site-packages\keras\layers\core.py:212 call
>             output= control_flow_util.smart_cond(training, dropped_inputs,
>         C:\Users\-\anaconda3\lib\site-packages\keras\utils\control_flow_util.py:105
> smart_cond
>             return tf.__internal__.smart_cond.smart_cond(
>         C:\Users\-\anaconda3\lib\site-packages\tensorflow\python\framework\smart_cond.py:56
> smart_cond
>             return true_fn()
>         C:\Users\-\anaconda3\lib\site-packages\keras\layers\core.py:208
> dropped_inputs
>             noise_shape=self._get_noise_shape(inputs),
>         C:\Users\-\anaconda3\lib\site-packages\keras\layers\core.py:197
> _get_noise_shape
>             for i, value in enumerate(self.noise_shape):
>>         TypeError: 'int' object is not iterable

@neatconda.

Ahmed M Eid2021-08-15 13:00:15

당신은 당신의 드롭 아웃에 오타가 있습니다. 0.2가 아니라 0.2가 아닙니다

neatconda2021-08-15 12:51:55
  • 이전 html : 텍스트 장식 : 밑줄은 문서화 된 회선 두께 속성이 있습니다.
  • 다음 node.js : 컬렉션의 배열 요소와 값 중 하나가 일치하는 경우 레code 찾기