小编Jos*_*hou的帖子

如何在 swift 中的类定义中调用 deinit 方法

我想定义一个方法,当该类中的变量增加到某个值时,该方法可以销毁它所属的实例。我尝试做类似以下的事情:

 var calledTimes = 0 //some other method would update this value

 func shouldDestroySelf(){
   if calledTimes == MAX_TIMES {
     denit
   }
 } 
Run Code Online (Sandbox Code Playgroud)

但我会收到错误消息“Expect '{' for deinitializers”。

班级里有没有自毁的事情?

swift deinit

6
推荐指数
1
解决办法
1万
查看次数

Keras自定义图像预处理函数引发Value Error“输出数组为只读”

我想在 Keras 中使用一些自定义的图像预处理函数和 ImageDataGenerator 函数。例如,我的自定义函数如下所示:

def customizedDataAugmentation(x):
   choice = np.random.choice(np.arange(1, 4), p=[0.3, 0.3, 0.4])
   if choice==1:
       x = exposure.adjust_gamma(x, np.random.uniform(0.5,1.5))
   elif choice==2:
       ix = Image.fromarray(np.uint8(x))
       blurI = ix.filter(ImageFilter.GaussianBlur(np.random.uniform(0.1,2.5)))
       x = np.asanyarray(blurI)
   return x
Run Code Online (Sandbox Code Playgroud)

使用方法如下:

        self.train_datagen = image.ImageDataGenerator(
            rescale=1./255,
            zoom_range=0.15,
            height_shift_range=0.1,
            horizontal_flip=True,
            preprocessing_function=customizedDataAugmentation
        )
Run Code Online (Sandbox Code Playgroud)

但是,当我开始训练时,它跳出这个错误:

Traceback (most recent call last):
File "/home/joseph/miniconda3/envs/py27/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
File "/home/joseph/miniconda3/envs/py27/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
File "/home/joseph/miniconda3/envs/py27/lib/python2.7/site-packages/keras/utils/data_utils.py", line 560, in data_generator_task
    generator_output = next(self._generator)
File "/home/joseph/miniconda3/envs/py27/lib/python2.7/site-packages/keras/preprocessing/image.py", line 1039, in next
    x …
Run Code Online (Sandbox Code Playgroud)

python keras valueerror

0
推荐指数
1
解决办法
3398
查看次数

标签 统计

deinit ×1

keras ×1

python ×1

swift ×1

valueerror ×1