Skip to content

Instantly share code, notes, and snippets.

@basile-bron
basile-bron / remove_corrupted_images.py
Created March 5, 2021 11:10
remove_corrupted_images
from os import listdir
from PIL import Image
for filename in listdir('data/images/'):
try:
img = Image.open('./data/images/'+filename) # open the image file
img.verify() # verify that it is, in fact an image
except (IOError, SyntaxError) as e:
print('Bad file:', filename) # print out the names of corrupt files
os.remove('./data/documents/'+filename)
@basile-bron
basile-bron / model.json
Last active October 12, 2020 17:55
model.json
{"format": "layers-model", "generatedBy": "keras v2.4.0", "convertedBy": "TensorFlow.js Converter v2.5.0", "modelTopology": {"keras_version": "2.4.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, 20], "dtype": "float32", "sparse": false, "ragged": false, "name": "embedding_input"}}, {"class_name": "Embedding", "config": {"name": "embedding", "trainable": true, "batch_input_shape": [null, 20], "dtype": "float32", "input_dim": 10000, "output_dim": 16, "embeddings_initializer": {"class_name": "RandomUniform", "config": {"minval": -0.05, "maxval": 0.05, "seed": null}}, "embeddings_regularizer": null, "activity_regularizer": null, "embeddings_constraint": null, "mask_zero": false, "input_length": 20}}, {"class_name": "Bidirectional", "config": {"name": "bidirectional", "trainable": true, "dtype": "float32", "layer": {"class_name": "LSTM", "config": {"name": "lstm", "trainable": t
import tensorflow as tf
frozen_graph = tf.compat.v1.keras.backend.get_session().graph
tf.io.write_graph(frozen_graph, "/content/drive/My Drive/data/", "model.pb", as_text=False)
import glob
from random import shuffle
import h5py
import numpy as np
import cv2
import math
import time
import matplotlib.pyplot as plt
%matplotlib inline
@basile-bron
basile-bron / requirement_install.bat
Last active January 25, 2020 17:16
install all requirement without stoping for missing one. credit to @clay : https://stackoverflow.com/users/5060792/clay
FOR /F "delims=~" %f in (requirements.txt) DO conda install --yes "%f" || pip install "%f"
@basile-bron
basile-bron / Logger.py
Created January 24, 2020 10:24
python logger
#Creation and configuration of the logger
LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(filename = "log.txt",
level = logging.DEBUG, #you can change DEBUG to : INFO,WARNING,ERROR,CRITICAL
format = LOG_FORMAT,
filemode = 'w')
logger = logging.getLogger()
# here is the diferent level you can use
#logger.debug("")
#logger.info("")
@basile-bron
basile-bron / linear_to_tag.py
Created January 17, 2020 10:03
linear dataset to label dataset
Y = np.zeros((5,), dtype=int)
Y = pd.cut(train_y, bins=[-1,25,50,75,100,np.inf], labels=[(1,0,0,0,0),(0,1,0,0,0),(0,0,1,0,0),(0,0,0,1,0),(0,0,0,0,1)])
train_y = Y
@basile-bron
basile-bron / variable_saver.py
Created December 8, 2019 00:22
Saving variable as npy and loading it
import numpy as np
#the tree following line allow you to save the train data in a file data.npy
np.save("data.npy", X,allow_pickle=True)
#loading the file
X = np.load("fooooo.npy")