[英]Keras on Apple M1
I am running following command on my Apple M1 system.我在我的 Apple M1 系统上运行以下命令。
----------Code Start---------------------- ----------代码开始----------
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense, Activation, BatchNormalization
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_CHANNELS)))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(BatchNormalization())
model.add(Dropout(0.5))
model.add(Dense(2, activation='softmax')) # 2 because we have cat and dog classes
model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
model.summary()
FAST_RUN = True
epochs=3 if FAST_RUN else 50
history = model.fit_generator(
train_generator,
epochs=epochs,
validation_data=validation_generator,
validation_steps=size_test//batch_size,
steps_per_epoch=size_train//batch_size,
callbacks=callbacks
)
---------------Code End------------------ ---------------代码结束------
It is giving me the following error which i am not able to figure out.它给了我以下我无法弄清楚的错误。
---------------Error Start--------------------- ---------------错误开始---------
1157 callbacks.on_train_batch_begin(step)
-> 1158 tmp_logs = self.train_function(iterator)
1159 if data_handler.should_sync:
1160 context.async_wait()
~/miniforge3/envs/tensorflow/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
887
888 with OptionalXlaContext(self._jit_compile):
--> 889 result = self._call(*args, **kwds)
890
891 new_tracing_count = self.experimental_get_tracing_count()
~/miniforge3/envs/tensorflow/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
915 # In this case we have created variables on the first call, so we run the
916 # defunned version which is guaranteed to never create variables.
--> 917 return self._stateless_fn(*args, **kwds) # pylint: disable=not-callable
918 elif self._stateful_fn is not None:
919 # Release the lock early so that multiple threads can perform the call
TypeError: 'NoneType' object is not callable
--------------Error End----------------- --------------错误结束------
What should I do to resolve this?我应该怎么做才能解决这个问题?
You need to do some changes in both these lines below as you said it is category 2 binary_class model
(0,1).您需要在下面的这两行中进行一些更改,因为您说它是类别 2
binary_class model
(0,1)。
model.add(Dense(1, activation='sigmoid')) # 2 because we have cat and dog classes
model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
Also try changing these below codes because steps_per_epoch
and validation_steps
are not counting correctly.还可以尝试更改以下代码,因为
steps_per_epoch
和validation_steps
计数不正确。 You can check this link for more information in this.您可以查看此链接以获取更多信息。
history = model.fit(
train_generator,
epochs=epochs,
validation_data=validation_generator)
#validation_steps=size_test//batch_size,
#steps_per_epoch=size_train//batch_size)
Let us know if issue still persists.让我们知道问题是否仍然存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.