- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试实现 Paper 中描述的“扩张残差网络”在 TensorFlow(s. PyTorch 实现 here )中在 CityScapes Dataset 上训练它并将其用于语义图像分割。不幸的是,我在尝试训练时遇到错误,而且似乎找不到修复方法。
由于这种类型的网络可以看作是 ResNet 的扩展,我使用了官方的 TensorFlow ResNet 模型 (Link) 并通过改变步幅修改了架构,添加了 dilation(作为 tf.layers.conv2d 中的参数)函数)并去除残留连接。
为了训练这个网络,我想使用与 TensorFlow ResNet 模型相同的方法:tf.estimator 结合 input_fn(可以在本文末尾找到)。
现在,当我想使用 CityScapes 数据集训练这个网络时,出现以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-19-263240bbee7e> in <module>()
----> 1 main()
<ipython-input-16-b57cd9b52bc7> in main()
27 print('Starting a training cycle.')
28 drn_classifier.train(
---> 29 input_fn=lambda: input_fn(True, _BATCH_SIZE, _EPOCHS_PER_EVAL),hooks=[logging_hook])
30
31 print(2)
~\Anaconda3\envs\master-thesis\lib\site-packages\tensorflow\python\estimator\estimator.py in train(self, input_fn, hooks, steps, max_steps, saving_listeners)
300
301 saving_listeners = _check_listeners_type(saving_listeners)
--> 302 loss = self._train_model(input_fn, hooks, saving_listeners)
303 logging.info('Loss for final step: %s.', loss)
304 return self
~\Anaconda3\envs\master-thesis\lib\site-packages\tensorflow\python\estimator\estimator.py in _train_model(self, input_fn, hooks, saving_listeners)
709 with ops.control_dependencies([global_step_read_tensor]):
710 estimator_spec = self._call_model_fn(
--> 711 features, labels, model_fn_lib.ModeKeys.TRAIN, self.config)
712 # Check if the user created a loss summary, and add one if they didn't.
713 # We assume here that the summary is called 'loss'. If it is not, we will
~\Anaconda3\envs\master-thesis\lib\site-packages\tensorflow\python\estimator\estimator.py in _call_model_fn(self, features, labels, mode, config)
692 if 'config' in model_fn_args:
693 kwargs['config'] = config
--> 694 model_fn_results = self._model_fn(features=features, **kwargs)
695
696 if not isinstance(model_fn_results, model_fn_lib.EstimatorSpec):
<ipython-input-15-797249462151> in drn_model_fn(features, labels, mode, params)
7 params['arch'], params['size'], _LABEL_CLASSES, params['data_format'])
8 print(4)
----> 9 logits = network(inputs=features, is_training=(mode == tf.estimator.ModeKeys.TRAIN))
10 print(12)
11 predictions = {
\Code\Semantic Image Segmentation\drn.py in model(inputs, is_training)
255 print(16)
256 inputs = conv2d_fixed_padding(
--> 257 inputs=inputs, filters=16, kernel_size=7, strides=2,
258 data_format=data_format,dilation_rate=1)
259 print(17)
\Code\Semantic Image Segmentation\drn.py in conv2d_fixed_padding(inputs, filters, kernel_size, strides, data_format, dilation_rate)
90 kernel_initializer=tf.variance_scaling_initializer(),
91 data_format=data_format,
---> 92 dilation_rate=dilation_rate)
93
94
~\Anaconda3\envs\master-thesis\lib\site-packages\tensorflow\python\layers\convolutional.py in conv2d(inputs, filters, kernel_size, strides, padding, data_format, dilation_rate, activation, use_bias, kernel_initializer, bias_initializer, kernel_regularizer, bias_regularizer, activity_regularizer, kernel_constraint, bias_constraint, trainable, name, reuse)
606 _reuse=reuse,
607 _scope=name)
--> 608 return layer.apply(inputs)
609
610
~\Anaconda3\envs\master-thesis\lib\site-packages\tensorflow\python\layers\base.py in apply(self, inputs, *args, **kwargs)
669 Output tensor(s).
670 """
--> 671 return self.__call__(inputs, *args, **kwargs)
672
673 def _add_inbound_node(self,
~\Anaconda3\envs\master-thesis\lib\site-packages\tensorflow\python\layers\base.py in __call__(self, inputs, *args, **kwargs)
557 input_shapes = [x.get_shape() for x in input_list]
558 if len(input_shapes) == 1:
--> 559 self.build(input_shapes[0])
560 else:
561 self.build(input_shapes)
~\Anaconda3\envs\master-thesis\lib\site-packages\tensorflow\python\layers\convolutional.py in build(self, input_shape)
130 channel_axis = -1
131 if input_shape[channel_axis].value is None:
--> 132 raise ValueError('The channel dimension of the inputs '
133 'should be defined. Found `None`.')
134 input_dim = input_shape[channel_axis].value
ValueError: The channel dimension of the inputs should be defined. Found `None`.
我已经在网上搜索了这个错误,但只找到了与 Keras 相关的帖子,当时后端未正确初始化(s. this)。
如果有人能指出我寻找错误的方向,我会很高兴。
这是我的 input_fn:
def input_fn(is_training, batch_size, num_epochs=1):
"""Input function which provides batches for train or eval."""
# Get list of paths belonging to training images and corresponding label images
filename_list = filenames(is_training)
filenames_train = []
filenames_labels = []
for i in range(len(filename_list)):
filenames_train.append(train_dataset_dir+filename_list[i])
filenames_labels.append(gt_dataset_dir+filename_list[i])
filenames_train = tf.convert_to_tensor(tf.constant(filenames_train, dtype=tf.string))
filenames_labels = tf.convert_to_tensor(tf.constant(filenames_labels, dtype=tf.string))
dataset = tf.data.Dataset.from_tensor_slices((filenames_train,filenames_labels))
if is_training:
dataset = dataset.shuffle(buffer_size=_FILE_SHUFFLE_BUFFER)
dataset = dataset.map(image_parser)
dataset = dataset.prefetch(batch_size)
if is_training:
# When choosing shuffle buffer sizes, larger sizes result in better
# randomness, while smaller sizes have better performance.
dataset = dataset.shuffle(buffer_size=_SHUFFLE_BUFFER)
# We call repeat after shuffling, rather than before, to prevent separate
# epochs from blending together.
dataset = dataset.repeat(num_epochs)
dataset = dataset.batch(batch_size)
iterator = dataset.make_one_shot_iterator()
images, labels = iterator.get_next()
return images, labels
这是 input_fn 中使用的 image_parser 函数:
def image_parser(filename, label):
image_string = tf.read_file(filename)
image_decoded = tf.image.decode_image(image_string,_NUM_CHANNELS)
image_decoded = tf.image.convert_image_dtype(image_decoded, dtype=tf.float32)
label_string = tf.read_file(label)
label_decoded = tf.image.decode_image(label)
return image_decoded, tf.one_hot(label_decoded, _LABEL_CLASSES)
最佳答案
在 tf.read_file
之后试试这个:
image_decoded = tf.image.decode_image(image_string, channels=3)
image_decoded.set_shape([None, None, 3])
关于python - TensorFlow ValueError : The channel dimension of the inputs should be defined. 发现 `None`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48264676/
我正在尝试添加 ace editor到我的应用程序。我从 github 下载它,将“ace/lib/ace”目录放到我的应用程序目录中,包括: " 在我的正文标签中: editor = ace.edi
如果有人能介绍一下 TypeScript 1.8 模块,我将不胜感激。 我有 SomeClass.ts 文件: export class SomeClass { } 然后,在我的 app.ts 中导入
今天,当我阅读php内核代码时,在目录:php5.3/Zend/Zend.h中,有一行代码让我很困惑。 代码如下: /* overloaded elements data types */ #defi
今天看php的内核代码,在php5.3/Zend/Zend.h目录下,有一行代码搞得我一头雾水。 代码如下: /* overloaded elements data types */ #define
我有一个相当大的项目,我试图将所有 JS 文件连接到一个文件中。我已经能够做到这一点,但我在实际将这两个文件实现到代码中时遇到了麻烦。 我的 Gruntfile 有一个执行串联的任务: require
1在以下示例中似乎没有必要(并且可能具有误导性),但是在用于检查 #ifdef 时我已经多次看到这种情况s: #ifndef __NEWLIB_H__ #define __NEWLIB_H__ 1 使
感谢您提供的任何帮助。我有一个 Grails 项目,我正在尝试将 Karma 安装到其中。但是,当我运行时 ./gradlew 构建 我收到以下错误: [x-10-105-56-234]SENG519
我从 Frontend Developer Interview Coding Questions 得到了这个问题.为什么下面的代码片段会打印它打印的内容?我最初认为它会抛出一个 ReferenceEr
之前的问题描述有歧义,所以我在下面修改了一些东西。谢谢。 我想像这样实现一些宏: #define AddVariable(x) \ #define x (++counter) class Ba
我知道我正试图朝自己的腿开枪 ;) 但是,它可以让我使其余(大量)代码更小且更易读。 有什么技巧可以在另一个预处理器宏中创建预处理器宏吗? 这是我正在寻找的示例。我的真实场景更复杂 // That's
在 Microsoft 的 WinDef.h 中引入了几个用于回调的#defines: #ifdef _MAC #define CALLBACK PASCAL #define WINAPI
我知道我想在腿上开枪;)但是,它可以让我使其余(大量)代码更小且更具可读性。 在另一个预处理器宏中创建预处理器宏有什么棘手的方法吗? 这是我正在寻找的示例。我的真实场景更复杂 // That's wh
当我使用这段代码时: #include #define STR(x) #x int main(void) { printf(__FILE__ STR(__LINE__) "hello!\n"
今天的问候, 您好,我是使用 vb 6.0 的初学者。我正在使用以下代码并获得“用户定义类型未定义”。代码在下面。我得到错误的行被突出显示。请帮助。我应该添加一些引用或组件吗?如果是这样,它会是什么。
当我尝试编译此代码时,在 VB6 中出现编译错误“用户定义的类型未定义”。谁能告诉我需要做什么来解决这个错误?以下是我收到错误的行: Public Conn As ADODB.Connection P
我最近将我的应用程序从 Ember 1.3 升级到了 Ember 2.4.2。然而,在使用 ember build --env production 将其部署到我的生产环境后,我注意到了一些问题。 第
这个问题在这里已经有了答案: Getting user-defined type not defined error when running code (2 个回答) 3年前关闭。 我在运行程序以通
在我的一个项目中,我最近进行了重构并重命名了很多。完成此步骤后,一切正常,所有单元测试都通过了,但是我遇到了以下问题。 当我在VBE中执行“编译”时,确实出现了“用户定义的类型未定义”错误,并出现两种
所以我的 Visual Studio 将 tag1 和 tag2 都声明为未定义,但它们的定义很清楚,我不能根据另一个定义一个吗? #define push 99 #de
在 Excel 2007 中,我有以下非常简单的 VBA 代码: Public Type specType sb As Long End Type Private Sub MyButton_C
我是一名优秀的程序员,十分优秀!