Ali Ahmed55 نشر 11 نوفمبر أرسل تقرير نشر 11 نوفمبر السلام عليكم ده الكود col = ['D1','D2','D3','D4','D5','D6','D7','D8','D9','E1','E10','E11','E12','E13','E14', 'E15','E16','E17','E18','E19','E2','E20','E3','E4','E5','E6','E7','E8','E9','I1', 'I2','I3','I4','I5','I6','I7','I8','I9','M1','M10','M11','M12','M13','M14','M15', 'M16','M17','M18','M2','M3','M4','M5','M6','M7','M8','M9','P1','P10','P11','P12', 'P13','P2','P3','P4','P5','P6','P7','P8','P9','S1','S10','S11','S12','S2','S3', 'S4','S5','S6','S7','S8','S9','V1','V10','V11','V12','V13','V2','V3','V4','V5', 'V6','V7','V8','V9','is_scored','lagged_risk_free_rate', 'lagged_market_forward_excess_returns'] model = tf.keras.models.load_model('AlphaPulse.keras') def predict(test: pd.DataFrame) -> float: df = test df_copy = data_test_copy x_test = df[col] preds = model.predict(x_test) allocation = preds.clip(0, 2).reshape(-1) return pd.DataFrame({"date_id": df_copy["date_id"].values,"prediction": allocation}) inference_server = kaggle_evaluation.default_inference_server.DefaultInferenceServer(predict) if os.getenv('KAGGLE_IS_COMPETITION_RERUN'): inference_server.serve() else: inference_server.run_local_gateway(('/kaggle/input/hull-tactical-market-prediction/',)) ودي المشكله الناتج عن الكود ده --------------------------------------------------------------------------- GatewayRuntimeError Traceback (most recent call last) /tmp/ipykernel_39/3513852296.py in <cell line: 0>() 38 inference_server.serve() 39 else: ---> 40 inference_server.run_local_gateway(('/kaggle/input/hull-tactical-market-prediction/',)) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/templates.py in run_local_gateway(self, data_paths, file_share_dir, *args, **kwargs) 106 self.gateway.run() 107 except Exception as err: --> 108 raise err from None 109 finally: 110 self.server.stop(0) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/templates.py in run_local_gateway(self, data_paths, file_share_dir, *args, **kwargs) 104 try: 105 self.gateway = self._get_gateway_for_test(data_paths, file_share_dir, *args, **kwargs) --> 106 self.gateway.run() 107 except Exception as err: 108 raise err from None /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in run(self) 149 elif error: 150 # For local testing --> 151 raise error 152 153 @final /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in run(self) 130 try: 131 self.unpack_data_paths() --> 132 predictions, row_ids = self.get_all_predictions() 133 self.write_submission(predictions, row_ids) 134 except GatewayRuntimeError as gre: /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in get_all_predictions(self) 106 self.data_batch_counter = 0 107 for data_batch, row_ids in self.generate_data_batches(): --> 108 predictions = self.predict(*data_batch) 109 self.competition_agnostic_validation(predictions, row_ids) 110 self.competition_specific_validation(predictions, row_ids, data_batch) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in predict(self, *args, **kwargs) 124 return self.client.send('predict', *args, **kwargs) 125 except Exception as e: --> 126 self.handle_server_error(e, 'predict') 127 128 def run(self) -> None: /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in handle_server_error(self, exception, endpoint) 429 message_match = re.search('"Exception calling application: (.*)"', exception_str, re.IGNORECASE) 430 message = message_match.group(1) if message_match else exception_str --> 431 raise GatewayRuntimeError(GatewayRuntimeErrorType.SERVER_RAISED_EXCEPTION, message) from None 432 if isinstance(exception, grpc._channel._InactiveRpcError): 433 raise GatewayRuntimeError(GatewayRuntimeErrorType.SERVER_CONNECTION_FAILED, exception_str) from None GatewayRuntimeError: (<GatewayRuntimeErrorType.SERVER_RAISED_EXCEPTION: 3>, 'All arrays must be of the same length') 1 اقتباس
0 Mustafa Suleiman نشر 12 نوفمبر أرسل تقرير نشر 12 نوفمبر لديك مشكلة في عدم تطابق طول البيانات عند إنشاء إطار البيانات النهائي، بسبب استخدام متغير غير معرف data_test_copy بدلاً من استخدام نفس إطار البيانات الذي يحتوي على الميزات أي استخدم df أو test لاستخراج date_id وليس data_test_copy. أيضًا الدالة حددت لها بأن تُعيد float لكن النتيجة هي pd.DataFrame، يجب تصحيح ذلك إلى pd.DataFrame import pandas as pd import tensorflow as tf import kaggle_evaluation import os col = ['D1','D2','D3','D4','D5','D6','D7','D8','D9','E1','E10','E11','E12','E13','E14', 'E15','E16','E17','E18','E19','E2','E20','E3','E4','E5','E6','E7','E8','E9','I1', 'I2','I3','I4','I5','I6','I7','I8','I9','M1','M10','M11','M12','M13','M14','M15', 'M16','M17','M18','M2','M3','M4','M5','M6','M7','M8','M9','P1','P10','P11','P12', 'P13','P2','P3','P4','P5','P6','P7','P8','P9','S1','S10','S11','S12','S2','S3', 'S4','S5','S6','S7','S8','S9','V1','V10','V11','V12','V13','V2','V3','V4','V5', 'V6','V7','V8','V9','is_scored','lagged_risk_free_rate', 'lagged_market_forward_excess_returns'] model_path = 'AlphaPulse.keras' if not os.path.exists(model_path): model_path = '/kaggle/working/AlphaPulse.keras' model = tf.keras.models.load_model(model_path) def predict(test: pd.DataFrame) -> pd.DataFrame: df = test.copy() missing_cols = set(col) - set(df.columns) if missing_cols: raise ValueError(f"missing columns: {missing_cols}") x_test = df[col] preds = model.predict(x_test, verbose=0) allocation = preds.clip(0, 2).reshape(-1) if len(allocation) != len(df): raise ValueError(f"prediction length ({len(allocation)}) doesn't match data length ({len(df)})") return pd.DataFrame({ "date_id": df["date_id"].values, "prediction": allocation }) inference_server = kaggle_evaluation.default_inference_server.DefaultInferenceServer(predict) if os.getenv('KAGGLE_IS_COMPETITION_RERUN'): inference_server.serve() else: inference_server.run_local_gateway(('/kaggle/input/hull-tactical-market-prediction/',)) 1 اقتباس
0 Ali Ahmed55 نشر 12 نوفمبر الكاتب أرسل تقرير نشر 12 نوفمبر بتاريخ 2 ساعة قال Mustafa Suleiman: لديك مشكلة في عدم تطابق طول البيانات عند إنشاء إطار البيانات النهائي، بسبب استخدام متغير غير معرف data_test_copy بدلاً من استخدام نفس إطار البيانات الذي يحتوي على الميزات أي استخدم df أو test لاستخراج date_id وليس data_test_copy. ايوه بس اطار البيانات ده انا مسح منو العمود ده في بيانات التدريب وكمان الاختبار عشان كده عملت copy البيانات ؟ 1 اقتباس
0 Mustafa Suleiman نشر 12 نوفمبر أرسل تقرير نشر 12 نوفمبر حذفت date_id من test نفسه؟ إذن يجب تمرير إطار بيانات يحتوي على date_id. import pandas as pd import tensorflow as tf import kaggle_evaluation import os col = ['D1','D2','D3','D4','D5','D6','D7','D8','D9','E1','E10','E11','E12','E13','E14', 'E15','E16','E17','E18','E19','E2','E20','E3','E4','E5','E6','E7','E8','E9','I1', 'I2','I3','I4','I5','I6','I7','I8','I9','M1','M10','M11','M12','M13','M14','M15', 'M16','M17','M18','M2','M3','M4','M5','M6','M7','M8','M9','P1','P10','P11','P12', 'P13','P2','P3','P4','P5','P6','P7','P8','P9','S1','S10','S11','S12','S2','S3', 'S4','S5','S6','S7','S8','S9','V1','V10','V11','V12','V13','V2','V3','V4','V5', 'V6','V7','V8','V9','is_scored','lagged_risk_free_rate', 'lagged_market_forward_excess_returns'] model_path = 'AlphaPulse.keras' if not os.path.exists(model_path): model_path = '/kaggle/working/AlphaPulse.keras' model = tf.keras.models.load_model(model_path) def predict(test: pd.DataFrame, test_with_dates: pd.DataFrame) -> pd.DataFrame: df = test.copy() x_test = df[col] preds = model.predict(x_test, verbose=0) allocation = preds.clip(0, 2).reshape(-1) return pd.DataFrame({ "date_id": test_with_dates["date_id"].values, "prediction": allocation }) inference_server = kaggle_evaluation.default_inference_server.DefaultInferenceServer(predict) if os.getenv('KAGGLE_IS_COMPETITION_RERUN'): inference_server.serve() else: inference_server.run_local_gateway(('/kaggle/input/hull-tactical-market-prediction/',)) 1 اقتباس
0 Ali Ahmed55 نشر 12 نوفمبر الكاتب أرسل تقرير نشر 12 نوفمبر بس بتحصل بقا المشكله دي /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/templates.py:95: RuntimeWarning: 1889 seconds elapsed before server startup. This exceeds the startup time limit of 900 seconds that the gateway will enforce during the rerun on the hidden test set. Start the server before performing any time consuming steps. warnings.warn( --------------------------------------------------------------------------- GatewayRuntimeError Traceback (most recent call last) /tmp/ipykernel_39/2380296845.py in <cell line: 0>() 38 inference_server.serve() 39 else: ---> 40 inference_server.run_local_gateway(('/kaggle/input/hull-tactical-market-prediction/',)) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/templates.py in run_local_gateway(self, data_paths, file_share_dir, *args, **kwargs) 106 self.gateway.run() 107 except Exception as err: --> 108 raise err from None 109 finally: 110 self.server.stop(0) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/templates.py in run_local_gateway(self, data_paths, file_share_dir, *args, **kwargs) 104 try: 105 self.gateway = self._get_gateway_for_test(data_paths, file_share_dir, *args, **kwargs) --> 106 self.gateway.run() 107 except Exception as err: 108 raise err from None /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in run(self) 149 elif error: 150 # For local testing --> 151 raise error 152 153 @final /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in run(self) 130 try: 131 self.unpack_data_paths() --> 132 predictions, row_ids = self.get_all_predictions() 133 self.write_submission(predictions, row_ids) 134 except GatewayRuntimeError as gre: /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in get_all_predictions(self) 106 self.data_batch_counter = 0 107 for data_batch, row_ids in self.generate_data_batches(): --> 108 predictions = self.predict(*data_batch) 109 self.competition_agnostic_validation(predictions, row_ids) 110 self.competition_specific_validation(predictions, row_ids, data_batch) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in predict(self, *args, **kwargs) 124 return self.client.send('predict', *args, **kwargs) 125 except Exception as e: --> 126 self.handle_server_error(e, 'predict') 127 128 def run(self) -> None: /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in handle_server_error(self, exception, endpoint) 429 message_match = re.search('"Exception calling application: (.*)"', exception_str, re.IGNORECASE) 430 message = message_match.group(1) if message_match else exception_str --> 431 raise GatewayRuntimeError(GatewayRuntimeErrorType.SERVER_RAISED_EXCEPTION, message) from None 432 if isinstance(exception, grpc._channel._InactiveRpcError): 433 raise GatewayRuntimeError(GatewayRuntimeErrorType.SERVER_CONNECTION_FAILED, exception_str) from None GatewayRuntimeError: (<GatewayRuntimeErrorType.SERVER_RAISED_EXCEPTION: 3>, "predict() missing 1 required positional argument: 'test_with_dates'") اقتباس
0 محمد_عاطف نشر الأحد في 11:10 أرسل تقرير نشر الأحد في 11:10 بتاريخ On 12/11/2025 at 18:57 قال Ali Ahmed55: بس بتحصل بقا المشكله دي /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/templates.py:95: RuntimeWarning: 1889 seconds elapsed before server startup. This exceeds the startup time limit of 900 seconds that the gateway will enforce during the rerun on the hidden test set. Start the server before performing any time consuming steps. warnings.warn( --------------------------------------------------------------------------- GatewayRuntimeError Traceback (most recent call last) /tmp/ipykernel_39/2380296845.py in <cell line: 0>() 38 inference_server.serve() 39 else: ---> 40 inference_server.run_local_gateway(('/kaggle/input/hull-tactical-market-prediction/',)) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/templates.py in run_local_gateway(self, data_paths, file_share_dir, *args, **kwargs) 106 self.gateway.run() 107 except Exception as err: --> 108 raise err from None 109 finally: 110 self.server.stop(0) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/templates.py in run_local_gateway(self, data_paths, file_share_dir, *args, **kwargs) 104 try: 105 self.gateway = self._get_gateway_for_test(data_paths, file_share_dir, *args, **kwargs) --> 106 self.gateway.run() 107 except Exception as err: 108 raise err from None /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in run(self) 149 elif error: 150 # For local testing --> 151 raise error 152 153 @final /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in run(self) 130 try: 131 self.unpack_data_paths() --> 132 predictions, row_ids = self.get_all_predictions() 133 self.write_submission(predictions, row_ids) 134 except GatewayRuntimeError as gre: /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in get_all_predictions(self) 106 self.data_batch_counter = 0 107 for data_batch, row_ids in self.generate_data_batches(): --> 108 predictions = self.predict(*data_batch) 109 self.competition_agnostic_validation(predictions, row_ids) 110 self.competition_specific_validation(predictions, row_ids, data_batch) /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in predict(self, *args, **kwargs) 124 return self.client.send('predict', *args, **kwargs) 125 except Exception as e: --> 126 self.handle_server_error(e, 'predict') 127 128 def run(self) -> None: /kaggle/input/hull-tactical-market-prediction/kaggle_evaluation/core/base_gateway.py in handle_server_error(self, exception, endpoint) 429 message_match = re.search('"Exception calling application: (.*)"', exception_str, re.IGNORECASE) 430 message = message_match.group(1) if message_match else exception_str --> 431 raise GatewayRuntimeError(GatewayRuntimeErrorType.SERVER_RAISED_EXCEPTION, message) from None 432 if isinstance(exception, grpc._channel._InactiveRpcError): 433 raise GatewayRuntimeError(GatewayRuntimeErrorType.SERVER_CONNECTION_FAILED, exception_str) from None GatewayRuntimeError: (<GatewayRuntimeErrorType.SERVER_RAISED_EXCEPTION: 3>, "predict() missing 1 required positional argument: 'test_with_dates'") المشكلة الأساسية لديك تظهر في رسالة الخطأ في السطر الأخير: GatewayRuntimeError: ... "predict() missing 1 required positional argument: 'test_with_dates'" فسبب المشكلة هو مكتبة التقييم (kaggle_evaluation) ففي هذه المسابقة تقوم باستدعاء دالة predict الخاصة بك وتقوم بتمرير متغير واحد فقط وهو البيانات الخاصة بالاختبار test ولكنك قمت بتعريف الدالة لتنتظر متغيرين (test و test_with_dates). بما أن الدالة تنتظر شيئاً لم يتم إرساله يحدث الخطأ لديك. إذا يجب تعديل دالة predict لتستقبل متغيراً واحداً فقط، وتستخرج date_id من نفس المتغير test : import pandas as pd import tensorflow as tf import kaggle_evaluation import os # ... (باقي تعريف الأعمدة col وتحميل الموديل كما هو) ... # تأكد أن قائمة col تحتوي فقط على الأعمدة الموجودة فعلياً في البيانات القادمة (Feature Columns) def predict(test: pd.DataFrame) -> pd.DataFrame: # 1. التعديل هنا: حذفنا test_with_dates من تعريف الدالة df = test.copy() # تأكد أنك تختار فقط أعمدة الميزات (Features) للتنبؤ # قد تحتاج للتحقق إذا كانت كل الأعمدة في col موجودة في test # أحياناً date_id يكون موجوداً فنحتاج استثنائه من الموديل x_test = df[col] preds = model.predict(x_test, verbose=0) allocation = preds.clip(0, 2).reshape(-1) # 2. التعديل هنا: نأخذ date_id من الـ test dataframe نفسه return pd.DataFrame({ "date_id": test["date_id"].values, "prediction": allocation }) inference_server = kaggle_evaluation.default_inference_server.DefaultInferenceServer(predict) if os.getenv('KAGGLE_IS_COMPETITION_RERUN'): inference_server.serve() else: inference_server.run_local_gateway(('/kaggle/input/hull-tactical-market-prediction/',)) وهناك ملاحظة هامة جدا بخصوص التحذير (Warning) حيث ظهر لك تحذير خطير في بداية اللوج: RuntimeWarning: 1889 seconds elapsed before server startup وهذا يعني أن الكود استغرق 31 دقيقة فقط ليعمل قبل أن يبدأ التنبؤ حتى والحد المسموح به عادة هو 15 دقيقة (900 ثانية) للإقلاع. والسبب غالبا هي عملية تحميل الموديل tf.keras.models.load_model أو استدعاء المكتبات بطيء جداً. لذلم تأكد أنك تستخدم GPU accelerator في النوت بوك. 1 اقتباس
0 Ali Ahmed55 نشر الأحد في 18:29 الكاتب أرسل تقرير نشر الأحد في 18:29 الف شكراا جدا لحضرتكم جزاك الله كل خير اقتباس
السؤال
Ali Ahmed55
السلام عليكم
ده الكود
ودي المشكله الناتج عن الكود ده
6 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.