Some tips about Python, Pandas, and Tensorflow

  • Post author:
  • Post category:IT
  • Post comments:0评论

There are some useful tips for using Keras and Tensorflow to build models.

1. Using applications.inception_v3.InceptionV3(include_top = False, weights = ‘Imagenet’) to get pretrained parameters for InceptionV3 model, the console reported:

Exception: URL fetch failure on None -- unknown url type: https

The solution ishere. Just install some packages:

Sudo yum install openssl openssl-devel -y

2. Could we use ‘add’ to merge two DataFrames of Pandas? Let’s try

import pandas as pd

a = pd.DataFrame([[1, 2], [3, 4]], columns = ['first', 'second'])
b = pd.DataFrame([], columns = ['first', 'second'])

The result is:

first second
0   NaN    NaN
1   NaN    NaN

The operator ‘+’ just works as ‘pandas.DataFrame.add‘. It try to add all values column by column, but the second DataFrame is empty, so the result of adding a number and a nonexistent value is ‘Nan’.

To merge two DataFrames, we should use ‘append’:


3. Why Estimator of Tensorflow doesn’t print out log?

logging_hook = tf.train.LoggingTensorHook({'step': global_step, 'loss': loss, 'precision': precision, 'recall': recall, 'f1': f1, 'auc': auc},
            every_n_iter = every_n_iter, formatter = formatter_log)
    if mode == tf.estimator.ModeKeys.EVAL:
        return tf.estimator.EstimatorSpec(mode, loss = loss, evaluation_hooks = [logging_hook])

But the logging_hook hasn’t been run. The solution is just adding one line before running Estimator: