简体   繁体   English

如何解决 TypeError: 'int' 和 'str' 实例之间不支持的 '<'?

[英]How do I resolve TypeError: '<' not supported between instances of 'int' and 'str'?

I am trying to use the following code to train Keras-I3D model from the following link:我正在尝试使用以下代码从以下链接训练 Keras-I3D 模型:

https://github.com/srijandas07/i3d . https://github.com/srijandas07/i3d I have slightly modified the code, but I can get it work.我稍微修改了代码,但我可以让它工作。

imported modules are导入的模块是

import os
os.environ['KERAS_BACKEND'] = 'tensorflow'

os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"   
os.environ["CUDA_VISIBLE_DEVICES"]="3" 

from keras.layers import Dense, Flatten, Dropout, Reshape
from keras import regularizers
from keras.preprocessing import image
from keras.models import Model, load_model
from keras.applications.vgg16 import preprocess_input
from keras.utils import to_categorical
from keras.optimizers import SGD
from i3d_inception import Inception_Inflated3d, conv3d_bn
from keras.callbacks import ReduceLROnPlateau, ModelCheckpoint, CSVLogger, Callback
from keras.utils import Sequence, multi_gpu_model

import random
import sys
from multiprocessing import cpu_count
import numpy as np
import glob
from skimage.io import imread
import cv2

some definitions一些定义

epochs = sys.argv[0]
#epochs = 17
model_name = sys.argv[0]
#model_name = model_name
version = sys.argv[0]
num_classes = 35
batch_size = 16
stack_size = 64
DataLoader_video_train = DataLoader_video_train
DataLoader_video_test = DataLoader_video_test
class CustomModelCheckpoint(Callback):

    def __init__(self, model_parallel, path):

        super(CustomModelCheckpoint, self).__init__()

        self.save_model = model_parallel
        self.path = path
        self.nb_epoch = 0

    def on_epoch_end(self, epoch, logs=None):
        self.nb_epoch += 1
        self.save_model.save(self.path + str(self.nb_epoch) + '.hdf5')


i3d = i3d_modified(weights = 'rgb_imagenet_and_kinetics')
model = i3d.i3d_flattened(num_classes = num_classes)
optim = SGD(lr = 0.01, momentum = 0.9)

reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor = 0.1, patience = 10)
csvlogger = CSVLogger('i3d_'+model_name+'.csv')

model.compile(loss = 'categorical_crossentropy', optimizer = optim, metrics = ['accuracy'])

model_checkpoint = CustomModelCheckpoint(model, './weights_'+model_name+'/epoch_')    

train_generator = DataLoader_video_train('/train_CS.txt',version, batch_size = batch_size)
test_generator = DataLoader_video_test('/test_CS.txt', version, batch_size = batch_size)

fit generator拟合生成器

model.fit_generator(
    generator = train_generator,
    #validation_data=val_generator,
    epochs = epochs, 
    steps_per_epoch = 17, 
    callbacks = [csvlogger, reduce_lr, model_checkpoint], 
    max_queue_size = 48,
    workers = cpu_count() - 2,
    use_multiprocessing = True,
)

print(model.evaluate_generator(generator = test_generator))

I get the following error我收到以下错误

runfile('D:/Clones/i3d-master/i3d_train.py', wdir='D:/Clones/i3d-master')
Reloaded modules: i3d_inception
C:\Users\sancy\Anaconda3\lib\site-packages\keras\engine\training_generator.py:47: UserWarning: Using a generator with `use_multiprocessing=True` and multiple workers may duplicate your data. Please consider using the`keras.utils.Sequence class.
  UserWarning('Using a generator with `use_multiprocessing=True`'
Traceback (most recent call last):

  File "<ipython-input-8-8f7b9cc152d8>", line 1, in <module>
    runfile('D:/Clones/i3d-master/i3d_train.py', wdir='D:/Clones/i3d-master')

  File "C:\Users\sancy\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\sancy\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/Clones/i3d-master/i3d_train.py", line 108, in <module>
    use_multiprocessing = True,

  File "C:\Users\sancy\Anaconda3\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)

  File "C:\Users\sancy\Anaconda3\lib\site-packages\keras\engine\training.py", line 1418, in fit_generator
    initial_epoch=initial_epoch)

  File "C:\Users\sancy\Anaconda3\lib\site-packages\keras\engine\training_generator.py", line 174, in fit_generator
    while epoch < epochs:

TypeError: '<' not supported between instances of 'int' and 'str'

What am I doing wrong?我究竟做错了什么? What does epoch < epochs mean? epoch < epochs是什么意思?

Windows 10 python 3.7.1 spyder: 3.7 Windows 10 蟒蛇 3.7.1 间谍:3.7

How are you running the code?你是如何运行代码的? Looking at the Github repo, it takes 3 arguments查看 Github 存储库,它需要 3 个参数

i3d_train.py i3d_train.py

epochs = int(sys.argv[1])
model_name = sys.argv[2]
version = sys.argv[3]

finetune.sh 微调.sh

export PATH=/home/sdas/anaconda2/bin:$PATH
module load cuda/8.0 cudnn/5.1-cuda-8.0 opencv/3.4.1
mkdir -p weights_$2
python ./i3d_train.py $1 $2 $3

On a terminal, you should run it like this在终端上,你应该像这样运行它

python ./i3d_train.py <epochs> <model_name> <version>

This could also happen because of compatibility issues as quoted in the link below.这也可能由于以下链接中引用的兼容性问题而发生。

You should use learning_rate instead of lr while initializing the optimizer.您应该在初始化优化器时使用learning_rate而不是lr This solved my error.这解决了我的错误。

https://github.com/tensorflow/tensorflow/blob/fcc4b966f1265f466e82617020af93670141b009/tensorflow/python/keras/optimizer_v2/adam.py#L362-L363 https://github.com/tensorflow/tensorflow/blob/fcc4b966f1265f466e82617020af93670141b009/tensorflow/python/keras/optimizer_v2/adam.py#L362-L363

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决此错误输出:TypeError: &#39;NoneType&#39; 和 &#39;int&#39; 实例之间不支持 &#39;&lt;&#39; - How do I resolve this error output: TypeError: '<' not supported between instances of 'NoneType' and 'int' 如何在python 3中解决“ int”和“ NoneType”实例之间不支持“&#39;&lt;&#39;”的问题? - How do I resolve “'<' not supported between instances of 'int' and 'NoneType'” in python 3? 类型错误:“str”和“int”的实例之间不支持“&gt;”,但我将字符串设为 Interger - TypeError: '>' not supported between instances of 'str' and 'int' but I made the string an Interger 我有这个错误 TypeError: &#39;&lt;&#39; not supported between &#39;str&#39; and &#39;int&#39; - i am having this error TypeError: '<' not supported between instances of 'str' and 'int' 我收到TypeError:“ str”和“ int”的实例之间不支持“ &lt;” - I got a TypeError: '<' not supported between instances of 'str' and 'int' NLTK TypeError:&#39;str&#39;和&#39;int&#39;的实例之间不支持&#39;&lt;&#39; - NLTK TypeError: '<' not supported between instances of 'str' and 'int' Flask TypeError:“str”和“int”的实例之间不支持“&lt;” - Flask TypeError: '<' not supported between instances of 'str' and 'int' TypeError:在 Python 中的“str”和“int”实例之间不支持“&gt;” - TypeError: '>' not supported between instances of 'str' and 'int' in Python TypeError:'int'和'str'的实例之间不支持'&lt;=' - TypeError: '<=' not supported between instances of 'int' and 'str' “TypeError: &#39;&gt;&#39; 在 &#39;int&#39; 和 &#39;str&#39; 的实例之间不受支持”最大值 - "TypeError: '>' not supported between instances of 'int' and 'str'" in max
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM