In [1]:
%load_ext autoreload
%autoreload 2
import os
import re
import vislab._results
import pandas as pd
import vislab
import vislab.datasets
import vislab.results
import vislab.vw3
In [21]:
def write_pascal_as_feat(
dataset_name, mc_pred_df, target_feature_name,
feature_name='pascal_mc'):
"""
Get the ids of the target feature, and output to txt.gz in the same order.
"""
# Get the id order of the target feature.
target_feature_ids_name = '{}/{}/{}.txt.gz.ids.txt'.format(
vislab.config['paths']['feats'], dataset_name, target_feature_name)
if not os.path.exists(target_feature_ids_name):
print("Feature ids file does not exist! Run scripts/get_feat_file_ids.sh")
image_ids = pd.Index([x.strip() for x in open(target_feature_ids_name)])
# Output this feature in the same order to the same directory.
output_filename = '{}/{}/{}_for_{}.txt.gz'.format(
vislab.config['paths']['feats'], dataset_name, feature_name, target_feature_name)
mc_pred_df = mc_pred_df.ix[image_ids.tolist()]
# Note that we may not have all the ids.
# In that case, just fill with column means to introduce no information.
print('{}/{} records are null'.format(
mc_pred_df.isnull().any(1).sum(), mc_pred_df.shape[0]))
df = mc_pred_df.fillna(mc_pred_df.mean())
# Standardize
df = (df - df.values.mean(0)) / df.values.std(0)
print df.info()
# Write to file.
vislab.vw3.write_data_in_vw_format(df, feature_name, output_filename)
print("Success, written to {}".format(output_filename))
In [52]:
pascal_feat='decaf_fc6 None vw'
In [10]:
## AVA Style
results_df, preds_panel = aphrodite.results.load_pred_results(
'pascal_meta_on_ava_oct29', os.path.expanduser('~/work/aphrodite/data/results2'),
multiclass=False, force=False)
mc_pred_df = preds_panel.minor_xs(pascal_feat).astype(float)
mc_pred_df.columns = [x.replace('clf ava_style_', '') for x in mc_pred_df.columns]
# best feature is decaf_fc6
#write_pascal_as_feat('ava_style', mc_pred_df, 'decaf_fc6')
#write_pascal_as_feat('ava_style', mc_pred_df, 'lab_hist')
#write_pascal_as_feat('ava_style', mc_pred_df, 'noise')
write_pascal_as_feat('ava_style', mc_pred_df, 'fusion_ava_style_oct22')
In [22]:
## Flickr
results_df, preds_panel = vislab._results.load_pred_results(
'pascal_mc_on_flickr_mar23', os.path.expanduser('~/work/vislab-git/data/results'),
multiclass=True, force=False)
pascal_feat='caffe_fc7 False vw'
mc_pred_df = preds_panel.minor_xs(pascal_feat)
mc_pred_df = mc_pred_df[[x for x in mc_pred_df.columns if x.startswith('pred_metaclass_')]]
mc_pred_df
# RUN ./scripts/get_feat_file_ids.sh BEFOREHAND
write_pascal_as_feat('flickr', mc_pred_df, 'fusion_flickr_mar23')
In [21]:
## Wikipaintings
results_df, preds_panel = aphrodite.results.load_pred_results(
'pascal_on_wp_oct29', os.path.expanduser('~/work/aphrodite/data/results2'),
multiclass=False, force=False)
mc_pred_df = preds_panel.minor_xs(pascal_feat).astype(float)
mc_pred_df.columns = [x.replace('clf wikipaintings_', '') for x in mc_pred_df.columns]
mc_pred_df = mc_pred_df[[x for x in mc_pred_df.columns if x.startswith('metaclass_')]]
mc_pred_df
# best feature is mc_bit, but we'll run on decaf to finish in a reasonable time
#write_pascal_as_feat('wikipaintings', mc_pred_df, 'decaf_fc6')
#write_pascal_as_feat('wikipaintings', mc_pred_df, 'noise')
write_pascal_as_feat('wikipaintings', mc_pred_df, 'fusion_wikipaintings_oct25')
Out[21]:
In [17]:
import aphrodite.image
mc_pred_df = mc_pred_df.sort('metaclass_animal', ascending=False)
for image_id in mc_pred_df.iloc[:5].index:
imshow(aphrodite.image.get_image_for_id(image_id, 'ava_style'))
figure()
In [36]:
import aphrodite.image
mc_pred_df = mc_pred_df.sort('metaclass_person', ascending=False)
for image_id in mc_pred_df.iloc[:5].index:
imshow(aphrodite.image.get_image_for_id(image_id, 'ava_style'))
figure()
In [37]:
import aphrodite.image
mc_pred_df = mc_pred_df.sort('metaclass_vehicle', ascending=False)
for image_id in mc_pred_df.iloc[:5].index:
imshow(aphrodite.image.get_image_for_id(image_id, 'ava_style'))
figure()
In [38]:
import aphrodite.image
mc_pred_df = mc_pred_df.sort('metaclass_indoor', ascending=False)
for image_id in mc_pred_df.iloc[:5].index:
imshow(aphrodite.image.get_image_for_id(image_id, 'ava_style'))
figure()
In [39]:
results_df, preds_panel = aphrodite.results.load_pred_results(
'pascal_on_wp_oct29', os.path.expanduser('~/work/aphrodite/data/results2'),
multiclass=False, force=False)
pred_prefix = 'pred'
print preds_panel.minor_axis
preds_panel
Out[39]:
In [47]:
dataset_name = 'wikipaintings'
mc_pred_df = preds_panel.minor_xs('decaf_fc6 False vw')
mc_pred_df.columns = [x.replace('clf {}_'.format(dataset_name), '') for x in mc_pred_df.columns]
mc_pred_df
Out[47]:
In [49]:
import aphrodite.image
mc_pred_df = mc_pred_df.sort('metaclass_person', ascending=False)
for image_id in mc_pred_df.iloc[:5].index:
imshow(aphrodite.image.get_image_for_id(image_id, dataset_name))
figure()
In [50]:
import aphrodite.image
mc_pred_df = mc_pred_df.sort('metaclass_animal', ascending=False)
for image_id in mc_pred_df.iloc[:5].index:
imshow(aphrodite.image.get_image_for_id(image_id, dataset_name))
figure()