6.S081-Lab Util report

本文介绍了在 xv6 操作系统中实现 sleep 系统调用、并发 ping-pong 程序、并发 primes 素数筛选、find 文件查找以及 xargs 命令行工具的过程。通过阅读 xv6 代码,理解系统调用、管道、进程创建和同步等概念,加深了对操作系统内核和并发编程的理解。

Lab Util report

Boot Xv6 (easy)

没啥复杂的,按照教程来就可以了,基本没踩坑。

Sleep

描述:Implement the UNIX program sleep for xv6; your sleep should pause for a user-specified number of ticks. A tick is a notion of time defined by the xv6 kernel, namely the time between two interrupts from the timer chip. Your solution should be in the file user/sleep.c.

指导(可以称得上是保姆级了。。。):

  • Before you start coding, read Chapter 1 of the xv6 book.
    *Look at some of the other programs in user/ (e.g., user/echo.c, user/grep.c, and user/rm.c) to see how you can obtain the command-line arguments passed to a program.
  • If the user forgets to pass an argument, sleep should print an error message.
  • The command-line argument is passed as a string; you can convert it to an integer using atoi (see user/ulib.c).
  • Use the system call sleep.
  • See kernel/sysproc.c for the xv6 kernel code that implements the sleep system call (look for sys_sleep), user/user.h for the C definition of sleep callable from a user program, and user/usys.S for the assembler code that jumps from user code into the kernel for sleep.
  • Make sure main calls exit() in order to exit your program.
  • Add your sleep program to UPROGS in Makefile; once you’ve done that, make qemu will compile your program and you’ll be able to run it from the xv6 shell.
  • Look at Kernighan and Ritchie’s book The C programming language (second edition) (K&R) to learn about C.

按照教程即可。代码如下:

#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"

int main(int argc, char *argv[])
{
   
   
    int t;
	if (argc <= 1 || argc > 2) {
   
   
		fprintf(2, "usage: sleep <seconds>\n");
        exit(1);
	}
    t = atoi(argv[1]);
    sleep(t);
	exit(0);
}

实现sleep命令没啥好讲的,实际上好玩的是sleep syscall的实现,即如何从用户态陷入内核空间,进而完成sleep命令的。

首先在user.h中声明了sleep这个函数,在usys.S中看到,首先.global sleep在全局符号表中注册函数名sleep,之后调用sleep这个系统调用时就会执行以下这段riscv汇编代码:

.global sleep
sleep:
 li a7, SYS_sleep
 ecall
 ret

这段汇编的意思也很明确,就是把SYS_sleep的值放入a7寄存器中,记录系统调用的类型,之后的ecall指令产生一个异常,此时陷入内核态,然后查看kernel/syscall.c可知SYS_sleepsys_sleep存在映射关系,syscall函数可以根据SYS_<name>值的不同执行不同的sys_<name>函数(kernel/syscall.c:140)。

void
syscall(void)
{
   
   
  int num;
  struct proc *p = myproc();

  num = p->trapframe->a7;
  if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
   
   
    p->trapframe->a0 = syscalls[num]();
  } else {
   
   
    printf("%d %s: unknown sys call %d\n",
            p->pid, p->name, num);
    p->trapframe->a0 = -1;
  }
}

反正目前看kernel/syscall.c里的syscall实现,是通过中断实现的(trapframe),具体的实现会等到后面的实验再详细解释。

以上是一个基本的理解,更详细的了解估计在后面的课程中会涉及。

参考:

PingPong

描述:Write a program that uses UNIX system calls to ‘‘ping-pong’’ a byte between two processes over a pair of pipes, one for each direction. The parent should send a byte to the child; the child should print “: received ping”, where is its process ID, write the byte on the pipe to the parent, and exit; the parent should read the byte from the child, print “: received pong”, and exit. Your solution should be in the file user/pingpong.c.

指导:

  • Use pipe to create a pipe.
  • Use fork to create a child.
  • Use read to read from the pipe, and write to write to the pipe.
  • Use getpid to find the process ID of the calling process.
  • Add the program to UPROGS in Makefile.
  • User programs on xv6 have a limited set of library functions available to them. You can see the list in user/user.h; the source (other than for system calls) is in user/ulib.c, user/printf.c, and user/umalloc.c.

之前实现过unix的版本,直接把代码copy稍作改动即可。

#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"


int main()
{
   
   
    int p[2], q[2];
    pipe(p), pipe(q);
    if (fork() > 0) {
   
   
        close(p[0]);
        close(q[1]);
        char x[1];
        write(p[1], "0", 1);
        read
下面是我的代码: import os import cv2 import numpy as np import tensorflow as tf from tensorflow.keras import layers, models, applications from tensorflow.keras.preprocessing.image import ImageDataGenerator from tensorflow.keras.callbacks import EarlyStopping from tensorflow.keras.optimizers.legacy import Adam from sklearn.model_selection import train_test_split import tensorflow_addons as tfa # 新增用于高级优化器 # 配置文件路径 YIZHUIHE_PATH = "yizhuihe" STATS_PATH = "zhuihetongji.xlsx" PREPROCESSED_DATA_PATH = "preprocessed_data4" # 保存预处理数据的目录 MODEL_PATH = "bamboo_matching_model4.h5" # 模型保存路径 EPOCHS = 10 BATCH_SIZE = 32 # 创建保存预处理数据的目录 os.makedirs(PREPROCESSED_DATA_PATH, exist_ok=True) # -------------------- 数据预处理模块 -------------------- class BambooPreprocessor: def __init__(self, target_size=(256, 64)): self.target_size = target_size self.region_size = (64, 64) def _enhance_texture(self, img): """增强竹简纹理特征""" # 转换为RGB格式保持一致性 img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # 1. 自适应直方图均衡化 lab = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2LAB) l, a, b = cv2.split(lab) clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8, 8)) l = clahe.apply(l) lab = cv2.merge((l, a, b)) enhanced = cv2.cvtColor(lab, cv2.COLOR_LAB2RGB) # 2. 纹理方向滤波 kernel = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) textured = cv2.filter2D(enhanced, -1, kernel) return textured def _detect_fracture(self, img): """改进的断口检测方法""" # 灰度化+二值化 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) _, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU) # 边缘检测(自适应阈值) low_thresh = np.percentile(gray, 25) high_thresh = np.percentile(gray, 75) edges = cv2.Canny(gray, low_thresh, high_thresh) # 轮廓分析(OpenCV版本兼容处理) if cv2.__version__.startswith('4'): contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) else: _, contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) if not contours: return None main_contour = max(contours, key=cv2.contourArea) # 提取边界区域 x, y, w, h = cv2.boundingRect(main_contour) boundary_width = 10 # 统一边界宽度 # 确保边界在图像范围内 top = img[max(y, 0):min(y+boundary_width, img.shape[0]), max(x, 0):min(x+boundary_width, img.shape[1])] bottom = img[max(y+h-boundary_width, 0):min(y+h, img.shape[0]), max(x, 0):min(x+boundary_width, img.shape[1])] left = img[max(y, 0):min(y+h, img.shape[0]), max(x, 0):min(x+boundary_width, img.shape[1])] right = img[max(y, 0):min(y+h, img.shape[0]), max(x+w-boundary_width, 0):min(x+w, img.shape[1])] # 方向特征 sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=5) sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=5) orientation = np.arctan2(sobely, sobelx) orientation_region = orientation[max(y, 0):min(y+h, img.shape[0]), max(x, 0):min(x+w, img.shape[1])] return { 'top': top, 'bottom': bottom, 'left': left, 'right': right, 'orientation': orientation_region } def preprocess(self, img_path): img = cv2.imread(img_path) if img is None: return None # 纹理增强 img = self._enhance_texture(img) # 提取断口区域 fracture_regions = self._detect_fracture(img) if not fracture_regions: return None # 统一所有区域的大小 resized_regions = {} for region_name in ['top', 'bottom', 'left', 'right']: region = fracture_regions[region_name] # 确保是单通道灰度图 if len(region.shape) == 3: region = cv2.cvtColor(region, cv2.COLOR_BGR2GRAY) resized_regions[region_name] = cv2.resize(region, self.region_size) # 处理方向特征图 orientation = fracture_regions['orientation'] orientation = cv2.normalize(orientation, None, 0, 255, cv2.NORM_MINMAX) orientation = cv2.resize(orientation, self.region_size) # 创建多通道特征图 channels = [ resized_regions['top'], resized_regions['bottom'], resized_regions['left'], resized_regions['right'], orientation ] # 堆叠通道并调整最终尺寸 processed = np.stack(channels, axis=-1) return cv2.resize(processed, self.target_size) # -------------------- # 数据加载器 # -------------------- class BambooDataset: def __init__(self, data_root): self.data_root = data_root self.groups = self._load_groups() self.preprocessor = BambooPreprocessor() def _load_groups(self): """加载已缀合组信息""" groups = {} for group_id in os.listdir(self.data_root): group_path = os.path.join(self.data_root, group_id) if os.path.isdir(group_path): groups[group_id] = [ os.path.join(group_path, f) for f in os.listdir(group_path) if f.endswith(('.jpg', '.png')) ] return groups def _generate_pairs(self): """生成训练样本对(正负样本)""" positive_pairs = [] negative_pairs = [] # 正样本:同组内竹简 for group_id, paths in self.groups.items(): if len(paths) < 2: continue for i in range(len(paths)): for j in range(i+1, len(paths)): positive_pairs.append((paths[i], paths[j], 1)) # 负样本:不同组竹简 all_paths = [p for paths in self.groups.values() for p in paths] group_ids = list(self.groups.keys()) # 平衡正负样本数量 num_neg = min(len(positive_pairs), len(all_paths) * 2) for _ in range(num_neg): while True: path1 = np.random.choice(all_paths) path2 = np.random.choice(all_paths) group1 = next(g for g, ps in self.groups.items() if path1 in ps) group2 = next(g for g, ps in self.groups.items() if path2 in ps) if group1 != group2: negative_pairs.append((path1, path2, 0)) break return positive_pairs + negative_pairs def load_dataset(self): """加载预处理后的数据集""" pairs = self._generate_pairs() X1, X2, y = [], [], [] for path1, path2, label in pairs: img1 = self.preprocessor.preprocess(path1) img2 = self.preprocessor.preprocess(path2) if img1 is not None and img2 is not None: X1.append(img1) X2.append(img2) y.append(label) return np.array(X1), np.array(X2), np.array(y) def create_improved_siamese_network(input_shape): """改进的孪生网络架构""" def spatial_attention(input_tensor): """空间注意力机制""" avg_pool = layers.Lambda(lambda x: tf.reduce_mean(x, axis=3, keepdims=True))(input_tensor) max_pool = layers.Lambda(lambda x: tf.reduce_max(x, axis=3, keepdims=True))(input_tensor) concat = layers.Concatenate(axis=3)([avg_pool, max_pool]) cbam_feature = layers.Conv2D(1, kernel_size=7, padding='same', activation='sigmoid')(concat) return layers.Multiply()([input_tensor, cbam_feature]) # 输入层 base_input = layers.Input(shape=input_shape) # 通道适配层:将5通道转换为3通道 x = layers.Conv2D(3, (1, 1), padding='same', name='channel_adapter')(base_input) # 共享特征提取器(使用ResNet50) base_model = applications.ResNet50( weights='imagenet', include_top=False, input_shape=(input_shape[0], input_shape[1], 3) ) x = base_model(x) # 添加注意力机制 x = spatial_attention(x) # 多尺度特征融合 branch1 = layers.GlobalAveragePooling2D()(x) branch2 = layers.GlobalMaxPooling2D()(x) x = layers.Concatenate()([branch1, branch2]) # 增强特征表示 x = layers.Dense(512, activation='relu', kernel_regularizer=tf.keras.regularizers.l1_l2(0.01, 0.01))(x) x = layers.Dropout(0.3)(x) feature_extractor = models.Model(inputs=base_input, outputs=x) # 孪生架构 input_a = layers.Input(shape=input_shape) input_b = layers.Input(shape=input_shape) features_a = feature_extractor(input_a) features_b = feature_extractor(input_b) # 改进的特征差异度量 diff = layers.Subtract()([features_a, features_b]) abs_diff = layers.Lambda(lambda x: tf.abs(x))(diff) squared_diff = layers.Lambda(lambda x: tf.square(x))(diff) concat_diff = layers.Concatenate()([abs_diff, squared_diff]) # 相似性分类 x = layers.Dense(256, activation='relu')(concat_diff) x = layers.Dropout(0.2)(x) classification_output = layers.Dense(1, activation='sigmoid', name='classification')(x) # 添加特征差异作为额外输出 feat_diff = layers.Lambda( lambda x: tf.reduce_mean(tf.abs(x), axis=1), name='feature_difference' )(concat_diff) # 创建具有两个输出的模型 siamese_model = models.Model( inputs=[input_a, input_b], outputs=[classification_output, feat_diff] ) return siamese_model # 配对数据增强生成器 class PairedDataGenerator: def __init__(self, X1, X2, y, datagen, batch_size=32): self.X1 = X1 self.X2 = X2 self.y = y self.datagen = datagen self.batch_size = batch_size # 初始化数据生成器 self.genX1 = datagen.flow(X1, y, batch_size=batch_size, shuffle=False) self.genX2 = datagen.flow(X2, y, batch_size=batch_size, shuffle=False) def __iter__(self): return self def __next__(self): X1_batch, y_batch = next(self.genX1) X2_batch, _ = next(self.genX2) return [X1_batch, X2_batch], y_batch # 困难样本挖掘回调 class HardExampleMiner(tf.keras.callbacks.Callback): def __init__(self, train_data, threshold=0.2): self.X1_train, self.X2_train, self.y_train = train_data self.threshold = threshold def on_epoch_end(self, epoch, logs=None): # 获取当前批次预测结果 y_pred, _ = self.model.predict([self.X1_train, self.X2_train], verbose=0) # 选择预测概率接近0.5的困难样本 hard_indices = np.where(np.abs(y_pred.squeeze() - 0.5) < self.threshold)[0] # 增强训练(仅训练困难样本) if len(hard_indices) > 0: self.model.fit( [self.X1_train[hard_indices], self.X2_train[hard_indices]], [self.y_train[hard_indices], np.zeros(len(hard_indices))], # 为特征差异输出提供伪标签 epochs=1, batch_size=BATCH_SIZE, verbose=0 ) def hybrid_loss(y_true, y_pred): """混合损失函数 - 同时处理分类输出和特征差异""" # 解包预测值:y_pred 包含两个输出 classification_output = y_pred[0] feat_diff = y_pred[1] # 确保y_true是正确形状 (batch_size, 1) y_true = tf.reshape(tf.cast(y_true, tf.float32), [-1, 1]) # 计算二元交叉熵损失 - 确保维度匹配 bce = tf.keras.losses.binary_crossentropy( y_true, classification_output, from_logits=False ) # 特征差异正则化 - 确保维度匹配 reg_loss = 0.1 * tf.maximum(0.5 - feat_diff, 0) return bce + reg_loss def train_and_evaluate(): # 检查预处理数据文件是否存在 x1_path = os.path.join(PREPROCESSED_DATA_PATH, "X1.npy") x2_path = os.path.join(PREPROCESSED_DATA_PATH, "X2.npy") y_path = os.path.join(PREPROCESSED_DATA_PATH, "y.npy") if os.path.exists(x1_path) and os.path.exists(x2_path) and os.path.exists(y_path): # 加载预处理数据 X1 = np.load(x1_path) X2 = np.load(x2_path) y = np.load(y_path) print("预处理数据已加载") else: # 加载并预处理数据 dataset = BambooDataset(YIZHUIHE_PATH) X1, X2, y = dataset.load_dataset() # 保存预处理数据 np.save(x1_path, X1) np.save(x2_path, X2) np.save(y_path, y) print("预处理数据已保存") # 划分数据集 X1_train, X1_val, X2_train, X2_val, y_train, y_val = train_test_split( X1, X2, y, test_size=0.2, random_state=42 ) # 数据增强配置 datagen = ImageDataGenerator( rotation_range=10, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.1, zoom_range=0.1, horizontal_flip=True, fill_mode='nearest' ) # 创建配对数据生成器 train_generator = PairedDataGenerator( X1_train, X2_train, y_train, datagen, batch_size=BATCH_SIZE ) # 创建模型 siamese_model = create_improved_siamese_network(X1_train.shape[1:]) # 优化器(使用Lookahead优化器提升收敛性) optimizer = tfa.optimizers.Lookahead( Adam(learning_rate=1e-4), sync_period=6, slow_step_size=0.5 ) # 编译模型 - 使用自定义混合损失函数 siamese_model.compile( optimizer=optimizer, loss=hybrid_loss, metrics={'classification': 'accuracy'} # 只为分类输出计算准确率 ) # 早停策略 - 监控分类输出的准确率 early_stopping = EarlyStopping( monitor='val_classification_accuracy', patience=10, restore_best_weights=True, min_delta=0.001 ) # 困难样本挖掘 hard_miner = HardExampleMiner( train_data=(X1_train, X2_train, y_train), threshold=0.2 ) # 模型训练 - 注意:验证数据需要两个输出 history = siamese_model.fit( train_generator, steps_per_epoch=len(X1_train) // BATCH_SIZE, validation_data=([X1_val, X2_val], [y_val, np.zeros(len(y_val))]), # 为特征差异输出提供伪标签 epochs=EPOCHS, callbacks=[early_stopping, hard_miner], class_weight={0: 1.0, 1: 1.5} ) # 保存模型 siamese_model.save(MODEL_PATH) # 模型评估 - 只关注分类输出 loss = siamese_model.evaluate([X1_val, X2_val], [y_val, np.zeros(len(y_val))]) # 损失函数返回总损失,但我们关心分类准确率 # 在评估中,metrics 会返回分类准确率 print(f"验证准确率: {history.history['val_classification_accuracy'][-1]*100:.2f}%") return history if __name__ == "__main__": train_and_evaluate()在训练完毕后遇到了报错ifference_loss: 1.1556 - classification_accuracy: 0.4956 - val_loss: 36.8123 - val_classification_loss: 0.6945 - val_feature_difference_loss: 0.1284 - val_classification_accuracy: 0.4487 Epoch 10/10 1/32 [..............................] - ETA: 6:00 - loss: 30.5024 - classification_loss: 0.8720 - feature_differ 2/32 [>.............................] - ETA: 6:02 - loss: 30.2336 - classification_loss: 0.8529 - feature_differ 3/32 [=>............................] - ETA: 5:56 - loss: 30.5036 - classification_loss: 0.8665 - feature_differ 4/32 [==>...........................] - ETA: 5:47 - loss: 30.2310 - classification_loss: 0.8640 - feature_differ 5/32 [===>..........................] - ETA: 5:35 - loss: 29.9351 - classification_loss: 0.8612 - feature_differ 6/32 [====>.........................] - ETA: 5:23 - loss: 29.8819 - classification_loss: 0.8636 - feature_differ 7/32 [=====>........................] - ETA: 5:11 - loss: 29.8167 - classification_loss: 0.8773 - feature_differ 8/32 [======>.......................] - ETA: 4:58 - loss: 29.7443 - classification_loss: 0.9530 - feature_differ 9/32 [=======>......................] - ETA: 4:39 - loss: 29.6304 - classification_loss: 0.9469 - feature_differ10/32 [========>.....................] - ETA: 4:27 - loss: 29.4564 - classification_loss: 0.9363 - feature_differ11/32 [=========>....................] - ETA: 4:16 - loss: 29.2758 - classification_loss: 0.9282 - feature_differ12/32 [==========>...................] - ETA: 4:04 - loss: 29.1919 - classification_loss: 0.9231 - feature_differ13/32 [===========>..................] - ETA: 3:53 - loss: 29.1008 - classification_loss: 0.9268 - feature_differ14/32 [============>.................] - ETA: 3:41 - loss: 28.9858 - classification_loss: 0.9246 - feature_differ15/32 [=============>................] - ETA: 3:29 - loss: 28.8968 - classification_loss: 0.9279 - feature_differ16/32 [==============>...............] - ETA: 3:17 - loss: 28.7870 - classification_loss: 0.9224 - feature_differ17/32 [==============>...............] - ETA: 3:05 - loss: 28.6540 - classification_loss: 0.9196 - feature_differ18/32 [===============>..............] - ETA: 2:53 - loss: 28.5789 - classification_loss: 0.9091 - feature_differ19/32 [================>.............] - ETA: 2:41 - loss: 28.4827 - classification_loss: 0.9090 - feature_differ20/32 [=================>............] - ETA: 2:30 - loss: 28.3714 - classification_loss: 0.9066 - feature_differ21/32 [==================>...........] - ETA: 2:17 - loss: 28.2615 - classification_loss: 0.9061 - feature_differ22/32 [===================>..........] - ETA: 2:05 - loss: 28.1563 - classification_loss: 0.9246 - feature_differ23/32 [====================>.........] - ETA: 1:52 - loss: 28.0344 - classification_loss: 0.9217 - feature_differ24/32 [=====================>........] - ETA: 1:40 - loss: 27.9423 - classification_loss: 0.9150 - feature_differ25/32 [======================>.......] - ETA: 1:27 - loss: 27.8502 - classification_loss: 0.9217 - feature_differ26/32 [=======================>......] - ETA: 1:15 - loss: 27.7519 - classification_loss: 0.9186 - feature_differ27/32 [========================>.....] - ETA: 1:02 - loss: 27.6517 - classification_loss: 0.9175 - feature_differ28/32 [=========================>....] - ETA: 50s - loss: 27.5349 - classification_loss: 0.9154 - feature_differe29/32 [==========================>...] - ETA: 37s - loss: 27.4168 - classification_loss: 0.9140 - feature_differe30/32 [===========================>..] - ETA: 25s - loss: 27.3513 - classification_loss: 0.9132 - feature_differe31/32 [============================>.] - ETA: 12s - loss: 27.2566 - classification_loss: 0.9135 - feature_differe32/32 [==============================] - ETA: 0s - loss: 27.1861 - classification_loss: 0.9117 - feature_difference_loss: 1.1294 - classification_accuracy: 0.4956 2025-06-22 14:05:17.364362: W tensorflow/core/framework/op_kernel.cc:1839] OP_REQUIRES failed at fused_batch_norm_op.cc:1565 : RESOURCE_EXHAUSTED: OOM when allocating tensor with shape[32,4,16,1024] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu 2025-06-22 14:05:17.396860: W tensorflow/core/framework/op_kernel.cc:1839] OP_REQUIRES failed at conv_ops_fused_impl.h:772 : RESOURCE_EXHAUSTED: OOM when allocating tensor with shape[32,4,16,1024] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu Traceback (most recent call last): File "c:\Users\lin13\Desktop\data\lab9-8.py", line 436, in <module> train_and_evaluate() File "c:\Users\lin13\Desktop\data\lab9-8.py", line 415, in train_and_evaluate history = siamese_model.fit( File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None File "c:\Users\lin13\Desktop\data\lab9-8.py", line 310, in on_epoch_end self.model.fit( tensorflow.python.framework.errors_impl.ResourceExhaustedError: Graph execution error: Detected at node model_1/model/resnet50/conv4_block6_3_bn/FusedBatchNormV3 defined at (most recent call last): File "c:\Users\lin13\Desktop\data\lab9-8.py", line 436, in <module> File "c:\Users\lin13\Desktop\data\lab9-8.py", line 415, in train_and_evaluate File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 1850, in fit File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\callbacks.py", line 453, in on_epoch_end File "c:\Users\lin13\Desktop\data\lab9-8.py", line 310, in on_epoch_end File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 1783, in fit File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 1377, in train_function File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 1360, in step_function File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 1349, in run_step File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 1126, in train_step File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 589, in __call__ File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\base_layer.py", line 1149, in __call__ File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\functional.py", line 515, in call File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\functional.py", line 672, in _run_internal_graph File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 589, in __call__ File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\base_layer.py", line 1149, in __call__ File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\functional.py", line 515, in call File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\functional.py", line 672, in _run_internal_graph File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\training.py", line 589, in __call__ File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\base_layer.py", line 1149, in __call__ File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\functional.py", line 515, in call File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\functional.py", line 672, in _run_internal_graph File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 65, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\engine\base_layer.py", line 1149, in __call__ File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\traceback_utils.py", line 96, in error_handler File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\layers\normalization\batch_normalization.py", line 597, in call File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\layers\normalization\batch_normalization.py", line 990, in _fused_batch_norm File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\utils\control_flow_util.py", line 108, in smart_cond File "C:\Users\lin13\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\src\layers\normalization\batch_normalization.py", line 964, in _fused_batch_norm_training OOM when allocating tensor with shape[32,4,16,1024] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu [[{{node model_1/model/resnet50/conv4_block6_3_bn/FusedBatchNormV3}}]] Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info. This isn't available when running in Eager mode. [Op:__inference_train_function_66233] 2025-06-22 14:05:32.873794: W tensorflow/core/kernels/data/generator_dataset_op.cc:108] Error occurred when finalizing GeneratorDataset iterator: FAILED_PRECONDITION: Python interpreter state is not initialized. The process may be terminated. [[{{node PyFunc}}]] PS C:\Users\lin13\Desktop\data> 帮我看看为什么
最新发布
06-23
该错误表明系统无法找到名为 `./grade-labs-util` 的可执行文件或脚本。以下是可能的原因及解决方法: ### 可能原因与解决方法 1. **文件名拼写错误** 根据引用内容[^4],正确的命令是 `./grade-lab-util` 而不是 `./grade-labs-util`。请检查文件名是否正确,确保没有多余的字符或拼写错误。 2. **文件不存在** 如果文件确实不存在,请确认是否已正确克隆仓库并下载所有相关文件。可以运行以下命令检查: ```bash ls -l | grep grade-lab-util ``` 如果文件缺失,请重新克隆仓库或从官方资源中获取该文件。 3. **文件权限问题** 确保 `grade-lab-util` 文件具有可执行权限。如果没有,请使用以下命令添加权限: ```bash chmod +x grade-lab-util ``` 4. **Python 版本问题** 引用内容[^4]提到,如果运行 `./grade-lab-util sleep` 报错 `/usr/bin/env: ‘python’: No such file or directory`,则需要将脚本的第一行从 `python` 修改为 `python3`。可以通过以下步骤解决: - 打开文件进行编辑: ```bash vim grade-lab-util ``` - 将第一行的 `#!/usr/bin/env python` 修改为 `#!/usr/bin/env python3`。 - 保存并退出编辑器。 5. **系统未安装 Python3** 如果系统中未安装 Python3,可能会导致类似错误。可以通过以下命令安装 Python3: ```bash sudo apt-get update sudo apt-get install python3 ``` 6. **路径问题** 确保当前工作目录是包含 `grade-lab-util` 文件的目录。可以通过以下命令检查当前路径: ```bash pwd ``` 如果不在正确目录下,请切换到正确的目录,例如: ```bash cd ~/xv6-labs-2020 ``` ### 示例代码 以下是一个完整的示例流程,用于验证和修复问题: ```bash # 检查文件是否存在 ls -l | grep grade-lab-util # 如果文件存在但不可执行,添加可执行权限 chmod +x grade-lab-util # 编辑文件以确保使用 Python3 vim grade-lab-util # 修改第一行为:#!/usr/bin/env python3 # 测试命令 ./grade-lab-util sleep ``` ### 注意事项 - 如果问题仍然存在,请检查是否有其他依赖项未安装。 - 确保所有操作都在正确的目录下进行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值