text
stringlengths
1
93.6k
initial_img = normalize_image(np.float32(initial_img.cpu()[0].permute(1, 2, 0).data.numpy()))
# from now :
# - heatmap : numpy array with values between 0 and 1
# - initial_img : numpy array with values between 0 and 1
heatmap = cv2.resize(heatmap, (initial_img.shape[0], initial_img.shape[1])) # interpolation of the heatmap
heatmap = np.uint8(255 * heatmap) # convert between 0 and 255
heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET) # infer the heatmap colorization
heatmap = np.float32(heatmap) / 255. # convert between 0 and 1
superimposed_img = heatmap + initial_img # merge heatmap & initial image
superimposed_img = normalize_image(superimposed_img) # normalize the produced image
superimposed_img = np.uint8(255 * superimposed_img) # convert between 0 and 255
cv2.imwrite(produced_img_path, superimposed_img)
print("Interpretable image registred at : {}".format(produced_img_path))
def get_main_coeffs(term_1, term_2):
"""
Input:
term_1, term_2: vectors
Output:
indices of the coefficients that contribute the most to the score
resulting from the dot product of `term_1` and `term_2`.
"""
return (term_1 * term_2).detach().cpu()[0].sort()[1][-NUMBER_OF_MAIN_COEFF:] # [0] because we consider the first (and unique) element of the batch
################################################################################
#### MAIN
if __name__ == '__main__':
args = verify_input_args(parser.parse_args())
# Load model
args, model, vocab = load_model(args)
# Generate heatmaps
main_generate_heatmaps(args, model, vocab)
# <FILESEP>
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Python script to convert Forex files into different formats (e.g. FXT/HST/HCC).
from struct import pack, pack_into, calcsize
import argparse
import bstruct
import csv
import datetime
import mmap
import os
import re
import sys
import time
class Spinner:
"""Displays an ASCII spinner"""
def __init__(self, step):
self._n = self._x = 0
self._chars = "\\|/-"
self._step = step
def spin(self):
self._n += 1
if self._n % self._step == 0:
sys.stdout.write("\b" + self._chars[self._x % 4])
sys.stdout.flush()
self._x += 1
if self._x >= 4:
self._x = 0
self._n = 0
spinner = Spinner(100000)
class Input:
def __init__(self, path):
if args.verbose:
print("[INFO] Trying to read data from %s..." % path)
try:
self.path = open(path, "r")
except OSError as e:
print(
"[ERROR] '%s' raised when tried to read the file '%s'"
% (e.strerror, e.filename)
)
sys.exit(1)
self.uniBars = []
def __del__(self):