【问题标题】:TypeError: Cannot convert 0.5625 to EagerTensor of dtype int64 on Google ColabTypeError:无法在 Google Colab 上将 0.5625 转换为 dtype int64 的 EagerTensor
【发布时间】:2021-10-25 04:23:34
【问题描述】:

链接:https://colab.research.google.com/drive/1iqhSkMJF0UcNBR3FRCM4nun-OW5kyJN8?usp=sharing

# load and iterate training dataset
train_it = datagen.flow_from_directory(
'/content/drive/MyDrive/train/train', 
target_size=(224, 224), 
color_mode='rgb', 
class_mode="categorical")
# load and iterate validation dataset
valid_it = datagen.flow_from_directory(
'/content/drive/MyDrive/valid', 
target_size=(224, 224), 
color_mode='rgb', 
class_mode="categorical")

输出:

找到属于 6 个类别的 152 张图片。

找到属于 6 个类别的 33 张图片。

model.fit(
train_it,
validation_data=valid_it,
steps_per_epoch=train_it.samples/train_it.batch_size,
validation_steps=valid_it.samples/valid_it.batch_size,
epochs=10)

输出:

纪元 1/10 5/4 [===============================] - ETA:-4s - 损失:2.4248 - 准确度:0.4276

TypeError Traceback(最近一次调用最后一次)

  4     steps_per_epoch=train_it.samples/train_it.batch_size,
  5     validation_steps=valid_it.samples/valid_it.batch_size,
  6     epochs=10)

/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)

104       dtype = dtypes.as_dtype(dtype).as_datatype_enum
105   ctx.ensure_initialized()
106   return ops.EagerTensor(value, ctx.device_name, dtype)
107 
108 

TypeError:无法将 0.5625 转换为 dtype int64 的 EagerTensor

我试图更改验证步骤的值但徒劳无功:(

请帮助 Orz

【问题讨论】:

    标签: python machine-learning google-colaboratory


    【解决方案1】:

    嗯,我解决了

    是pb版

    应将版本更改为 2.2.0(colab 为 2.6.0)

    !pip uninstall tensorflow 
    !pip install tensorflow==2.2.0 
    

    用这个哈哈

    【讨论】:

      【解决方案2】:

      有同样的问题,我的解决方案,因为它不能将 0.53 作为步长 int(round(train_it.samples/train_it.batch_size)),作为步长来获得 int 步长

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-01
        • 2018-06-11
        • 2021-11-09
        • 2020-06-06
        • 1970-01-01
        • 2020-05-20
        • 1970-01-01
        相关资源
        最近更新 更多