コード例 #1
0
    def generate_output_names(self, batch_index, params, results,
                              prefix_template, output_dir):

        results_and_params = combine_dicts(
            (('p.', params.__dict__), ('r.', results[batch_index].__dict__)))
        prefix = prefix_template % results_and_params

        prefix = os.path.join(output_dir, prefix)

        if os.path.isdir(prefix):
            if prefix[-1] != '/':
                prefix += '/'  # append slash for dir-only template
        else:
            dirname = os.path.dirname(prefix)
            if dirname:
                mkdir_p(dirname)

        best_X_name = '%s_best_X.jpg' % prefix
        best_Xpm_name = '%s_best_Xpm.jpg' % prefix
        majority_X_name = '%s_majority_X.jpg' % prefix
        majority_Xpm_name = '%s_majority_Xpm.jpg' % prefix
        info_name = '%s_info.txt' % prefix
        info_pkl_name = '%s_info.pkl' % prefix
        info_big_pkl_name = '%s_info_big.pkl' % prefix
        return [
            best_X_name, best_Xpm_name, majority_X_name, majority_Xpm_name,
            info_name, info_pkl_name, info_big_pkl_name
        ]
コード例 #2
0
    def save_results(self,
                     params,
                     results,
                     prefix_template,
                     brave=False,
                     skipbig=False):
        if prefix_template is None:
            return

        results_and_params = combine_dicts(
            (('p.', params.__dict__), ('r.', results.__dict__)))
        prefix = prefix_template % results_and_params

        if os.path.isdir(prefix):
            if prefix[-1] != '/':
                prefix += '/'  # append slash for dir-only template
        else:
            dirname = os.path.dirname(prefix)
            if dirname:
                mkdir_p(dirname)

        # Don't overwrite previous results
        if os.path.exists('%sinfo.txt' % prefix) and not brave:
            raise Exception('Cowardly refusing to overwrite ' +
                            '%sinfo.txt' % prefix)

        output_majority = False
        if output_majority:
            if results.majority_xx is not None:
                asimg = results.majority_xx[
                    self.channel_swap_to_rgb].transpose((1, 2, 0))
                saveimagescc('%smajority_X.jpg' % prefix, asimg, 0)
                saveimagesc('%smajority_Xpm.jpg' % prefix,
                            asimg + self._data_mean_rgb_img)  # PlusMean

        if results.best_xx is not None:
            asimg = results.best_xx[self.channel_swap_to_rgb].transpose(
                (1, 2, 0))
            saveimagescc('%sbest_X.jpg' % prefix, asimg, 0)
            saveimagesc('%sbest_Xpm.jpg' % prefix,
                        asimg + self._data_mean_rgb_img)  # PlusMean

        with open('%sinfo.txt' % prefix, 'w') as ff:
            print >> ff, params
            print >> ff
            print >> ff, results
        if not skipbig:
            with open('%sinfo_big.pkl' % prefix, 'w') as ff:
                pickle.dump((params, results), ff, protocol=-1)
        results.trim_arrays()
        with open('%sinfo.pkl' % prefix, 'w') as ff:
            pickle.dump((params, results), ff, protocol=-1)
コード例 #3
0
    def save_results(self, params, results, prefix_template, brave = False, skipbig = False):
        if prefix_template is None:
            return

        results_and_params = combine_dicts((('p.', params.__dict__),
                                            ('r.', results.__dict__)))
        prefix = prefix_template % results_and_params
        
        if os.path.isdir(prefix):
            if prefix[-1] != '/':
                prefix += '/'   # append slash for dir-only template
        else:
            dirname = os.path.dirname(prefix)
            if dirname:
                mkdir_p(dirname)

        # Don't overwrite previous results
        if os.path.exists('%sinfo.txt' % prefix) and not brave:
            raise Exception('Cowardly refusing to overwrite ' + '%sinfo.txt' % prefix)

        output_majority = False
        if output_majority:
            if results.majority_xx is not None:
                asimg = results.majority_xx[self.channel_swap_to_rgb].transpose((1,2,0))
                saveimagescc('%smajority_X.jpg' % prefix, asimg, 0)
                saveimagesc('%smajority_Xpm.jpg' % prefix, asimg + self._data_mean_rgb_img)  # PlusMean

        if results.best_xx is not None:
            asimg = results.best_xx[self.channel_swap_to_rgb].transpose((1,2,0))
            saveimagescc('%sbest_X.jpg' % prefix, asimg, 0)
            saveimagesc('%sbest_Xpm.jpg' % prefix, asimg + self._data_mean_rgb_img)  # PlusMean

        with open('%sinfo.txt' % prefix, 'w') as ff:
            print >>ff, params
            print >>ff
            print >>ff, results
        if not skipbig:
            with open('%sinfo_big.pkl' % prefix, 'w') as ff:
                pickle.dump((params, results), ff, protocol=-1)
        results.trim_arrays()
        with open('%sinfo.pkl' % prefix, 'w') as ff:
            pickle.dump((params, results), ff, protocol=-1)