segments_N 和segments.gen

The active segments in the index are stored in the segment info file, segments_N. There may be one or more segments_N files in the index; however, the one with the largest generation is the active one (when older segments_N files are present it's because they temporarily cannot be deleted, or, a writer is in the process of committing, or a custom IndexDeletionPolicy is in use). This file lists each segment by name, has details about the separate norms and deletion files, and also contains the size of each segment.

As of 2.1, there is also a file segments.gen. This file contains the current generation (the _N in segments_N) of the index. This is used only as a fallback in case the current generation cannot be accurately determined by directory listing alone (as is the case for some NFS clients with time-based directory cache expiraation). This file simply contains an Int32 version header (SegmentInfos.FORMAT_LOCKLESS = -2), followed by the generation recorded as Int64, written twice.

Pre-2.1: Segments --> Format, Version, NameCounter, SegCount, <SegName, SegSize> SegCount

2.1 and above: Segments --> Format, Version, NameCounter, SegCount, <SegName, SegSize, DelGen, HasSingleNormFile, NumField, NormGenNumField, IsCompoundFile>SegCount

2.3 and above: Segments --> Format, Version, NameCounter, SegCount, <SegName, SegSize, DelGen, DocStoreOffset, [DocStoreSegment, DocStoreIsCompoundFile], HasSingleNormFile, NumField, NormGenNumField, IsCompoundFile>SegCount

Format, NameCounter, SegCount, SegSize, NumField, DocStoreOffset --> Int32

Version, DelGen, NormGen --> Int64

SegName, DocStoreSegment --> String

IsCompoundFile, HasSingleNormFile, DocStoreIsCompoundFile --> Int8

Format is -1 as of Lucene 1.4, -3 (SegmentInfos.FORMAT_SINGLE_NORM_FILE) as of Lucene 2.1 and 2.2, and -4 (SegmentInfos.FORMAT_SHARED_DOC_STORE) as of Lucene 2.3

Version counts how often the index has been changed by adding or deleting documents.

NameCounter is used to generate names for new segment files.

SegName is the name of the segment, and is used as the file name prefix for all of the files that compose the segment's index.

SegSize is the number of documents contained in the segment index.

DelGen is the generation count of the separate deletes file. If this is -1, there are no separate deletes. If it is 0, this is a pre-2.1 segment and you must check filesystem for the existence of _X.del. Anything above zero means there are separate deletes (_X_N.del).

NumField is the size of the array for NormGen, or -1 if there are no NormGens stored.

NormGen records the generation of the separate norms files. If NumField is -1, there are no normGens stored and they are all assumed to be 0 when the segment file was written pre-2.1 and all assumed to be -1 when the segments file is 2.1 or above. The generation then has the same meaning as delGen (above).

IsCompoundFile records whether the segment is written as a compound file or not. If this is -1, the segment is not a compound file. If it is 1, the segment is a compound file. Else it is 0, which means we check filesystem to see if _X.cfs exists.

If HasSingleNormFile is 1, then the field norms are written as a single joined file (with extension .nrm); if it is 0 then each field's norms are stored as separate .fN files. See "Normalization Factors" below for details.

DocStoreOffset, DocStoreSegment, DocStoreIsCompoundFile: If DocStoreOffset is -1, this segment has its own doc store (stored fields values and term vectors) files and DocStoreSegment and DocStoreIsCompoundFile are not stored. In this case all files for stored field values (*.fdt and *.fdx) and term vectors (*.tvf, *.tvd and *.tvx) will be stored with this segment. Otherwise, DocStoreSegment is the name of the segment that has the shared doc store files; DocStoreIsCompoundFile is 1 if that segment is stored in compound file format (as a .cfx file); and DocStoreOffset is the starting document in the shared doc store files where this segment's documents begin. In this case, this segment does not store its own doc store files but instead shares a single set of these files with other segments.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import cv2 import numpy as np import torch import torch.nn.functional as F from skimage.segmentation import slic import matplotlib.pyplot as plt from skimage.segmentation import mark_boundaries from skimage import img_as_float # 定义超像素数量 num_segments = 100 # 加载图像 A 和 B img_a = cv2.imread('img_a.jpg') img_b = cv2.imread('img_b.jpg') # 对图像 A 进行超像素分割,并获取每个超像素块的像素范围 segments_a = slic(img_as_float(img_a), n_segments=num_segments, sigma=5) pixel_ranges = [] for i in range(num_segments): mask = (segments_a == i) indices = np.where(mask)[1] pixel_range = (np.min(indices), np.max(indices)) pixel_ranges.append(pixel_range) # 将像素范围应用到图像 B 上实现超像素分割 segments_b = np.zeros_like(segments_a) for i in range(num_segments): pixel_range = pixel_ranges[i] segment_b = img_b[:, pixel_range[0]:pixel_range[1], :] segment_b = torch.from_numpy(segment_b.transpose(2, 0, 1)).unsqueeze(0).float() segment_b = F.interpolate(segment_b, size=(img_b.shape[0], pixel_range[1] - pixel_range[0]), mode='bilinear', align_corners=True) segment_b = segment_b.squeeze(0).numpy().transpose(1, 2, 0).astype(np.uint8) gray = cv2.cvtColor(segment_b, cv2.COLOR_BGR2GRAY) _, mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY) segments_b[np.where(mask)] = i # 可视化超像素分割结果 fig = plt.figure('Superpixels') ax = fig.add_subplot(1, 2, 1) ax.imshow(mark_boundaries(img_as_float(cv2.cvtColor(img_a, cv2.COLOR_BGR2RGB)), segments_a)) ax = fig.add_subplot(1, 2, 2) ax.imshow(mark_boundaries(img_as_float(cv2.cvtColor(img_b, cv2.COLOR_BGR2RGB)), segments_b)) plt.axis("off") plt.show(),上述代码中segments_a = slic(img_as_float(img_a), n_segments=num_segments, sigma=5)出现错误:ValueError: Cannot convert from object to float64.
最新发布
05-30
这个错误的原因可能是因为 `img_a` 的类型不是浮点类型,需要将其转换为浮点类型后再进行超像素分割。可以使用 `img_as_float` 函数将其转换为浮点类型,代码如下: ``` import cv2 import numpy as np import torch import torch.nn.functional as F from skimage.segmentation import slic import matplotlib.pyplot as plt from skimage.segmentation import mark_boundaries from skimage import img_as_float # 定义超像素数量 num_segments = 100 # 加载图像 A 和 B img_a = cv2.imread('img_a.jpg') img_b = cv2.imread('img_b.jpg') # 将图像 A 转换为浮点类型 img_a = img_as_float(img_a) # 对图像 A 进行超像素分割,并获取每个超像素块的像素范围 segments_a = slic(img_a, n_segments=num_segments, sigma=5) pixel_ranges = [] for i in range(num_segments): mask = (segments_a == i) indices = np.where(mask)[1] pixel_range = (np.min(indices), np.max(indices)) pixel_ranges.append(pixel_range) # 将像素范围应用到图像 B 上实现超像素分割 segments_b = np.zeros_like(segments_a) for i in range(num_segments): pixel_range = pixel_ranges[i] segment_b = img_b[:, pixel_range[0]:pixel_range[1], :] segment_b = torch.from_numpy(segment_b.transpose(2, 0, 1)).unsqueeze(0).float() segment_b = F.interpolate(segment_b, size=(img_b.shape[0], pixel_range[1] - pixel_range[0]), mode='bilinear', align_corners=True) segment_b = segment_b.squeeze(0).numpy().transpose(1, 2, 0).astype(np.uint8) gray = cv2.cvtColor(segment_b, cv2.COLOR_BGR2GRAY) _, mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY) segments_b[np.where(mask)] = i # 可视化超像素分割结果 fig = plt.figure('Superpixels') ax = fig.add_subplot(1, 2, 1) ax.imshow(mark_boundaries(img_as_float(cv2.cvtColor(img_a, cv2.COLOR_BGR2RGB)), segments_a)) ax = fig.add_subplot(1, 2, 2) ax.imshow(mark_boundaries(img_as_float(cv2.cvtColor(img_b, cv2.COLOR_BGR2RGB)), segments_b)) plt.axis("off") plt.show() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值