首页 > 解决方案 > TF 估计梯度提升分类器在训练时突然停止

问题描述

我用 TF 示例代码训练了梯度增强分类器 https://www.tensorflow.org/tutorials/estimators/boosted_trees_model_understanding

但是,TF 估计梯度提升分类器在训练时突然停止

我认为乞讨需要几步,而不是突然停止无一例外打印

我怎样才能得到python崩溃的任何原因

很难找到它停止的原因

资源:

lib : TF-gpu 1.13.1
cuda : 10.0
cudnn : 7.5

日志:

localhost/replica:0/task:0/device:GPU:0 with 4716 MB memory)-> 物理 GPU(设备:0,名称:GeForce GTX 1060 6GB,pci 总线 ID:0000:07:00.0,计算能力:6.1 ) WARNING:tensorflow:From D:\python\lib\site-packages\tensorflow\python\training\saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) 已弃用,将在未来版本中删除. 更新说明:使用标准文件 API 检查具有此前缀的文件。警告:tensorflow:来自 D:\python\lib\site-packages\tensorflow\python\training\saver.py:1070:get_checkpoint_mtimes(来自 tensorflow.python.training.checkpoint_management)已弃用,将在未来版本中删除。更新说明:使用标准文件实用程序获取 mtimes。警告:张量流:序列化资源时遇到的问题。类型不受支持,或者项目的类型与 CollectionDef 中的字段类型不匹配。请注意,这是一个警告,可能可以安全地忽略。'_Resource' 对象没有属性 'name' 警告:tensorflow:序列化资源时遇到的问题。类型不受支持,或者项目的类型与 CollectionDef 中的字段类型不匹配。请注意,这是一个警告,可能可以安全地忽略。'_Resource' 对象没有属性 'name' 或者项目的类型与 CollectionDef 中的字段类型不匹配。请注意,这是一个警告,可能可以安全地忽略。'_Resource' 对象没有属性 'name' 或者项目的类型与 CollectionDef 中的字段类型不匹配。请注意,这是一个警告,可能可以安全地忽略。'_Resource' 对象没有属性 'name'

D:\py>(刚刚完成培训)

trn = pd.read_csv('data/santander-customer-transaction-prediction/train.csv')
        tst = pd.read_csv('data/santander-customer-transaction-prediction/test.csv')



    #trn = upsample(trn[trn.target==0], trn[trn.target==1])
#   trn = downsample(trn[trn.target==0], trn[trn.target==1])


    features = trn.columns.values[2:202]
    target_name = trn.columns.values[1]
    train=trn[features]
    target=trn[target_name]

    NUM_EXAMPLES = len (target)
    print (NUM_EXAMPLES)

    feat1 = train.corrwith(target).sort_values().head(20).index
    feat2 = train.corrwith(target).sort_values().tail(20).index
    featonly = feat1.append(feat2)
    feat = featonly.append(pd.Index(['target']))

    train_origin, tt = train_test_split(trn, test_size=0.2)

    train = train_origin[featonly]
    target = train_origin[target_name]
    test = tst[featonly]

    target_name_tst = tst.columns.values[1]
    target_tst=tst[target_name_tst]

    val_origin=tt
    val_train = tt[featonly]
    val_target = tt[target_name]
    # Training and evaluation input functions.

    train_input_fn = make_input_fn(train, target)
    val_input_fn = make_input_fn(val_train, val_target)

    ttt=tf.estimator.inputs.pandas_input_fn(x=test,num_epochs=1,shuffle=False)


    del train,target,val_train,train_origin,trn,tst

    fc = tf.feature_column
    feature_columns = []
    for feature_name in featonly:
        feature_columns.append(fc.numeric_column(feature_name,dtype=tf.float32))
    #feature_columns



    #5
    #tf.logging.set_verbosity(tf.logging.INFO)
    #logging_hook = tf.train.LoggingTensorHook({"loss" : loss, "accuracy" : accuracy}, every_n_iter=10)

    params = {
      'n_trees': 50,
      'max_depth': 3,
      'n_batches_per_layer': 1,
      # You must enable center_bias = True to get DFCs. This will force the model to 
      # make an initial prediction before using any features (e.g. use the mean of 
      # the training labels for regression or log odds for classification when
      # using cross entropy loss).
      'center_bias': True
    }
#   config = tf.estimator.RunConfig().replace(keep_checkpoint_max = 1, 
 #                   log_step_count_steps=20, save_checkpoints_steps=20)

    est = tf.estimator.BoostedTreesClassifier(feature_columns, **params,model_dir='d:\py/model/')
    est.train(train_input_fn, max_steps=50)

-------------------------------------------------------已停止

metrics = est.evaluate(input_fn=val_input_fn,steps=1)

    results = est.predict(input_fn=ttt )
    result_list = list(results)


    classi = list(map(lambda x : x['classes'][0].decode("utf-8"), result_list))
    num = list(range(0,len(classi)))
    numi = list(map(lambda x : 'test_' + str(x),num))
    #df1 = pd.DataFrame(columns=('ID_code','target'))

    df_result = pd.DataFrame({'ID_code' : numi, 'target' : classi})

    df_result.to_csv('result/submission03.csv',index=False)

def make_input_fn(X, y, n_epochs=None, shuffle=True):
def input_fn():
    NUM_EXAMPLES = len(y)
    dataset = tf.data.Dataset.from_tensor_slices((dict(X), y))
  #  dataset = tf.data.Dataset.from_tensor_slices((X.to_dict(orient='list'), y))
    #if shuffle:
     #   dataset = dataset.shuffle(NUM_EXAMPLES)
    # For training, cycle thru dataset as many times as need (n_epochs=None).    
    dataset = (dataset.repeat(n_epochs).batch(NUM_EXAMPLES)) 
    return dataset
return input_fn

应显示评估结果

标签: tensorflowcrashclassificationtensorflow-estimator

解决方案


我认为问题是由 GPU 内存溢出引起的。您可以尝试根据您的 GPU 内存大小将“n_batches_per_layer”的值修改为更大的值。我使用的是 6G GPU,值为 16。


推荐阅读