- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 tensorflow 的对象检测 api 与 faster_rcnn_resnet101 结合使用,并在尝试训练时遇到以下错误:
tensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found.(0) Invalid argument: Input to reshape is a tensor with 36 values, but the requested shape requires a multiple of 16
[[{{node Reshape_13}}]]
[[IteratorGetNext]]
[[IteratorGetNext/_7243]]
(1) Invalid argument: Input to reshape is a tensor with 36 values, but the requested shape requires a multiple of 16
[[{{node Reshape_13}}]]
[[IteratorGetNext]]
0 successful operations.0 derived errors ignored.
我正在使用 pets-train.sh 文件的略微修改版本来运行训练(仅更改了路径)。我正在尝试对包含大小为 (1280, 720) 的 jpg 图像的 tf.record 文件进行训练,并且未对网络架构进行任何更改(我已确认记录中的所有图像都是此大小)。
奇怪的是,当我执行与教程文件 detect_pets.py 中的内容相同的操作时,我可以成功地对这些图像进行推理。这让我觉得我创建 tf.record 文件(下面的代码)的方式有问题,而不是与图像的形状有关,尽管错误与 reshape 有关。但是,我已经成功地训练了之前以相同方式创建的 tf.records(来自大小为 (600, 600)、(1024, 1024) 和 (720, 480) 的图像,它们都具有相同的网络)。此外,我之前在大小为 (600, 600) 的不同图像数据集上遇到过类似的错误(只是数字不同,但错误仍然与节点 Reshape_13 有关)。
我正在使用 python 3.7,tf 版本 1.14.0,cuda 10.2,Ubuntu 18.04
我广泛查看了其他各种帖子(here、here、here、here 和 here),但我无法取得任何进展。
我已经尝试调整 keep_aspect_ratio_resizer 参数(最初是 min_dimension=600, max_dimension=1024 但我也尝试过 min, max = (720, 1280) 并尝试了 pad_to_max_dimension: true 这两个最小/最大选择作为好吧)。
这是我用来创建 tf.record 文件的代码(抱歉或此处没有缩进):
def make_example(imfile, boxes):
with tf.gfile.GFile(imfile, "rb") as fid:
encoded_jpg = fid.read()
encoded_jpg_io = io.BytesIO(encoded_jpg)
image = PIL.Image.open(encoded_jpg_io)
if image.format != "JPEG":
raise Exception("Images need to be in JPG format")
height = image.height
width = image.width
xmins = []
xmaxs = []
ymins = []
ymaxs = []
for box in boxes:
xc, yc, w, h = box
xmin = xc - w / 2
xmax = xc + w / 2
ymin = yc - h / 2
ymax = yc + h / 2
new_xmin = np.clip(xmin, 0, width - 1)
new_xmax = np.clip(xmax, 0, width - 1)
new_ymin = np.clip(ymin, 0, height - 1)
new_ymax = np.clip(ymax, 0, height - 1)
area = (ymax - ymin) * (xmax - xmin)
new_area = (new_ymax - new_ymin) * (new_xmax - new_xmin)
if new_area > 0.3 * area:
xmins.append(new_xmin / width)
xmaxs.append(new_xmax / width)
ymins.append(new_ymin / height)
ymaxs.append(new_ymax / height)
classes_text = ["vehicle".encode("utf8")] * len(boxes)
classes = [1] * len(boxes)
abs_imfile = os.path.abspath(imfile)
difficult = [0] * len(boxes)
example = tf.train.Example(
features=tf.train.Features(
feature={
"image/height": int64_feature(height),
"image/width": int64_feature(width),
"image/filename": bytes_feature(imfile.encode("utf8")),
"image/source_id": bytes_feature(abs_imfile.encode("utf8")),
"image/encoded": bytes_feature(encoded_jpg),
"image/format": bytes_feature("jpeg".encode("utf8")),
"image/object/bbox/xmin": float_list_feature(xmins),
"image/object/bbox/xmax": float_list_feature(xmaxs),
"image/object/bbox/ymin": float_list_feature(ymins),
"image/object/bbox/ymax": float_list_feature(ymaxs),
"image/object/class/text": bytes_list_feature(classes_text),
"image/object/class/label": int64_list_feature(classes),
"image/object/difficult": int64_list_feature(difficult),
}
)
)
return example
def make_tfrecord(outfile, imfiles, truthfiles):
writer = tf.python_io.TFRecordWriter(outfile)
for imfile, truthfile in zip(imfiles, truthfiles):
print(imfile)
boxes = pd.read_csv(truthfile)
if boxes.empty:
boxes = []
else:
boxes = [
(box.Xc, box.Yc, box.Width, box.Height) for box in boxes.itertuples()
]
example = make_example(imfile, boxes)
writer.write(example.SerializeToString())
writer.close()
def make_combined_train_dset(names):
imfiles = []
truthfiles = []
traindir = os.path.join(tf_datadir, "train")
valdir = os.path.join(tf_datadir, "val")
for name in names:
imdir = os.path.join(processed_datadir, name, "images")
truthdir = os.path.join(processed_datadir, name, "truth")
imfiles.extend(sorted(glob.glob(os.path.join(imdir, "*.jpg"))))
truthfiles.extend(sorted(glob.glob(os.path.join(truthdir, "*.csv"))))
inds = list(range(len(imfiles)))
np.random.shuffle(inds)
imfiles = [imfiles[i] for i in inds]
truthfiles = [truthfiles[i] for i in inds]
ntrain = round(0.9 * len(imfiles))
train_imfiles = imfiles[:ntrain]
train_truthfiles = truthfiles[:ntrain]
val_imfiles = imfiles[ntrain:]
val_truthfiles = truthfiles[ntrain:]
chunksize = 1500
for d in [traindir, valdir]:
if not os.path.exists(d):
os.mkdir(d)
for i in range(0, len(train_imfiles), chunksize):
print(f"{i} / {len(train_imfiles)}", end="\r")
cur_imfiles = train_imfiles[i : i + chunksize]
cur_truthfiles = train_truthfiles[i : i + chunksize]
testfile = os.path.join(traindir, f"{i}.tfrecord")
make_tfrecord(testfile, cur_imfiles, cur_truthfiles)
for i in range(0, len(val_imfiles), chunksize):
print(f"{i} / {len(val_imfiles)}", end="\r")
cur_imfiles = val_imfiles[i : i + chunksize]
cur_truthfiles = val_truthfiles[i : i + chunksize]
testfile = os.path.join(valdir, f"{i}.tfrecord")
make_tfrecord(testfile, cur_imfiles, cur_truthfiles)
def make_train_dset(name, train_inc=1, val_inc=1, test_inc=1):
trainfile = os.path.join(tf_datadir, name + "-train.tfrecord")
valfile = os.path.join(tf_datadir, name + "-val.tfrecord")
imdir = os.path.join(processed_datadir, name, "images")
truthdir = os.path.join(processed_datadir, name, "truth")
imfiles = sorted(glob.glob(os.path.join(imdir, "*.jpg")))
truthfiles = sorted(glob.glob(os.path.join(truthdir, "*.csv")))
n = len(imfiles)
ntrain = round(0.9 * n)
print(trainfile)
make_tfrecord(trainfile, imfiles[:ntrain:train_inc], truthfiles[:ntrain:train_inc])
print(valfile)
make_tfrecord(valfile, imfiles[ntrain::val_inc], truthfiles[ntrain::val_inc])
对于其他数据集,我已经能够使用上面定义的函数 make_combined_train_dset(或 make_train_dset)创建一个 tf.record,然后在 faster_rcnn_resnet101.config 文件中提供这些数据集的路径,然后训练正常进行(只是如教程示例中所示)。使用这个新数据集(以及至少一个其他数据集),我遇到了上述 reshape 错误。尽管如此,我仍然可以对该数据集中的图像进行推理,因此我认为问题在于 tf 记录或它们的读取方式,而不是图像或其大小的内在问题。
任何人都可以提供任何帮助,我将不胜感激,因为我已经为此苦苦挣扎了好几天。
最佳答案
我是个白痴:确认。
问题是 classes_text、classes 和 difficult 的长度不对。
已替换
classes_text = ["vehicle".encode("utf8")] * len(boxes)
classes = [1] * len(boxes)
difficult = [0] * len(boxes)
与
classes_text = ["vehicle".encode("utf8")] * len(xmins)
classes = [1] * len(xmins
difficult = [0] * len(xmins)
它运行良好。发布这个以防其他人遇到类似问题。
感谢所有花时间或思考过我的问题的人。希望这有助于某人不要浪费时间。
关于python - 参数 : Input to reshape is a tensor with x values, 无效,但请求的形状需要 y 的倍数。 {节点 Reshape_13},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57965554/
我刚刚编写了这些代码,但输出不同。第二个代码的输出符合我的预期,但第一个代码的输出不正确。但为什么呢? def fib(n): x = 0 y = 1 print x
#include #include #define CUBE(y)y*(y*y) main() { int j; j = CUBE(-2+4);
这个问题在这里已经有了答案: Multiple assignment and evaluation order in Python (11 个答案) 关闭 1 年前。 我看到下面的代码,但不知道它做
我正在阅读 book , 并讲了 typeclass Eq 的定义 有两个功能== , /=在等式中,它们被实现为: x == y = not (x /= y) x /= y = not (
我最近参加了一个代码力量竞赛。在比赛的编辑部分,我看到了按位运算符之间的一种美妙关系,即 x + y = x & y + x |是的我还不知道证据。我拿了几个数字来看看这个等式是否正确。我很高兴知道这
我使用 CGRectMake(x,x,x,x) 在我的 View 中放置了一个按钮,当然 x 是位置和大小。当我使用 -(BOOL)shouldAutoRotate... 旋转 View 时,我想将按
this.x = (Math.random()*canvasWidth); this.y = (Math.random()*canvasHeight); (1) this.shift = {x: th
我想将此代码运行为“if 'Britain' or 'UK' in string do stuff, but don't do stuff if "Ex UK" 在字符串中": #Case insen
早上好,我是新来的,我带来了一个小问题。我无法针对以下问题开发有效的算法:我需要找到三个正数 x、y 和 z 的组合,以便 x + y、x - y、y + z、y - z、x + z 和 x - z
我现在正在使用 C++ 编写方案的解释器。我有一个关于定义和 lambda 的问题。 (define (add x y) (+ x y)) 扩展为 (define add (lambda (x y)
我正在尝试使用一台主机通过 FTP 将内容上传到另一台主机。 “我不会打开到 172.xxx.xxx.xxx(仅到 54.xxx.xxx.xxx)的连接”甚至不相关,因为我没有连接到那个主持人。这是托
在 Python 中,使用 [] 解包函数调用有什么区别? , 与 ()还是一无所有? def f(): return 0, 1 a, b = f() # 1 [a, b] = f() # 2
给定方程 z = z(x,y) 2 个表面 I和 II : z_I(x, y) = a0 + a1*y + a2*x + a3*y**2 + a4*x**2 + a5*x*y z_II(x, y)
几年前我有这个面试问题,但我还没有找到答案。 x 和 y 应该是什么才能形成无限循环? while (x = y && x != y) { } 我们尝试了 Nan,infinity+/-,null f
我正在尝试使用 Camel FTP Producer 将文件发送到第三方 ftp 服务器(似乎由 Amazon 托管),但遇到了一个问题,写入文件失败,并显示:文件操作失败...主机尝试数据连接 x.
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
我正在使用 torch.tensor.repeat() x = torch.tensor([[1, 2, 3], [4, 5, 6]]) period = x.size(1) repeats = [1
#include int main() { int x = 9; int y = 2; int z = x - (x / y) * y; printf("%d", z
我很难理解先有定义然后有两个异或表达式的含义。这个定义的作用是什么? 我尝试发送 x=8, y=7,结果是 x=15 和 y=8为什么会这样? 这是程序: #define FUNC(a,b) a^=b
我正在尝试使用 SIMD 优化此功能,但我不知道从哪里开始。 long sum(int x,int y) { return x*x*x+y*y*y; } 反汇编函数如下所示: 4007a0
我是一名优秀的程序员,十分优秀!