
Recherche avancée
Autres articles (78)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Le profil des utilisateurs
12 avril 2011, parChaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...) -
Configurer la prise en compte des langues
15 novembre 2010, parAccéder à la configuration et ajouter des langues prises en compte
Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)
Sur d’autres sites (7482)
-
Python : ani.save very slow. Any alternatives to create videos ?
14 novembre 2023, par CzesklebaIm doing some simple diffusion calculations. I save 2 matrices to 2 datasets every so many steps (every 2s or so) to a single .h5 file. After that I then load the file in another script, create some figures (2 subplots etc., see/run code - i know could be prettier). Then I use matplotlib.animation to make the animation. In the code below, in the very last lines, I then run the ani.save command from matplotlib.


And that's where the problem is. The animation is created within 2 seconds, even for my longer animations (14.755 frames, done in under 2s at 8284 it/s) but after that, ani.save in line 144 takes forever (it didn't finish over night). It reserves/uses about 10gb of my RAM constantly but seemingly takes forever. If you run the code below be sure to set the frames_to_do (line 20) to something like 30 or 60 to see that it does in fact save an mp4 for shorter videos. You can set it higher to see how fast the time to save stuff increases to something unreasonable.


I've been fiddling this for 2 days now and I cant figure it out. I guess my question is : Is there any way to create the video in a reasonable time like this ? Or do I need something other than animation ?


You should be able to just run the code. Ill provide a diffusion_array.h5 with 140 frames so you dont have to create a dummy file, if I can figure out how to upload something like this safely. (The results are with dummy numbers for now, diffusion coefficients etc. are not right yet.)
I used dropbox. Not sure if thats allowed, if not I'll delete the link and uhh PM me or something ?




Here is the code :


import h5py
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib.animation import FuncAnimation
from tqdm import tqdm
import numpy as np


# saving the .mp4 after tho takes forever

# Create an empty figure and axis
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 9), dpi=96)

# Load all saved arrays into a list
file_name = 'diffusion_array.h5'
loaded_u_arrays = []
loaded_h_arrays = []
frames_to_do = 14755 # for now like this, use # version once the slow mp4 convert is cleared up

# with h5py.File(file_name, 'r') as hf:
# for key in hf.keys():
# if key.startswith('u_snapshot_'):
# loaded_u_arrays.append(hf[key][:])
# elif key.startswith('h_snapshot_'):
# loaded_h_arrays.append(hf[key][:])

with h5py.File(file_name, 'r') as hf:
 for i in range(frames_to_do):
 target_key1 = f'u_snapshot_{i:05d}'
 target_key2 = f'h_snapshot_{i:05d}'
 if target_key1 in hf:
 loaded_u_arrays.append(hf[target_key1][:])
 else:
 print(f'Dataset u for time step {i} not found in the file.')
 if target_key2 in hf:
 loaded_h_arrays.append(hf[target_key2][:])
 else:
 print(f'Dataset h for time step {i} not found in the file.')

# Create "empty" imshow objects
# First one
norm1 = mcolors.Normalize(vmin=140, vmax=400)
cmap1 = plt.get_cmap('hot')
cmap1.set_under('0.85')
im1 = ax1.imshow(loaded_u_arrays[0], cmap=cmap1, norm=norm1)
ax1.set_title('Diffusion Heatmap')
ax1.set_xlabel('X')
ax1.set_ylabel('Y')
cbar_ax = fig.add_axes([0.05, 0.15, 0.03, 0.7])
cbar_ax.set_xlabel('$T$ / K', labelpad=20)
fig.colorbar(im1, cax=cbar_ax)


# Second one
ax2 = plt.subplot(1, 2, 2)
norm2 = mcolors.Normalize(vmin=-0.1, vmax=5)
cmap2 = plt.get_cmap('viridis')
cmap2.set_under('0.85')
im2 = ax2.imshow(loaded_h_arrays[0], cmap=cmap2, norm=norm2)
ax2.set_title('Diffusion Hydrogen')
ax2.set_xlabel('X')
ax2.set_ylabel('Y')
cbar_ax = fig.add_axes([0.9, 0.15, 0.03, 0.7])
cbar_ax.set_xlabel('HD in ml/100g', labelpad=20)
fig.colorbar(im2, cax=cbar_ax)

# General
fig.subplots_adjust(right=0.85)
time_text = ax2.text(-15, 0.80, f'Time: {0} s', transform=plt.gca().transAxes, color='black', fontsize=20)

# Annotations
# Heat 1
marker_style = dict(marker='o', markersize=6, markerfacecolor='black', markeredgecolor='black')
ax1.scatter(*[10, 40], s=marker_style['markersize'], c=marker_style['markerfacecolor'],
 edgecolors=marker_style['markeredgecolor'])
ann_heat1 = ax1.annotate(f'Temp: {loaded_u_arrays[0][40, 10]:.0f}', xy=[10, 40], xycoords='data',
 xytext=([10, 40][0], [10, 40][1] + 48), textcoords='data',
 arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.3"), fontsize=12, color='black')
# Heat 2
ax1.scatter(*[140, 85], s=marker_style['markersize'], c=marker_style['markerfacecolor'],
 edgecolors=marker_style['markeredgecolor'])
ann_heat2 = ax1.annotate(f'Temp: {loaded_u_arrays[0][85, 140]:.0f}', xy=[140, 85], xycoords='data',
 xytext=([140, 85][0] + 55, [140, 85][1] + 3), textcoords='data',
 arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.3"), fontsize=12, color='black')

# Diffusion 1
marker_style = dict(marker='o', markersize=6, markerfacecolor='black', markeredgecolor='black')
ax2.scatter(*[10, 40], s=marker_style['markersize'], c=marker_style['markerfacecolor'],
 edgecolors=marker_style['markeredgecolor'])
ann_diff1 = ax2.annotate(f'HD: {loaded_h_arrays[0][40, 10]:.0f}', xy=[10, 40], xycoords='data',
 xytext=([10, 40][0], [10, 40][1] + 48), textcoords='data',
 arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.3"), fontsize=12, color='black')
# Diffusion 2
ax2.scatter(*[140, 85], s=marker_style['markersize'], c=marker_style['markerfacecolor'],
 edgecolors=marker_style['markeredgecolor'])
ann_diff2 = ax2.annotate(f'HD: {loaded_h_arrays[0][85, 140]:.0f}', xy=[140, 85], xycoords='data',
 xytext=([140, 85][0] + 55, [140, 85][1] + 3), textcoords='data',
 arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.3"), fontsize=12, color='black')


# Function to update the animation
def update(frame, *args):
 loaded_u_array, loaded_h_array = args

 s_per_frame = 2 # during weld/cooling you save a state every 2s
 frames_to_room_temp = 7803 # that means this many frames need to be animated
 dt_big = 87 # during "just diffusion" you save every 10 frame but 87s pass in those

 # Update the time step shown
 if frame <= frames_to_room_temp:
 im1.set_data(loaded_u_array[frame])
 im2.set_data(loaded_h_array[frame])
 time_text.set_text(f'Time: {frame * s_per_frame} s')

 else:
 im1.set_data(loaded_u_array[frame])
 im2.set_data(loaded_h_array[frame])
 calc_time = int(((2 * frames_to_room_temp) + (frame - frames_to_room_temp) * 87) / 3600)
 time_text.set_text(f'Time: {calc_time} s')

 # Annotate some points
 ann_heat1.set_text(f'Temp: {loaded_u_arrays[frame][40, 10]:.0f}')
 ann_heat2.set_text(f'Temp: {loaded_u_arrays[frame][85, 140]:.0f}')
 ann_diff1.set_text(f'HD: {loaded_h_arrays[frame][40, 10]:.0f}')
 ann_diff2.set_text(f'HD: {loaded_h_arrays[frame][85, 140]:.0f}')

 return im1, im2 # Return the updated artists


# Create the animation without displaying it
ani = FuncAnimation(fig, update, frames=frames_to_do, repeat=False, blit=True, interval=1,
 fargs=(loaded_u_arrays, loaded_h_arrays)) # frames=len(loaded_u_arrays)

# Create the progress bar with tqdm
with tqdm(total=frames_to_do, desc='Creating Animation') as pbar: # total=len(loaded_u_arrays)
 for i in range(frames_to_do): # for i in range(len(loaded_u_arrays)):
 update(i, loaded_u_arrays, loaded_h_arrays) # Manually update the frame with both datasets
 pbar.update(1) # Update the progress bar

# Save the animation as a video file (e.g., MP4)
print("Converting to .mp4 now. This may take some time. This is normal, wait for Python to finish this process.")
ani.save('diffusion_animation.mp4', writer='ffmpeg', dpi=96, fps=60)

# Close the figure to prevent it from being displayed
plt.close(fig)




-
What is Audience Segmentation ? The 5 Main Types & Examples
16 novembre 2023, par Erin — Analytics Tips -
arm : vp9 : Add NEON loop filters
14 novembre 2016, par Martin Storsjöarm : vp9 : Add NEON loop filters
This work is sponsored by, and copyright, Google.
The implementation tries to have smart handling of cases
where no pixels need the full filtering for the 8/16 width
filters, skipping both calculation and writeback of the
unmodified pixels in those cases. The actual effect of this
is hard to test with checkasm though, since it tests the
full filtering, and the benefit depends on how many filtered
blocks use the shortcut.Examples of relative speedup compared to the C version, from checkasm :
Cortex A7 A8 A9 A53
vp9_loop_filter_h_4_8_neon : 2.72 2.68 1.78 3.15
vp9_loop_filter_h_8_8_neon : 2.36 2.38 1.70 2.91
vp9_loop_filter_h_16_8_neon : 1.80 1.89 1.45 2.01
vp9_loop_filter_h_16_16_neon : 2.81 2.78 2.18 3.16
vp9_loop_filter_mix2_h_44_16_neon : 2.65 2.67 1.93 3.05
vp9_loop_filter_mix2_h_48_16_neon : 2.46 2.38 1.81 2.85
vp9_loop_filter_mix2_h_84_16_neon : 2.50 2.41 1.73 2.85
vp9_loop_filter_mix2_h_88_16_neon : 2.77 2.66 1.96 3.23
vp9_loop_filter_mix2_v_44_16_neon : 4.28 4.46 3.22 5.70
vp9_loop_filter_mix2_v_48_16_neon : 3.92 4.00 3.03 5.19
vp9_loop_filter_mix2_v_84_16_neon : 3.97 4.31 2.98 5.33
vp9_loop_filter_mix2_v_88_16_neon : 3.91 4.19 3.06 5.18
vp9_loop_filter_v_4_8_neon : 4.53 4.47 3.31 6.05
vp9_loop_filter_v_8_8_neon : 3.58 3.99 2.92 5.17
vp9_loop_filter_v_16_8_neon : 3.40 3.50 2.81 4.68
vp9_loop_filter_v_16_16_neon : 4.66 4.41 3.74 6.02The speedup vs C code is around 2-6x. The numbers are quite
inconclusive though, since the checkasm test runs multiple filterings
on top of each other, so later rounds might end up with different
codepaths (different decisions on which filter to apply, based
on input pixel differences). Disabling the early-exit in the asm
doesn’t give a fair comparison either though, since the C code
only does the necessary calcuations for each row.Based on START_TIMER/STOP_TIMER wrapping around a few individual
functions, the speedup vs C code is around 4-9x.This is pretty similar in runtime to the corresponding routines
in libvpx. (This is comparing vpx_lpf_vertical_16_neon,
vpx_lpf_horizontal_edge_8_neon and vpx_lpf_horizontal_edge_16_neon
to vp9_loop_filter_h_16_8_neon, vp9_loop_filter_v_16_8_neon
and vp9_loop_filter_v_16_16_neon - note that the naming of horizonal
and vertical is flipped between the libraries.)In order to have stable, comparable numbers, the early exits in both
asm versions were disabled, forcing the full filtering codepath.Cortex A7 A8 A9 A53
vp9_loop_filter_h_16_8_neon : 597.2 472.0 482.4 415.0
libvpx vpx_lpf_vertical_16_neon : 626.0 464.5 470.7 445.0
vp9_loop_filter_v_16_8_neon : 500.2 422.5 429.7 295.0
libvpx vpx_lpf_horizontal_edge_8_neon : 586.5 414.5 415.6 383.2
vp9_loop_filter_v_16_16_neon : 905.0 784.7 791.5 546.0
libvpx vpx_lpf_horizontal_edge_16_neon : 1060.2 751.7 743.5 685.2Our version is consistently faster on on A7 and A53, marginally slower on
A8, and sometimes faster, sometimes slower on A9 (marginally slower in all
three tests in this particular test run).This is an adapted cherry-pick from libav commit
dd299a2d6d4d1af9528ed35a8131c35946be5973.Signed-off-by : Ronald S. Bultje <rsbultje@gmail.com>