FLex AS3标签[RemoteClass(alias=”samples.crm.Test”)]

本文介绍如何使用[RemoteClass]元标签在ActionScript类与Java类间建立绑定,实现复杂FlashRemoting场景下对象类型的自动转换,确保客户端和服务端对象之间的正确交互。
如果您没有映射到服务器上的java对象,可以使用[RemoteClass]标签而不需要别名,但您必须从服务器上发送回对象类型。当发送 ActionScript对象被发送到服务器的同时,它被序列化成map对象,而从服务器上返回的对象就是你的原始ActionScript类型。

[RemoteClass]

RemoteClass 可以用来将一个ActionScript类绑定到一个Java类或一个ColdFusion CFC。这样做可以自动转换数据类型。下面的例子将包com.mydomain中的名为MyClass的ActionScript类绑定到了同一个包中名为MyClass的Java类:

package com.mydomain {
[Bindable]
[RemoteClass(alias=”com.mydomain.MyClass”)]
public class MyClass {
public var id:int; public var myText:String;

}
}

即:在编写 ActionScript Class 时告知该 ActionScript Class 是对应到服务器端哪个 Class 的(非ActionScript)。

,若在服务端有个 Java Object 名为 Test,若有个 ActionScript Class 要去对应时,就可以加上这段描述,
当然不去描述是不会马上出错的,但是在执行阶段,如果直接使用而没经过转换,这时候会出现错误信息 。

package samples.crm{
[RemoteClass(alias=”samples.crm.Test”)]
public class Test
{
……..
}
}

通常用到的时候是当你使用到复杂的 Flash Remoting,当他传回一个 Class Object ,而你又希望能直接用 Class 的方法操作时,就会用到该meta tag。


本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/keido711/archive/2009/10/20/4702703.aspx
import torch import torch.nn as nn import torch.optim as optim from torchvision import datasets, transforms from torch.utils.data import DataLoader import time,os import matplotlib.pyplot as plt from sklearn.metrics import f1_score from PIL import Image import cv2 device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") class SimpleCNN(nn.Module): def __init__(self, num_classes=40): super(SimpleCNN, self).__init__() self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1) self.pool = nn.MaxPool2d(kernel_size=2, stride=2) self.adap_pool=nn.AdaptiveAvgPool2d((160,160)) self.fc1 = nn.Linear(16 * 160 * 160, 512) self.fc2 = nn.Linear(512, num_classes) def forward(self, x): x = self.pool(torch.relu(self.conv1(x))) x = self.adap_pool(x) x = x.view(-1, 16 * 160 * 160) x = torch.relu(self.fc1(x)) x = self.fc2(x) return x model = SimpleCNN().to(device) # 加载模型权重 model.load_state_dict(torch.load('model.pth'),strict=False) model.eval() # 定义数据预处理 transform = transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) ]) # 加载测试数据集 def pil_loader(path): try: with open(path, "rb") as f: img = Image.open(f) return img.convert("RGB") except OSError as e: print(f"Error loading image: {path}, {e}") return None test_data_dir = '/root/train' # 替换为包含测试数据的文件夹路径 test_dataset = datasets.ImageFolder(test_data_dir, transform=transform, loader=pil_loader) test_dataset.samples = [(path,label) for path ,label in test_dataset.samples if pil_loader(path)] test_loader = DataLoader(test_dataset, batch_size=32,num_workers=4) # 计算测试集上的性能指标 correct_test = 0 total_test = 0 test_predictions = [] test_targets = [] with torch.no_grad(): for test_inputs, test_labels in test_loader: test_inputs, test_labels = test_inputs.to(device), test_labels.to(device) test_outputs = model(test_inputs) _, test_predicted = torch.max(test_outputs, 1) total_test += test_labels.size(0) correct_test += (test_predicted == test_labels).sum().item() test_predictions.extend(test_predicted.cpu().tolist()) test_targets.extend(test_labels.cpu().tolist()) test_accuracy = 100 * correct_test / total_test test_f1 = f1_score(test_targets, test_predictions, average='macro') print("="*50) print(f"Test Accracy: {test_accuracy:.2f}%") print(f"Test F1 Score: {test_f1:.4f}") print("="*50)能更优化一下吗
最新发布
10-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值