Anaconda hört mit einem langen Programm auf zu arbeiten und schaltet sich aus
Verfasst: Montag 4. Mai 2020, 21:33
Ich habe das Problem, dass ich ein Programm geschrieben habe, das ein Zoom-Video für das Mandelbrot-Set erstellt. Bisher funktioniert das Programm einwandfrei und fehlerfrei.
Mein Problem ist jetzt, dass die Berechnung des Programms mehrere Stunden dauert. Ich habe die Anaconda Power Shell-Eingabeaufforderung verwendet, aber nach ungefähr zwei Stunden gibt es einfach keine Fortschritte. Ich dachte, das liegt an meinem Programm. Aber Anaconda reagiert dann nicht mehr und Sie können mit dem Programm kein Notebook oder ähnliches starten. Man könnte sagen, dass Anaconda nach einer bestimmten Zeit abschaltet und meine Power Shell-Eingabeaufforderung nicht mehr funktioniert und mein Programm nicht fortgesetzt wird.
Ich habe keine Ahnung warum und wäre sehr dankbar für Hilfe.
Mein Problem ist jetzt, dass die Berechnung des Programms mehrere Stunden dauert. Ich habe die Anaconda Power Shell-Eingabeaufforderung verwendet, aber nach ungefähr zwei Stunden gibt es einfach keine Fortschritte. Ich dachte, das liegt an meinem Programm. Aber Anaconda reagiert dann nicht mehr und Sie können mit dem Programm kein Notebook oder ähnliches starten. Man könnte sagen, dass Anaconda nach einer bestimmten Zeit abschaltet und meine Power Shell-Eingabeaufforderung nicht mehr funktioniert und mein Programm nicht fortgesetzt wird.
Ich habe keine Ahnung warum und wäre sehr dankbar für Hilfe.
Code: Alles auswählen
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation, rc
from itertools import cycle
import matplotlib.colors as clr
import matplotlib.animation as animation
import moviepy.editor as mp
import time
import os
import cv2
colorpoints = [(1-(1-q)**4, c) for q, c in zip(np.linspace(0, 1, 20),
cycle(['#ffff88', '#000000', #Standard: #ffff88, #000000, #ffaa00
'#ffaa00',]))]
#http://www.am.uni-duesseldorf.de/de/Links/Tools/farbtabelle.html for RGB-codes
cmap = clr.LinearSegmentedColormap.from_list('mycmap',colorpoints, N=2048)
rc('animation', html='html5')
fig_size = 8
fig = plt.figure(figsize=(fig_size, fig_size), dpi = 100, tight_layout=True)
max_frames = 500
max_zoom = 50000 #max_zoom for these coordinates (0.357535415497125, 0.070571561552046) 1.7592187E13
#can go higher but it is possible that it zooms into a non borderregion region
#but 1.7592187E13 is already a huge zoom-factor
rmin, rmax, imin, imax = -2.5, 1.5, -2, 2
images = []
Writer = animation.writers['ffmpeg']
writer = animation.FFMpegWriter(fps=10, metadata=dict(artist='Lukas Kretschamnn'), bitrate = -1)
def mandelbrot(rmin, rmax, rpoints, imin, imax, ipoints,
max_iterations=1000, infinity_border=10):
image = np.zeros((rpoints, ipoints))
r, i = np.mgrid[rmin:rmax:(rpoints * 1j), imin:imax:(ipoints * 1j)]
c = r + 1j * i
z = np.zeros_like(c)
for k in range(max_iterations):
z = z ** 2 + c
mask = (np.abs(z) > infinity_border) & (image == 0)
image[mask] = k
z[mask] = np.nan
return -image.T
def init():
return plt.gca()
def animate(i):
if i > max_frames: #probieren, ob man //2 weglassen kann um alle Werte richtig ausgedruckt zu bekommen
plt.imshow(images[max_frames - i], cmap='flag')
print(i)
return
r_center, i_center = 0.357535415497125, 0.070571561552046 #Standard: 0.357535415497125, 0.070571561552046
zoom = (i / max_frames) ** 3 * max_zoom + 1
scalefactor = 1 / zoom
rmin_ = (rmin - r_center) * scalefactor + r_center
imin_ = (imin - i_center) * scalefactor + i_center
rmax_ = (rmax - r_center) * scalefactor + r_center
imax_ = (imax - i_center) * scalefactor + i_center
image = mandelbrot(rmin_, rmax_, 1000, imin_, imax_, 1000) #increase rpoints and ipoints for better resolution
plt.axis('off', bbox_inches='tight', pad_inches = 0, tight_layout=True)
plt.imshow(image, cmap=cmap, interpolation='none')
images.append(image)
print("Frame number {} created;".format(i), "next frame: {}".format(i + 1)) #counter starts with zero; so last frame number is max_frames - 1
return plt.gca()
def cut_frames():
cam = cv2.VideoCapture("OUTPUT.mp4")
try:
# create a directory named data
if not os.path.exists('data'):
os.makedirs('data')
# if directory was not created then raise an error
except OSError:
print ('Error: Creating directory of data failed')
# frame
currentframe = 0
while(True):
# reading from frame
ret,frame = cam.read()
if ret:
# if video is still left continue creating images
name = './data/frame' + str(currentframe) + '.jpg'
print ('Creating...' + name)
# writing the extracted images
cv2.imwrite(name, frame)
# increasing counter so that it will
# show how many frames are created
currentframe += 1
else:
break
# Release all space and windows once done
cam.release()
cv2.destroyAllWindows()
t0 = time.time()
print("Video Processing")
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=max_frames, interval=150)
anim.save('OUTPUT.mp4', writer=writer, dpi = 100)
t1 = time.time()
print(" Video Processing Time:", t1 - t0)
t01 = time.time()
print("Next Step: Frame slicing")
cut_frames()
t11 = time.time()
print("Frame sclicing Time:", t11 - t01)