前提・実現したいこと
前回の質問同様,オープンソースのニューラルネットワークのコード(Variational Integrator Networks)を用いて,この論文で行われているideal single pendulumの学習を再現したいと思っています.
環境構築をなんとか済ませ,実際にコードを回すために
python run_exp.py experiments VIN_VV pendulum pixels 1 60 1
を実行したところ,以下のようにFigureCanvasMacでAttributeErrorがでてしまいました.
AttributeError: 'FigureCanvasMac' object has no attribute 'renderer' In call to configurable 'create_dataset' (<function create_dataset at 0x13f1a6ae8>) In call to configurable 'main' (<function main at 0x13f1a6d90>)
発生している問題・エラーメッセージ
(VIN0503-Python3.6) ユーザー名@ユーザー名s-MacBook-Pro Variational_Integrator_Networks % python run_exp.py experiments VIN_VV pendulum pixels 1 60 1 2021-05-04 01:24:09.657712: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2021-05-04 01:24:09.694326: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7ffec8f05b90 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2021-05-04 01:24:09.694348: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version /Users/ユーザー名/VIN0503-Python3.6/lib/python3.6/site-packages/numpy/core/_asarray.py:136: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray return array(a, dtype, copy=False, order=order, subok=True) Traceback (most recent call last): File "run_exp.py", line 241, in <module> main(root_dir, model_name, system_name, observations, num_train_traj, num_train_steps, seed) File "/Users/ユーザー名/VIN0503-Python3.6/lib/python3.6/site-packages/gin/config.py", line 1078, in gin_wrapper utils.augment_exception_message_and_reraise(e, err_str) File "/Users/ユーザー名/VIN0503-Python3.6/lib/python3.6/site-packages/gin/utils.py", line 49, in augment_exception_message_and_reraise six.raise_from(proxy.with_traceback(exception.__traceback__), None) File "<string>", line 3, in raise_from File "/Users/ユーザー名/VIN0503-Python3.6/lib/python3.6/site-packages/gin/config.py", line 1055, in gin_wrapper return fn(*new_args, **new_kwargs) File "run_exp.py", line 200, in main build_utils.create_dataset(system, model.horizon, num_train_traj, num_train_steps) File "/Users/ユーザー名/VIN0503-Python3.6/lib/python3.6/site-packages/gin/config.py", line 1078, in gin_wrapper utils.augment_exception_message_and_reraise(e, err_str) File "/Users/ユーザー名/VIN0503-Python3.6/lib/python3.6/site-packages/gin/utils.py", line 49, in augment_exception_message_and_reraise six.raise_from(proxy.with_traceback(exception.__traceback__), None) File "<string>", line 3, in raise_from File "/Users/ユーザー名/VIN0503-Python3.6/lib/python3.6/site-packages/gin/config.py", line 1055, in gin_wrapper return fn(*new_args, **new_kwargs) File "/Users/ユーザー名/VIN0503-Python3.6/Variational_Integrator_Networks/build_utils.py", line 119, in create_dataset obs, states = system.run(num_traj, num_steps, step_size) File "/Users/ユーザー名/VIN0503-Python3.6/Variational_Integrator_Networks/systems.py", line 73, in run return self._state_to_observations(qqd), qqd File "/Users/ユーザー名/VIN0503-Python3.6/Variational_Integrator_Networks/systems.py", line 33, in _state_to_observations return self._state_to_pixels(qqdot) File "/Users/ユーザー名/VIN0503-Python3.6/Variational_Integrator_Networks/systems.py", line 115, in _state_to_pixels y_t = np.array(f.canvas.renderer.buffer_rgba())[:, :, :1] AttributeError: 'FigureCanvasMac' object has no attribute 'renderer' In call to configurable 'create_dataset' (<function create_dataset at 0x13f1a6ae8>) In call to configurable 'main' (<function main at 0x13f1a6d90>)
該当のソースコード
Python
1systems.py のファイル内容は以下の通りになります.文字数の関係から一部のみの抜粋となります. 2 3import numpy as np 4from scipy.integrate import ode 5 6import plot_utils 7import matplotlib.pyplot as plt 8 9 10class System(object): 11 12 def __init__(self, observations, seed, **kwargs): 13 14 self.observations = observations 15 self.RNG = np.random.RandomState(seed) 16 self.system_param = kwargs 17 self._init_system(**kwargs) 18 19 def _init_system(self, **kwargs): 20 raise NotImplementedError() 21 22 def _random_init_state(self): 23 raise NotImplementedError() 24 25 def _ODE(self, t, y): 26 raise NotImplementedError() 27 28 def _state_to_observations(self, qqdot): 29 if self.observations == "observed": 30 return qqdot 31 elif self.observations == "noisy": 32 noise = self.RNG.randn(*qqdot.shape) * self.system_param["noise_std"] 33 return qqdot + noise 34 elif self.observations == "pixels": 35 return self._state_to_pixels(qqdot) 36 37 def _state_to_pixels(self, qqdot): 38 raise NotImplementedError() 39 40 def compute_energy(self, qqdot): 41 raise NotImplementedError() 42 43 def integrate_ODE(self, num_steps, step_size, y0=None, rtol=1e-12): 44 45 T = num_steps * step_size 46 t = np.linspace(0.0, T, num_steps) 47 48 if y0 is None: 49 y0 = self._random_init_state() 50 51 solver = ode(self._ODE).set_integrator('dop853', rtol=rtol) 52 sol = np.empty((len(t), 2)) 53 sol[0] = y0 54 solver.set_initial_value(y0) 55 k = 1 56 while solver.successful() and solver.t < T: 57 solver.integrate(t[k]) 58 sol[k] = solver.y 59 k += 1 60 61 return sol 62 63 def run(self, num_traj, num_steps, step_size, y0=None): 64 65 qqd = [] 66 for n in range(num_traj): 67 if y0 is not None: 68 y0_n = y0[n] 69 else: 70 y0_n = None 71 qqd_n = self.integrate_ODE(num_steps, step_size, y0=y0_n) 72 qqd.append(qqd_n[None]) 73 qqd = np.vstack(qqd) 74 75 return self._state_to_observations(qqd), qqd 76 77class Pendulum(System): 78 79 def _init_system(self, mass=1.0, length=1.0, g=9.82, friction=0., **kwargs): 80 81 def pendulum_ODE(t, y): 82 q, qdot = y 83 dydt = [qdot, -friction*qdot - (g/length)*np.sin(q)] 84 return dydt 85 86 self._ODE = pendulum_ODE 87 88 def _random_init_state(self): 89 90 sign = [-1., 1.] 91 q0 = np.pi - self.RNG.uniform(low=0.1, high=1./2.*np.pi) 92 q0 = self.RNG.choice(sign)*q0 93 qdot0 = self.RNG.uniform(low=-1., high=1.) 94 y0 = np.hstack([q0, qdot0]) 95 return y0 96 97 def _state_to_pixels(self, qqdot): 98 99 length = self.system_param["length"] 100 q, qdot = np.split(qqdot, 2, axis=-1) 101 x = length * np.sin(q) 102 y = -length * np.cos(q) 103 104 f, ax = plt.subplots(figsize=(1, 1), dpi=28) 105 f_lim = length+0.2 106 107 ys = [] 108 for traj in range(q.shape[0]): 109 y_traj = [] 110 for t in range(q.shape[1]): 111 plt.cla() 112 ax.set_xlim(-f_lim, f_lim) 113 ax.set_ylim(-f_lim, f_lim) 114 ax.plot([0, x[traj, t]],[0, y[traj, t]], linewidth=12, color="black") 115 ax.axis('off') 116 f.canvas.draw() 117 y_t = np.array(f.canvas.renderer.buffer_rgba())[:, :, :1] 118 y_t[y_t > 0] = 255 119 y_t[y_t == 0] = 1. 120 y_t[y_t == 255] = 0. 121 y_traj.append(np.float32(y_t[None])) 122 y_traj = np.vstack(y_traj) 123 ys.append(y_traj[None]) 124 ys = np.vstack(ys) 125 ys = ys.reshape(*ys.shape[:2], 784) 126 127 return ys 128 129 def compute_energy(self, qqdot): 130 131 mass = self.system_param["mass"] 132 length = self.system_param["length"] 133 g = self.system_param["g"] 134 135 q, qdot = np.split(qqdot, 2, axis=-1) 136 K = 0.5 * mass * (length**2) * qdot**2 137 U = -mass * g * length * np.cos(q) 138 E = K + U 139 140 return E
試したこと
元々Python3.7.5でやっていたのですが,
NotImplementedError: Cannot convert a symbolic Tensor (sequential_2_1/lstm/strided_slice:0) to a numpy array. In call to configurable 'create_model' (<function create_model at 0x134c40a70>) In call to configurable 'main' (<function main at 0x1366c3dd0>)
というエラーが出たため調べたところ,tensorflowのgithubにて同様のエラーに関するイシューを発見し,そこでPython3.6でやるといいと書いてあったため,Pythonのバージョンを3.7.5から3.6.0に下げました.
また,AttributeErrorの方のエラー文でも検索してみたところ,こちらも同様のエラーに関するイシューを発見しました.こちらで言及されている通り,
python
1import matplotlib; matplotlib.use('agg')
を,systems.pyの1行目に追記した上で再度実行しましたが,同様のエラーが出てしまいました.
補足情報(FW/ツールのバージョンなど)
0S: MacOS Catalina ver10.15.7
仮想環境名:VIN0503-Python3.6
pip==21.0.1
Pytho==3.6.0
jax==0.1.60
numpy==1.19.5
matplotlib==3.2.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/05/04 05:39
退会済みユーザー
2021/05/04 05:48
2021/05/04 07:18