Skip to content

Instantly share code, notes, and snippets.

View bzamecnik's full-sized avatar

Bohumír Zámečník bzamecnik

View GitHub Profile
@bzamecnik
bzamecnik / extract_musicnet_labels.py
Created July 17, 2017 11:12
Extract MusicNet labels
#!/usr/bin/env python3
# Extracts just a dataset of labels (ingoring audio) from the full
# MusicNet dataset in order to shrink it from 11 GB.
# Note: I was not able to save objects (not numpy arrays) back to npz file,
# so we save to pickle.
import numpy as np
from tqdm import tqdm
# the npz file was picked in Python 2, we're opening in Python 3
package com.github.fge.jsonschema
import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import com.github.fge.jsonschema.main.{JsonSchema, JsonSchemaFactory}
import org.scalatest.FunSuite
// Example of using JSON-schema validator
// https://github.com/java-json-tools/json-schema-validator
//
// Code Samples - Example 1 - translated to a Scala test:
@bzamecnik
bzamecnik / README.md
Created May 14, 2017 08:46
How to fix corrupted DJI video from Phantom drone

During filming of off-road piano improvisations in New Zealand a Phantom 4 drone crashed in the flight, the last video is corrupted. Here's how we fixed it:

  • DJI_0065.mov - corrupt
  • DJI_0065.mov - OK

Let's compare the metadata:

$ ffmpeg -i DJI_0065.mov
[...]
@bzamecnik
bzamecnik / decrypt_pdf.py
Created January 18, 2017 07:54
Decrypt password-protected PDF in Python.
# Decrypt password-protected PDF in Python.
# cleaned-up version of http://stackoverflow.com/a/26537710/329263
#
# Requirements:
# pip install PyPDF2
#
# Usage: decrypt_pdf('encrypted.pdf', 'decrypted.pdf', 'secret_password')
from PyPDF2 import PdfFileReader, PdfFileWriter
@bzamecnik
bzamecnik / join_invoices.py
Last active April 27, 2023 06:50
Joins multiple single-file invoices in the StormWare Pohoda XML format to a single XML file.
"""
Joins multiple single-file invoices in the StormWare Pohoda XML format to a
single XML file.
https://www.stormware.cz/xml/schema/version_2/invoice.xsd
https://www.stormware.cz/schema/version_2/data.xsd
Usage:
$ python join_invoices.py 'single_invoices/*.xml' merged_invoice.xml
@bzamecnik
bzamecnik / lenovo_p70_wifi_bugs.md
Created January 1, 2017 07:18
Lenovo P70 wifi bugs
  • firmware: Lenovo_P70-A_S134_150729

There's a strange bug in Lenovo P70 which affects WiFi. Let me describe it.

Ocassionaly the WiFi diconnects and is not able to connect again. When I try to connect it asks me for password and then just shows Saved, but doesn't connect. Also the UI in the WiFi settings behaves stranglely. When I turn off WiFi it stays enabled, etc.

The solution that works sometimes is to go into the Flight mode and back. Sometimes it helps for the first time, sometimes after a few tries. Also restart works, but takes more time.

However, the flight mode affect some other features. It changes the sleep mode timer to less then 1 minute, so I need to adjust it again. Also it disables automatic screen rotation.

@bzamecnik
bzamecnik / process_memory_usage_osx.sh
Last active January 24, 2021 15:37
Process memory usage on OSX using GNU time
# On Linux we can use native GNU time, on OSX we have to install gnu-time
# manually, since native time doesn't measure memory.
# http://man7.org/linux/man-pages/man1/time.1.html
# http://braumeister.org/formula/gnu-time
$ brew install gnu-time
# can be called via gtime, since time is a bash command
# %M - Maximum resident set size of the process during its lifetime, in Kbytes.
@bzamecnik
bzamecnik / simples_lstm_softmax_classifier_keras.py
Created December 24, 2016 07:11
Simplest sequence classifier with LSTM & softmax in Keras
"""
Classifies sequences of length 10 with 20 features into 2 classes
with a single LSTM layer with 32 neurons.
See also a more involved example:
https://gist.github.com/bzamecnik/dccc1c4fdcf1c7a31757168b19c827a7
"""
from keras.layers import Input, LSTM, Dense
@bzamecnik
bzamecnik / lstm_with_softmax_keras.py
Created December 24, 2016 07:04
LSTM with softmax activation in Keras
"""
When classifying upon a sequence usually we stack some LSTM returning sequences,
then one LSTM returning a point, then Dense with softmax activation.
Is it possible instead to give the last non-sequential LSTM a softmax activation?
The answer is yes.
In this example we have 3 sequential layers and one layer producing the final result.
@bzamecnik
bzamecnik / model_summary.txt
Last active May 31, 2024 16:42
Residual LSTM in Keras
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_1 (InputLayer) (None, 32, 10) 0
____________________________________________________________________________________________________
lstm_1 (LSTM) (None, 32, 10) 840 input_1[0][0]
____________________________________________________________________________________________________
add_1 (Add) (None, 32, 10) 0 input_1[0][0]
lstm_1[0][0]
____________________________________________________________________________________________________