Skip to content

Instantly share code, notes, and snippets.

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
def grad_cam(layer_name, data, model):
grad_model = tf.keras.models.Model(
[model.inputs], [model.get_layer(layer_name).output, model.output]
)
last_conv_layer_output, preds = grad_model(data)
@Bsingstad
Bsingstad / custom_batch_gen.py
Created May 8, 2020 06:22
Making your own batch generator in Python
def generate_y():
while True:
for i in range(len(y_train)):
y= y_train[i]
yield y
def generate_X():
while True:
with open("/kaggle/input/physionet-csv-april-2020/ECG_long_signals_train.csv") as f:
@Bsingstad
Bsingstad / comp.vhd
Created December 1, 2019 13:41
A comparator with testbench
------------------------------------------------
-- A comparator that compares vector A and B --
-- equal is set to 1 when A and B are equal --
-- equal is 0 when others --
------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
entity comp is
port (
@Bsingstad
Bsingstad / TenBase_to_binary_converter.py
Last active November 21, 2019 11:28
Binary, hex and ten base conversion in Python
def tenBase_to_binary_converter(x):
y =''
while (x>=1):
#print(x)
if (x % 2) == 0:
y+='0'
else:
y+='1'
x=x//2
return y[::-1] #reverses the sting
-- This example shows how to synchronize a external signal with its own clock
import lirabry;
use.ieee.std_logic.1146.all;
entity synch is
port(
inputSignalA : in std_logic;
clk : in std_logic;
OutputSignalC : out std_logic
);
architecture behaviour of edge_detector is
signal B : std_logic := 0;
begin
--edge detector
p_behav: process (clk)
begin
if rising_edge(clk) then
B <= A;
end if;
end process;
library IEEE;
use IEEE.std_logic_1164.use;
entity register_vhdl is
port(
clk : in std_logic;
inngang : in std_logic;
utgang : out std_logic;
LD : in std_logic
);
library IEEE;
use IEEE.std_logic_1164.all;
entity multiplexer is
port(
inngangA : in std_logic;
inngangB : in std_logic;
inngangC : in std_logic;
inngangD : in std_logic;
Utgang : out std_logic;
@Bsingstad
Bsingstad / Entity_for_I2C-master.vhd
Last active November 15, 2019 08:51
VHDL-files
entity i2c_master is
generic(
GC_SYSTEM_CLK : integer := 50000000;
GC_I2C_CLK : integer := 2000000
);
port(
clk : in std_logic;
rst_n : in std_logic;
valid : in std_logic;
addr : in STD_logic_vector(6 downto 0);
@Bsingstad
Bsingstad / semaphores.c
Last active November 15, 2019 08:52
VHDL-files
#include <string.h>
#include <stdio.h>
#include <system.h>
#include <altera_avalon_pio_regs.h>
#include "includes.h"
#include "i2c_avalon_mm_if.h"
#include "adxl345.h"
#include "unistd.h"
#include <sys/alt_irq.h>
#include <io.h>