gpt4 book ai didi

python - 类型错误 : "NoneType" object is not callable in Google Colab

转载 作者:行者123 更新时间:2023-12-04 01:14:16 25 4
gpt4 key购买 nike

在定义为允许访问建筑操作的导入包和模型下方,

import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import cv2
import os
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing import image
from tensorflow.keras.optimizers import RMSpro
现在这里是创建模型的编码,我认为描述模型太重要了,

Rescale the images shapes,

train = ImageDataGenerator(rescale=1/255)
validation = ImageDataGenerator(rescale=1/255)

Fixed the dataset directory and access the data,

train_dataset = train.flow_from_directory(
'cnn_happy_NotHapp/Basedata/training/',
target_size=(200,200),
batch_size = 3,
class_mode = 'binary')
validation_dataset = validation.flow_from_directory(
'cnn_happy_NotHapp/Basedata/validation/',
target_size=(200,200),
batch_size = 3,
class_mode = 'binary')

Create the CNN model

model = tf.keras.models.Sequential([tf.keras.layers.Conv2D(16,(3,3), activation='relu', input_shape=(200, 200, 3)),
tf.keras.layers.MaxPool2D(2,2),
##################################
tf.keras.layers.Conv2D(132,(3,3), activation='relu'),
tf.keras.layers.MaxPool2D(2,2),
##################################
tf.keras.layers.Conv2D(64,(3,3), activation='relu'),
tf.keras.layers.MaxPool2D(2,2),
##################################
tf.keras.layers.Flatten(),
###################################
tf.keras.layers.Dense(512, activation='relu'),
###################################
tf.keras.layers.Dense(1, activation='sigmoid'),
])

Compile the model

model.compile(loss = 'binary_crossentropy',
optimizer = RMSprop(lr=0.001),
metrics = ['accuracy '])

Fit the model and please noticed here because i faced problem here,

model_fit = model.fit(train_dataset,
steps_per_epoch=3,
epochs= 10,
validation_data = validation_dataset) #error is here

Below the error section, I request all of stactoverflow members forcarefully read and help me for solving this error,

Epoch 1/10
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-85ae786a1bf1> in <module>()
2 steps_per_epoch=3,
3 epochs= 10,
----> 4 validation_data = validation_dataset)

3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
805 # In this case we have created variables on the first call, so we run the
806 # defunned version which is guaranteed to never create variables.
--> 807 return self._stateless_fn(*args, **kwds) # pylint: disable=not-callable
808 elif self._stateful_fn is not None:
809 # Release the lock early so that multiple threads can perform the call

TypeError: 'NoneType' object is not callable
注:我正遭受此错误的困扰,我无法解决它,并感谢尝试解决它并在此处发表评论以分享答案的人

最佳答案

@AlirezaMoradi 请关注这里,
我在下面犯了一个错误,

In compile section of the model,

model.compile(loss = 'binary_crossentropy',
optimizer = RMSprop(lr=0.001),
metrics = ['accuracy ']) #'accuracy ' it will be 'accuracy'
这意味着,对于我的错误,我添加 空白 和删除后它解决了。
我很忙,这就是为什么分享解决方案迟到了,我很抱歉迟到了。

关于python - 类型错误 : "NoneType" object is not callable in Google Colab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63850359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com