import json matplotlib.use('Agg') import matplotlib.pyplot as plt from keras.callbacks import Callback from Rignak_Misc.plt import COLORS from Rignak_Misc.path import get_local_file from Rignak_DeepLearning.Image_to_Image.plot_example import plot_example as plot_autoencoder_example from Rignak_DeepLearning.Image_to_Class.plot_example import plot_example as plot_categorizer_example from Rignak_DeepLearning.Image_to_Class.plot_example import plot_regressor from Rignak_DeepLearning.Image_to_Class.confusion_matrix import compute_confusion_matrix, plot_confusion_matrix HISTORY_CALLBACK_ROOT = get_local_file(__file__, os.path.join('_outputs', 'history')) EXAMPLE_CALLBACK_ROOT = get_local_file(__file__, os.path.join('_outputs', 'example')) CONFUSION_CALLBACK_ROOT = get_local_file(__file__, os.path.join('_outputs', 'confusion')) class HistoryCallback(Callback): """Callback generating a fitness plot in a file after each epoch""" def __init__(self, batch_size, training_steps, root=HISTORY_CALLBACK_ROOT): super().__init__() self.x = [] self.logs = {} self.root = root self.batch_size = batch_size self.training_steps = training_steps
import subprocess from graphviz import Digraph import numpy as np import os import unicodedata from Rignak_Misc.path import get_local_file from Rignak_MAL_database.database import load DOT_FILENAME = get_local_file(__file__, os.path.join('outputs', 'recommandations.dot')) PNG_FILENAME = get_local_file( __file__, os.path.join('outputs', 'png', 'recommandations¤.png')) THRESHOLD_FACTOR = 1 FONT_POWER = 2 / 3 EDGE_POWER = 1 / 3 def get_widths(id2title, recommendations): anime_widths = {} for anime_id in id2title: anime_widths[anime_id] = 0 for (k1, k2), n in recommendations.items(): if anime_id == k1 or anime_id == k2: anime_widths[anime_id] += recommendations[(k1, k2)] return anime_widths def plot_nodes(graph, user_anime, id2title, anime_widths): threshold = np.mean(list(anime_widths.values())) * THRESHOLD_FACTOR
from scipy import signal from PIL import Image import sys import numpy as np import io import os import fire import matplotlib.pyplot as plt from Rignak_Misc.path import get_local_file INPUT_FOLDER = get_local_file(__file__, 'input') HIGH_PASS_FILTER = np.array([[0, -3, 0], [-3, 12, -3], [0, -3, 0]]) MIN_POSSIBLE_QUALITY = 1 MAX_POSSIBLE_QUALITY = 100 def filter_array(array, array_filter): return signal.convolve2d(array, array_filter)[1:-1, 1:-1] def filter_image(im, array_filter=HIGH_PASS_FILTER): array = np.array(im) grayscale_array = np.mean(array, axis=-1) filtered_array = filter_array(grayscale_array, array_filter) return filtered_array def jpeg_noise_detection(filename): jpeg_noise = []
import os import numpy as np import tqdm.auto as tqdm from keras.models import load_model as keras_load_model from Rignak_Misc.path import get_local_file from Rignak_DeepLearning.data import read MODELS_FOLDER = get_local_file(__file__, os.path.join('_outputs', 'models')) BATCH_SIZE = 16 def load_model(model_filename, models_folder=MODELS_FOLDER): return keras_load_model(os.path.join(models_folder, model_filename)) def run_batch(array, model, batch_size=BATCH_SIZE, normalizer=None, use_tqdm=False): output_shape = model.layers[-1].output_shape[-1] output = np.zeros((array.shape[0], output_shape)) batch_range = range(array.shape[0] // batch_size + 1) if use_tqdm: batch_range = tqdm.tqdm(batch_range) for batch_i in batch_range: batch = array[batch_i * batch_size:(batch_i + 1) * batch_size] if normalizer is not None:
import tqdm from keras.models import Model from keras.layers import Input, Lambda, concatenate, GlobalAveragePooling2D, Dense, Conv2D from keras.applications.inception_v3 import InceptionV3 from keras.losses import mean_squared_error from keras_radam.training import RAdamOptimizer import keras.backend as K from Rignak_DeepLearning.Image_to_Image.unet import import_model as import_unet_model from Rignak_Misc.path import get_local_file from Rignak_DeepLearning.config import get_config from Rignak_DeepLearning.loss import weighted_binary_crossentropy from Rignak_DeepLearning.models import write_summary WEIGHT_ROOT = get_local_file(__file__, os.path.join('..', '_outputs', 'models')) SUMMARY_ROOT = get_local_file(__file__, os.path.join('..', '_outputs', 'summary')) LOAD = False LEARNING_RATE = 10**-4 CONFIG_KEY = 'segmenter' CONFIG = get_config()[CONFIG_KEY] DEFAULT_NAME = CONFIG.get('NAME', 'DEFAULT_MODEL_NAME') def import_inception(config, input_layer, learning_rate=LEARNING_RATE): input_shape = config.get('INPUT_SHAPE') if input_shape[0] < 75 or input_shape[ 1] < 75: # minimal input for InceptionV3 input_layer_resize = Lambda(
import os import pygame from Rignak_Misc.path import get_local_file from Rignak_Games.Asteroid.Screen import Screen from Rignak_Games.Asteroid.collisions import get_bullet_collisions, get_ship_collisions from Rignak_Games.Sprites import SCALING_FACTOR, SPRITE_ROOT DEFAULT_BATTLE = 'default' BATTLE_FILENAME = get_local_file(__file__, os.path.join('res', 'json', 'battles.json')) SCREEN_WIDTH = 512 SCREEN_HEIGHT = 512 BACKGROUND_FILENAME = os.path.join(SPRITE_ROOT, 'bg_main.png') BACKGROUND = pygame.transform.scale( pygame.image.load(BACKGROUND_FILENAME), (int(SCREEN_WIDTH * SCALING_FACTOR), int(SCREEN_HEIGHT * SCALING_FACTOR))) FPS = 20 DAMAGE_ON_COLLISION = 1000 class GameState: def __init__(self, battle=DEFAULT_BATTLE, battle_filename=BATTLE_FILENAME, screen_width=SCREEN_WIDTH,
import math import os import json from functools import lru_cache from Rignak_Games.Entities import Entity from Rignak_Games.Asteroid.Bullets import Bullet from Rignak_Misc.path import get_local_file SHIP_FILENAME = get_local_file(__file__, os.path.join('res', 'json', 'ships.json')) class Ship(Entity): def __init__(self, ship_name, team, x, y, angle, x_speed=0, y_speed=0, angle_speed=0, ship_filename=SHIP_FILENAME): ship = load(ship_name, ship_filename=ship_filename) super(Ship, self).__init__(ship['sprite'], x=x, y=y, angle=angle, x_speed=x_speed, y_speed=y_speed, angle_speed=angle_speed) self.team = team self.dead = False self.score = 0 self.bullet_sprite = ship['bullet_sprite'] self.reward = ship['reward'] self.hp = ship['hp'] self.shield = ship['shield'] self.acceleration = ship['acceleration'] self.bullets = [] self.fire_delay = ship['fire_delay']
import json from Rignak_Misc.path import get_local_file CONFIG_FILENAME = get_local_file(__file__, 'config.json') def get_config(config_filename=CONFIG_FILENAME): with open(config_filename, 'r') as file: config = json.load(file) return config