Commit 568b365f authored by Jack's avatar Jack
Browse files

first commit, adding all files

parents
/venv/
/.idea
This diff is collapsed.
0.7575677377599462 0.26556038721774916 0.26976488827784456 0.887757986734683 0.30298113085362793 0.6462627232106811 0.040763166428201214 0.2204700671486813 0.6961713195243869 0.1401515119552493 0.6122116869605355 0.16699432152455876 0.6739887166566367 0.2529839355467667 0.2273660244940476 0.4681865657588861 0.7820391875100132 0.18207434476537354 0.6828727811314783 0.07238642479814542 0.5627301448198244 0.6899473000886821 0.3889083573600629 0.7458707748767349 0.0663861839448331 1.1031387958198082 0.31491275296109367 0.3314606764535562 0.6161705953210392 0.41546110116237567 0.38286150116336826 3.390172835330156 0.26808018799472066 0.4977830455591546 0.6251803699231051 0.6564230743447576 0.16165154228136608 0.562094806643602 0.2801116328565903 0.009770327029845972 0.035136514889983324 1.1477621088887813 0.27423256745785285 0.6147476901735027 0.226235322456757 0.7820293595515457 0.2785367641977524 0.49518423932556976 0.29983800189089677 0.579835009179672 0.24145774753174473 0.7762028119563629 0.3030182839667054 0.34110053144876457 0.4950583795918869 0.12313960718217588 0.400599678360907 0.7047340874108771 0.42252962420515155 0.9865605230936163 0.43505690630040683 0.20729198145836933 0.5530223883338016 0.5344830141349325
\ No newline at end of file
To use this installation, you need :
- Python 3.6 minimum
- Pure Data 0.49 minimum
To install Python3 dependencies (tensorflow, keras and numpy), you can create a virtual env :
$ cd spirit_essence_listening
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
To install Pd dependencies, install Gem and Zexy.
To start the installation :
You need to put your own picture filename as value for FILENAME_INPUT env variable.
Open a terminal :
$ cd spirit_essence_listening
$ FILENAME_INPUT="IMG_20181203_104343_BURST1.jpg" python3 spirit_essence_listening_session.py
When the Gem window is created, you can use the keyboard :
- 's' to start to play the sound
- 'q' to close the Gem window
At the end of the perforance, press the 'q' key to close the Gem window and click on the 'stop' message in the 'main.pd' window.
A .wav sound file will be save in the /tmp directory with a name like 145612.wav.
RYBN
#N canvas 0 96 904 446 10;
#X obj 117 49 inlet;
#X obj 117 256 phasor~;
#X obj 117 234 r phasor_freq;
#X obj 117 279 *~ 784;
#X obj 117 355 throw~ output;
#X obj 117 193 array set \$1-sound;
#X obj 117 302 tabread4~ \$1-sound;
#X obj 542 82 array define \$1-sound 784;
#X obj 117 72 t l b;
#X obj 144 99 v image_size;
#X obj 144 162 array size \$1-sound;
#X obj 144 122 t f f;
#X connect 0 0 8 0;
#X connect 1 0 3 0;
#X connect 2 0 1 0;
#X connect 3 0 6 0;
#X connect 6 0 4 0;
#X connect 8 0 5 0;
#X connect 8 1 9 0;
#X connect 9 0 11 0;
#X connect 11 0 10 0;
#X connect 11 1 3 1;
This diff is collapsed.
#N canvas 525 228 524 355 10;
#X declare -lib Gem -path Gem;
#X declare -lib zexy -path zexy;
#X obj 43 117 r filename;
#X obj 43 145 symbol;
#X obj 43 170 s2l -;
#N canvas 736 424 675 516 select_photograph_and_dispay_it 0;
#X obj 182 27 inlet;
#X msg 182 55 open \$1;
#X obj 100 27 gemhead;
#X obj 100 84 pix_image;
#X obj 100 327 pix_texture;
#X obj 100 354 rectangle 7.11111 4;
#X obj 100 107 pix_info ----------;
#X obj 115 130 /;
#X floatatom 115 153 5 0 0 0 - - -;
#X obj 115 175 moses 1;
#X obj 115 232 t f b;
#X obj 100 297 translateXYZ 4 0 0;
#X obj 185 232 t b f;
#X msg 185 254 3.05;
#X obj 185 207 * 3.05;
#X msg 142 254 3.95;
#X obj 115 208 * 3.95;
#X obj 359 433 pix_texture;
#X obj 359 27 gemhead 55;
#X obj 359 410 pix_set 224 224;
#X obj 495 330 text get images;
#X msg 367 388 GREY;
#X obj 367 364 loadbang;
#X msg 359 103 64;
#X obj 359 126 until;
#X obj 359 149 t b b;
#X obj 386 173 f;
#X obj 416 173 + 1;
#X msg 401 144 0;
#X obj 359 80 t b a b;
#X obj 359 327 translateXYZ;
#X obj 386 196 t f f f;
#X obj 359 297 separator m;
#X obj 359 271 gemlist;
#X obj 405 219 div 8;
#X obj 386 243 mod 8;
#X obj 359 50 translateXYZ -6.6 -3.5 0;
#X obj 359 456 square 0.45;
#X connect 0 0 1 0;
#X connect 1 0 3 0;
#X connect 2 0 3 0;
#X connect 3 0 6 0;
#X connect 4 0 5 0;
#X connect 6 0 11 0;
#X connect 6 1 7 0;
#X connect 6 2 7 1;
#X connect 7 0 8 0;
#X connect 8 0 9 0;
#X connect 9 0 16 0;
#X connect 9 1 14 0;
#X connect 10 0 5 1;
#X connect 10 1 15 0;
#X connect 11 0 4 0;
#X connect 12 0 13 0;
#X connect 12 1 5 2;
#X connect 13 0 5 1;
#X connect 14 0 12 0;
#X connect 15 0 5 2;
#X connect 16 0 10 0;
#X connect 17 0 37 0;
#X connect 18 0 36 0;
#X connect 19 0 17 0;
#X connect 20 0 19 1;
#X connect 21 0 19 0;
#X connect 22 0 21 0;
#X connect 23 0 24 0;
#X connect 24 0 25 0;
#X connect 25 0 33 0;
#X connect 25 1 26 0;
#X connect 26 0 27 0;
#X connect 26 0 31 0;
#X connect 27 0 26 1;
#X connect 28 0 26 1;
#X connect 29 0 23 0;
#X connect 29 1 33 1;
#X connect 29 2 28 0;
#X connect 30 0 19 0;
#X connect 31 0 35 0;
#X connect 31 1 34 0;
#X connect 31 2 20 0;
#X connect 32 0 30 0;
#X connect 33 0 32 0;
#X connect 34 0 30 2;
#X connect 35 0 30 1;
#X connect 36 0 29 0;
#X restore 100 220 pd select_photograph_and_dispay_it;
#X obj 43 27 declare -lib Gem -path Gem;
#X obj 43 276 text define images;
#X msg 43 248 read -c \$1;
#X obj 43 196 unpack s s;
#N canvas 0 96 598 344 Gem_window 0;
#X obj 91 130 gemkeyname;
#X msg 148 230 destroy;
#X obj 171 130 keyname;
#X obj 60 41 loadbang;
#X msg 80 68 dimen 1280 720 \, border 1 \, offset 0 0 \, create \,
1;
#X obj 60 280 gemwin 20;
#X msg 60 93 dimen 1920 1080 \, border 0 \, offset 0 0 \, cursor 0
\, create \, 1;
#X msg 265 175 connect 127.0.0.1 9999;
#X obj 433 212 sel 0;
#X msg 167 195 send bang;
#X obj 265 231 netsend;
#X obj 433 186 f;
#X obj 433 154 metro 1000;
#X obj 433 128 loadbang;
#X obj 148 167 sel q s;
#X obj 433 235 delay 500;
#X connect 0 1 14 0;
#X connect 1 0 5 0;
#X connect 2 1 14 0;
#X connect 3 0 6 0;
#X connect 4 0 5 0;
#X connect 6 0 5 0;
#X connect 7 0 10 0;
#X connect 8 0 15 0;
#X connect 9 0 10 0;
#X connect 10 0 11 1;
#X connect 11 0 8 0;
#X connect 12 0 11 0;
#X connect 13 0 12 0;
#X connect 14 0 1 0;
#X connect 14 1 9 0;
#X connect 15 0 7 0;
#X restore 43 77 pd Gem_window;
#X text 184 101 Press 'q' to destroy the Gem window. Press 's' to start
sound., f 37;
#X obj 43 50 declare -lib zexy -path zexy;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 7 0;
#X connect 6 0 5 0;
#X connect 7 0 6 0;
#X connect 7 1 3 0;
Keras==2.3.1
numpy==1.19.5
Pillow==6.2.2
tensorflow==2.2.2
import os
import shlex
import subprocess
import numpy
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import VGG16
from keras import models
FILENAME_INPUT = os.environ.get('FILENAME_INPUT')
def get_output_layer():
# load the model
model = VGG16()
model.summary()
# load an image from file
image = load_img(FILENAME_INPUT, target_size=(224, 224))
# convert the image pixels to a numpy array
image = img_to_array(image)
image = numpy.expand_dims(image, axis=0)
image /= 255.
layer_outputs = [layer.output for layer in model.layers[1:18]]
activation_model = models.Model(inputs=model.input, outputs=layer_outputs)
activations = activation_model.predict(image)
layer = 0 # we choose the first layer
layer_activation = activations[layer]
print(layer_activation.shape)
ide, width, height, channels = layer_activation.shape
print(channels)
string = ''
l_average = []
for channel in range(channels):
average = numpy.average(layer_activation[0, :, :, channel].tolist())
l_average.append(average)
l_list_of_pixels_line = []
for line in layer_activation[0, :, :, channel].tolist():
l_list_of_pixels_line.extend(line)
string += ' '.join(map(str, l_list_of_pixels_line))
string += '\n'
filename = '{}_channels_of_layer_{}'.format(channels, layer)
# save data in a file for Pd
with open(filename, 'w') as f:
f.write(string)
with open(filename + '_average', 'w') as f:
f.write(' '.join(map(str, l_average)))
return filename, width, height
def start_pd(filename, width, height):
# cmd_pd = 'pd -open main.pd -send ";filename {}-{}-{}-{}"'.format(filename, width, height, FILENAME_INPUT)
cmd_pd = 'pd -open main.pd -audiooutdev 1 -outchannels 2 -send ";filename {}-{}-{}-{}"'.format(filename, width, height, FILENAME_INPUT)
cmd_pd2 = 'pd -open main_gem.pd -send ";filename {}-{}"'.format(filename, FILENAME_INPUT)
sub_pd = subprocess.Popen(shlex.split(cmd_pd))
sub_pd2 = subprocess.Popen(shlex.split(cmd_pd2))
sub_pd.wait()
sub_pd2.wait()
def main():
filename, width, height = get_output_layer()
start_pd(filename, width, height)
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment